Merge lp:~smoser/ubuntu/precise/software-properties/lp1233486 into lp:ubuntu/precise-updates/software-properties

Proposed by Scott Moser
Status: Merged
Merged at revision: 93
Proposed branch: lp:~smoser/ubuntu/precise/software-properties/lp1233486
Merge into: lp:ubuntu/precise-updates/software-properties
Diff against target: 272 lines (+184/-9)
4 files modified
add-apt-repository (+32/-7)
debian/changelog (+7/-0)
softwareproperties/SoftwareProperties.py (+20/-2)
softwareproperties/cloudarchive.py (+125/-0)
To merge this branch: bzr merge lp:~smoser/ubuntu/precise/software-properties/lp1233486
Reviewer Review Type Date Requested Status
Brian Murray Disapprove
Review via email: mp+189905@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

This was already SRU'ed and uploaded to precise.

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'add-apt-repository'
2--- add-apt-repository 2012-04-25 21:11:57 +0000
3+++ add-apt-repository 2013-10-08 16:10:27 +0000
4@@ -5,10 +5,12 @@
5 import gettext
6 import locale
7
8-from softwareproperties.SoftwareProperties import SoftwareProperties
9-from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line
10+from softwareproperties.SoftwareProperties import SoftwareProperties, expand_shortcut_line
11+from softwareproperties.ppa import DEFAULT_KEYSERVER
12+from softwareproperties import cloudarchive
13 from softwareproperties import lp_application_name
14 from aptsources.sourceslist import SourceEntry
15+from aptsources.distro import get_distro
16 from optparse import OptionParser
17 from gettext import gettext as _
18 from urllib2 import HTTPError, URLError
19@@ -117,6 +119,7 @@
20 line = args[0]
21
22 # display PPA info (if needed)
23+ prompt_info = {}
24 if line.startswith("ppa:") and not options.assume_yes:
25 from softwareproperties.ppa import get_ppa_info_from_lp, LAUNCHPAD_PPA_API
26 user, sep, ppa_name = line.split(":")[1].partition("/")
27@@ -142,12 +145,34 @@
28 print _("Adding private PPAs is not supported currently")
29 sys.exit(1)
30
31+ prompt_info["description"] = ppa_info["description"] or ""
32+ prompt_info["web_link"] = ppa_info["web_link"]
33+ prompt_info["remove"] = _("You are about to remove the following PPA from your system:")
34+ prompt_info["add"] = _("You are about to add the following PPA to your system:")
35+
36+ elif line.startswith("cloud-archive:"):
37+ try:
38+ # we check 'expand' for the current codename here. so as to know
39+ # that later calls will not raise exception.
40+ handler = cloudarchive.shortcut_handler(line)
41+ handler.expand(codename=get_distro().codename)
42+ except cloudarchive.ShortcutException as e:
43+ print e
44+ sys.exit(1)
45+
46+ if not options.assume_yes:
47+ prompt_info.update(handler.info())
48+ prompt_info["remove"] = _("You are about to remove the following from your system:")
49+ prompt_info["add"] = _("You are about to add the following to your system:")
50+
51+ if prompt_info:
52 if options.remove:
53- print _("You are about to remove the following PPA from your system:")
54+ print prompt_info["remove"]
55 else:
56- print _("You are about to add the following PPA to your system:")
57- print " %s" % utf8(ppa_info["description"] or "")
58- print _(" More info: %s") % ppa_info["web_link"]
59+ print prompt_info["add"]
60+
61+ print " %s" % utf8(prompt_info["description"] or "")
62+ print _(" More info: %s") % prompt_info["web_link"]
63 if (sys.stdin.isatty() and
64 not "FORCE_ADD_APT_REPOSITORY" in os.environ):
65 if options.remove:
66@@ -159,7 +184,7 @@
67 # add it
68 sp = SoftwareProperties(options=options)
69 if options.remove:
70- (line, file) = expand_ppa_line(line.strip(), sp.distro.codename)
71+ (line, file) = expand_shortcut_line(line.strip(), sp.distro.codename)
72 deb_line = sp.expand_http_line(line)
73 debsrc_line = 'deb-src' + deb_line[3:]
74 deb_entry = SourceEntry(deb_line, file)
75
76=== modified file 'debian/changelog'
77--- debian/changelog 2013-09-13 10:07:44 +0000
78+++ debian/changelog 2013-10-08 16:10:27 +0000
79@@ -1,3 +1,10 @@
80+software-properties (0.82.7.6) UNRELEASED; urgency=low
81+
82+ * support adding cloud-archive repositories using syntax like
83+ cloud-archive:havana from add-apt-repository (LP: #1233486)
84+
85+ -- Scott Moser <smoser@ubuntu.com> Sat, 05 Oct 2013 20:55:24 -0400
86+
87 software-properties (0.82.7.5) precise-security; urgency=low
88
89 * SECURITY UPDATE: possible privilege escalation via policykit UID lookup
90
91=== modified file 'softwareproperties/SoftwareProperties.py'
92--- softwareproperties/SoftwareProperties.py 2012-04-25 21:11:57 +0000
93+++ softwareproperties/SoftwareProperties.py 2013-10-08 16:10:27 +0000
94@@ -51,6 +51,7 @@
95 from AptAuth import AptAuth
96 from aptsources.sourceslist import SourcesList, SourceEntry
97 from ppa import AddPPASigningKeyThread, expand_ppa_line
98+from cloudarchive import shortcut_handler as ca_shortcut_handler
99
100 class SoftwareProperties(object):
101
102@@ -693,14 +694,23 @@
103 Add a source with the given apt line and auto-add
104 signing key if we have it in the whitelist
105 """
106- (deb_line, file) = expand_ppa_line(line.strip(), self.distro.codename)
107+ (deb_line, file) = expand_shortcut_line(line.strip(), self.distro.codename)
108 deb_line = self.expand_http_line(deb_line)
109 debsrc_line = 'deb-src' + deb_line[3:]
110 new_deb_entry = SourceEntry(deb_line, file)
111 new_debsrc_entry = SourceEntry(debsrc_line, file)
112 if new_deb_entry.invalid or new_debsrc_entry.invalid:
113 return False
114- worker = self.check_and_add_key_for_whitelisted_channels(deb_line)
115+
116+ if line.startswith("cloud-archive:"):
117+ # in trunk, we modified check_and_add_key_for_whitelisted_channels to
118+ # take the line itself. but this is that functions only caller
119+ # so it should be safe and less invasive to do this check here instead.
120+ ca_handler = ca_shortcut_handler(line.strip())
121+ worker = threading.Thread(target=ca_handler.add_key)
122+ worker.start()
123+ else:
124+ worker = self.check_and_add_key_for_whitelisted_channels(deb_line)
125 self.sourceslist.add(new_deb_entry.type,
126 new_deb_entry.uri,
127 new_deb_entry.dist,
128@@ -774,6 +784,14 @@
129 return False
130
131
132+def expand_shortcut_line(abrev, codename):
133+ if abrev.startswith("cloud-archive:"):
134+ handler = ca_shortcut_handler(abrev)
135+ return handler.expand(codename)
136+
137+ return expand_ppa_line(abrev, distro_codename=codename)
138+
139+
140 if __name__ == "__main__":
141 sp = SoftwareProperties()
142 print sp.get_release_upgrades_policy()
143
144=== added file 'softwareproperties/cloudarchive.py'
145--- softwareproperties/cloudarchive.py 1970-01-01 00:00:00 +0000
146+++ softwareproperties/cloudarchive.py 2013-10-08 16:10:27 +0000
147@@ -0,0 +1,125 @@
148+# software-properties cloud-archive support
149+#
150+# Copyright (c) 2013 Canonical Ltd.
151+#
152+# Author: Scott Moser <smoser@ubuntu.org>
153+#
154+# This program is free software; you can redistribute it and/or
155+# modify it under the terms of the GNU General Public License as
156+# published by the Free Software Foundation; either version 2 of the
157+# License, or (at your option) any later version.
158+#
159+# This program is distributed in the hope that it will be useful,
160+# but WITHOUT ANY WARRANTY; without even the implied warranty of
161+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
162+# GNU General Public License for more details.
163+#
164+# You should have received a copy of the GNU General Public License
165+# along with this program; if not, write to the Free Software
166+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
167+# USA
168+
169+from __future__ import print_function
170+
171+import apt_pkg
172+import os
173+import subprocess
174+from gettext import gettext as _
175+
176+CODENAME = "precise"
177+OS_RELEASES = ('folsom', 'grizzly', 'havana', 'icehouse')
178+MIRROR = "http://ubuntu-cloud.archive.canonical.com/ubuntu"
179+UCA = "Ubuntu Cloud Archive"
180+WEB_LINK = 'https://wiki.ubuntu.com/ServerTeam/CloudArchive'
181+APT_INSTALL_KEY = ['apt-get', '--quiet', '--assume-yes', 'install',
182+ 'ubuntu-cloud-keyring']
183+
184+ALIASES = {'tools-updates': 'tools'}
185+for _r in OS_RELEASES:
186+ ALIASES["%s-updates" % _r] = _r
187+
188+MAP = {
189+ 'tools': {
190+ 'sldfmt': '%(codename)s-updates/cloud-tools',
191+ 'description': UCA + " for cloud-tools (JuJu and MAAS)"},
192+ 'tools-proposed': {
193+ 'sldfmt': '%(codename)s-proposed/cloud-tools',
194+ 'description': UCA + " for cloud-tools (JuJu and MAAS) [proposed]"}
195+}
196+
197+for _r in OS_RELEASES:
198+ MAP[_r] = {
199+ 'sldfmt': '%(codename)s-updates/' + _r,
200+ 'description': UCA + ' for ' + 'Openstack ' + _r}
201+ MAP[_r + "-proposed"] = {
202+ 'sldfmt': '%(codename)s-proposed/' + _r,
203+ 'description': UCA + ' for ' + 'Openstack %s [proposed]' % _r}
204+
205+
206+class CloudArchiveShortcutHandler(object):
207+ def __init__(self, shortcut):
208+ self.shortcut = shortcut
209+
210+ prefix = "cloud-archive:"
211+
212+ subs = {'shortcut': shortcut, 'prefix': prefix,
213+ 'ca_names': sorted(MAP.keys())}
214+ if not shortcut.startswith(prefix):
215+ raise ValueError(
216+ _("shortcut '%(shortcut)s' did not start with '%(prefix)s'")
217+ % subs)
218+
219+ name_in = shortcut[len(prefix):]
220+ caname = ALIASES.get(name_in, name_in)
221+
222+ subs.update({'input_name': name_in})
223+ if caname not in MAP:
224+ raise ShortcutException(
225+ _("'%(input_name)s': not a valid cloud-archive name.\n"
226+ "Must be one of %(ca_names)s") % subs)
227+
228+ self.caname = caname
229+ self._info = MAP[caname].copy()
230+ self._info['web_link' ] = WEB_LINK
231+
232+ def info(self):
233+ return self._info
234+
235+ def expand(self, codename):
236+ if codename not in (CODENAME, os.environ.get("CA_ALLOW_CODENAME")):
237+ raise ShortcutException(
238+ _("cloud-archive only supported on %(codename)s")
239+ % {'codename': CODENAME})
240+ dist = MAP[self.caname]['sldfmt'] % {'codename': codename}
241+ line = ' '.join(('deb', MIRROR, dist, 'main',))
242+ return (line, _fname_for_caname(self.caname))
243+
244+ def should_confirm(self):
245+ return True
246+
247+ def add_key(self, keyserver=None):
248+ env = os.environ.copy()
249+ env['DEBIAN_FRONTEND'] = 'noninteractive'
250+ try:
251+ subprocess.check_call(args=APT_INSTALL_KEY, env=env)
252+ except subprocess.CalledProcessError as e:
253+ return False
254+ return True
255+
256+
257+def _fname_for_caname(caname):
258+ # caname is an entry in MAP ('tools' or 'tools-proposed')
259+ return os.path.join(
260+ apt_pkg.config.find_dir("Dir::Etc::sourceparts"),
261+ 'cloudarchive-%s.list' % caname)
262+
263+
264+def shortcut_handler(shortcut):
265+ try:
266+ return CloudArchiveShortcutHandler(shortcut)
267+ except ValueError:
268+ return None
269+
270+
271+def ShortcutException(Exception):
272+ pass

Subscribers

People subscribed via source and target branches

to all changes: