Merge lp:~hodgestar/software-properties/configurable-key-server into lp:software-properties

Proposed by Hodgestar
Status: Merged
Merged at revision: 662
Proposed branch: lp:~hodgestar/software-properties/configurable-key-server
Merge into: lp:software-properties
Diff against target: 144 lines (+24/-5)
5 files modified
add-apt-repository (+8/-2)
software-properties-gtk (+4/-0)
software-properties-kde (+5/-0)
softwareproperties/SoftwareProperties.py (+1/-1)
softwareproperties/ppa.py (+6/-2)
To merge this branch: bzr merge lp:~hodgestar/software-properties/configurable-key-server
Reviewer Review Type Date Requested Status
Barry Warsaw (community) code Needs Fixing
Ubuntu Core Development Team Pending
Review via email: mp+57406@code.launchpad.net

Description of the change

A small patch that adds a --keyserver option to apt-add-repository. My main use case is so that I can fall back to other alternatives if the Ubuntu key server is down or inaccessible for some reason. I consider the patch just a draft -- I don't know enough about how the code base is used to tell whether I've added the new option to the appropriate places.

To post a comment you must log in.
659. By Jonathan Riddell

data/designer/main.ui make strings match GTK UI file LP: #760825

660. By Stéphane Graber

In Sources tab, ignore deb-src templates

661. By Stéphane Graber

releasing version 0.80.9

Revision history for this message
Barry Warsaw (barry) wrote :

Hi Simon, thanks very much for the contribution to Ubuntu! I agree this could be a useful addition to the code. It doesn't happen often (these days, IME) but I have seen failures from the ubuntu keyserver, so in those cases it would be nice to have a fallback.

I have some comments on your patch. You're not too far off, but with a few changes, I think it would be a solid addition.

In add-apt-repository, I don't think you need the 'dest' argument to add_option(). The long version of the switch will be taken as the default dest. Also note the misspelling of 'Default' in the help string.

It looks like you have multiple places where 'hkp://keyserver.ubuntu.com:80/' is hardcoded. I'd refactor this so that it's defined exactly once, in a module global constant (upper-cased) in ppa.py. Then in apt-add-repository, I'd change the import at line 9 to be:

    from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line

(i.e. DEFAULT_KEYSERVER being the module global). Use that variable in the add_option() call.

Interestingly enough, the SoftwareProperties class already takes an `options` keyword in its __init__(), so I don't think you need to extend that method's signature to take a keyserver argument. In add-apt-repository, just create the instance like this:

    sp = SoftwareProperties(options=options)

I guess the only concern here is whether the `options` that SoftwareProperties takes is intended to be the command line options or something else. Since it's undocumented and untested, let's assume 'yes' although the use of self.options.massive_debug has me scratching my head. Anyway, I'd just pass in options to the constructor.

Now when you instantiate AddPPASigningKeyThread, pass in something like this:

    worker = AddPPASigningKeyThread(parsed_uri.path, options and options.keyserver)

Now in ppa.py, where you add a keyserver argument to AddPPASigningKeyThread.__init__(), use a default value of None instead of the hardcoded path, and do something like this in the __init__():

    self.keyserver = (keyserver if keyserver is not None else DEFAULT_KEYSERVER)

I hope that all makes sense!

I wish this were testable, because then I'd be sure to request that you add a test for your new code :). If you feel like giving it a shot, go for it, but as the rest of the code isn't well tested, I wouldn't block your branch on that.

Marking as needs-fixing for now, but I'm happy to review an update if you push it.

review: Needs Fixing (code)
663. By Simon Cross <email address hidden>

Factor out default keyserver to a module global. Fix typo in --keyserver docstring. Allow passing in None for the keyserver to fallback to the default value.

664. By Simon Cross <email address hidden>

Move --keyserver into the generic 'options' holder used by SoftwareProperties. This also adds --massive-debug to add-apt-repository and --keyserver to software-properties-gtk and -kde to ensure that all scripts that use SoftwareProperties support the options it needs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'add-apt-repository'
--- add-apt-repository 2010-12-07 10:20:45 +0000
+++ add-apt-repository 2011-05-02 22:01:28 +0000
@@ -6,7 +6,7 @@
6import locale6import locale
77
8from softwareproperties.SoftwareProperties import SoftwareProperties8from softwareproperties.SoftwareProperties import SoftwareProperties
9from softwareproperties.ppa import expand_ppa_line9from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line
10from aptsources.sourceslist import SourceEntry10from aptsources.sourceslist import SourceEntry
11from optparse import OptionParser11from optparse import OptionParser
12from gettext import gettext as _12from gettext import gettext as _
@@ -41,9 +41,15 @@
41 parser = OptionParser(usage)41 parser = OptionParser(usage)
42 # FIXME: provide a --sources-list-file= option that 42 # FIXME: provide a --sources-list-file= option that
43 # puts the line into a specific file in sources.list.d43 # puts the line into a specific file in sources.list.d
44 parser.add_option ("-m", "--massive-debug", action="store_true",
45 dest="massive_debug", default=False,
46 help="Print a lot of debug information to the command line")
44 parser.add_option("-r", "--remove", action="store_true",47 parser.add_option("-r", "--remove", action="store_true",
45 dest="remove", default=False,48 dest="remove", default=False,
46 help="remove repository from sources.list.d directory")49 help="remove repository from sources.list.d directory")
50 parser.add_option("-k", "--keyserver",
51 dest="keyserver", default=DEFAULT_KEYSERVER,
52 help="URL of keyserver. Default: %default")
47 (options, args) = parser.parse_args()53 (options, args) = parser.parse_args()
4854
49 if os.geteuid() != 0:55 if os.geteuid() != 0:
@@ -57,7 +63,7 @@
57 # force new ppa file to be 644 (LP: #399709)63 # force new ppa file to be 644 (LP: #399709)
58 os.umask(0022)64 os.umask(0022)
5965
60 sp = SoftwareProperties() 66 sp = SoftwareProperties(options=options)
61 line = args[0]67 line = args[0]
62 if options.remove:68 if options.remove:
63 (line, file) = expand_ppa_line(line.strip(), sp.distro.codename)69 (line, file) = expand_ppa_line(line.strip(), sp.distro.codename)
6470
=== modified file 'software-properties-gtk'
--- software-properties-gtk 2011-04-05 13:07:35 +0000
+++ software-properties-gtk 2011-05-02 22:01:28 +0000
@@ -39,6 +39,7 @@
39#sys.path.append("@prefix@/share/update-manager/python")39#sys.path.append("@prefix@/share/update-manager/python")
4040
41from softwareproperties.gtk.SoftwarePropertiesGtk import SoftwarePropertiesGtk41from softwareproperties.gtk.SoftwarePropertiesGtk import SoftwarePropertiesGtk
42from softwareproperties.ppa import DEFAULT_KEYSERVER
4243
43if __name__ == "__main__":44if __name__ == "__main__":
44 _ = gettext.gettext45 _ = gettext.gettext
@@ -70,6 +71,9 @@
70 parser.add_option("--enable-ppa", "",71 parser.add_option("--enable-ppa", "",
71 action="store", type="string", default=None,72 action="store", type="string", default=None,
72 help="Enable PPA with the given name")73 help="Enable PPA with the given name")
74 parser.add_option("-k", "--keyserver",
75 dest="keyserver", default=DEFAULT_KEYSERVER,
76 help="URL of keyserver. Default: %default")
73 parser.add_option("--data-dir", "",77 parser.add_option("--data-dir", "",
74 action="store", type="string", default="/usr/share/software-properties/",78 action="store", type="string", default="/usr/share/software-properties/",
75 help="Use data files (UI) from the given directory")79 help="Use data files (UI) from the given directory")
7680
=== modified file 'software-properties-kde'
--- software-properties-kde 2009-12-09 13:21:36 +0000
+++ software-properties-kde 2011-05-02 22:01:28 +0000
@@ -32,6 +32,7 @@
32#sys.path.append("@prefix@/share/update-manager/python")32#sys.path.append("@prefix@/share/update-manager/python")
3333
34from softwareproperties.kde.SoftwarePropertiesKDE import SoftwarePropertiesKDE34from softwareproperties.kde.SoftwarePropertiesKDE import SoftwarePropertiesKDE
35from softwareproperties.ppa import DEFAULT_KEYSERVER
3536
36from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs , KCmdLineOptions37from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs , KCmdLineOptions
37from PyKDE4.kdeui import KApplication, KMessageBox38from PyKDE4.kdeui import KApplication, KMessageBox
@@ -41,6 +42,7 @@
41 massive_debug = False42 massive_debug = False
42 no_update = False43 no_update = False
43 enable_component = ""44 enable_component = ""
45 keyserver = DEFAULT_KEYSERVER
4446
45#--------------- main ------------------47#--------------- main ------------------
46if __name__ == '__main__':48if __name__ == '__main__':
@@ -69,6 +71,7 @@
69 opts.add ("dont-update", ki18n("No update on repository change (useful if called from an external program)"))71 opts.add ("dont-update", ki18n("No update on repository change (useful if called from an external program)"))
70 opts.add ("enable-component <name>", ki18n("Enable the specified component of the distro's repositories"), "component_arg")72 opts.add ("enable-component <name>", ki18n("Enable the specified component of the distro's repositories"), "component_arg")
71 opts.add ("enable-ppa <name>", ki18n("Enable PPA with the given name"), "ppa_arg")73 opts.add ("enable-ppa <name>", ki18n("Enable PPA with the given name"), "ppa_arg")
74 opts.add ("keyserver <url>", ki18n("URL of keyserver"), "keyserver_url")
72 opts.add ("attach <WinID>", ki18n("Win ID to act as a dialogue for"), "attach_arg")75 opts.add ("attach <WinID>", ki18n("Win ID to act as a dialogue for"), "attach_arg")
73 76
74 KCmdLineArgs.addCmdLineOptions(opts)77 KCmdLineArgs.addCmdLineOptions(opts)
@@ -104,6 +107,8 @@
104 options.no_update = True107 options.no_update = True
105 if args.isSet("attach") == True:108 if args.isSet("attach") == True:
106 attachWinID = args.getOption("attach")109 attachWinID = args.getOption("attach")
110 if args.isSet("keyserver"):
111 options.keyserver = str(args.getOption("keyserver"))
107112
108 if args.isSet("enable-ppa"):113 if args.isSet("enable-ppa"):
109 app = SoftwarePropertiesKDE(datadir=data_dir, options=options, file=file)114 app = SoftwarePropertiesKDE(datadir=data_dir, options=options, file=file)
110115
=== modified file 'softwareproperties/SoftwareProperties.py'
--- softwareproperties/SoftwareProperties.py 2010-12-07 10:20:45 +0000
+++ softwareproperties/SoftwareProperties.py 2011-05-02 22:01:28 +0000
@@ -616,7 +616,7 @@
616 # FIXME: abstract this all alway into the ppa.py file616 # FIXME: abstract this all alway into the ppa.py file
617 parsed_uri = urlparse(SourceEntry(srcline).uri)617 parsed_uri = urlparse(SourceEntry(srcline).uri)
618 if parsed_uri.netloc == 'ppa.launchpad.net':618 if parsed_uri.netloc == 'ppa.launchpad.net':
619 worker = AddPPASigningKeyThread(parsed_uri.path)619 worker = AddPPASigningKeyThread(parsed_uri.path, self.options and self.options.keyserver)
620 worker.start()620 worker.start()
621621
622 def update_interface(self):622 def update_interface(self):
623623
=== modified file 'softwareproperties/ppa.py'
--- softwareproperties/ppa.py 2010-12-13 08:42:40 +0000
+++ softwareproperties/ppa.py 2011-05-02 22:01:28 +0000
@@ -27,6 +27,8 @@
27from urllib2 import urlopen, Request, URLError27from urllib2 import urlopen, Request, URLError
28from urlparse import urlparse28from urlparse import urlparse
2929
30DEFAULT_KEYSERVER = "hkp://keyserver.ubuntu.com:80/"
31
30def encode(s):32def encode(s):
31 return re.sub("[^a-zA-Z0-9_-]","_", s)33 return re.sub("[^a-zA-Z0-9_-]","_", s)
3234
@@ -55,9 +57,11 @@
55class AddPPASigningKeyThread(Thread):57class AddPPASigningKeyThread(Thread):
56 " thread class for adding the signing key in the background "58 " thread class for adding the signing key in the background "
5759
58 def __init__(self, ppa_path):60 def __init__(self, ppa_path, keyserver=None):
59 Thread.__init__(self)61 Thread.__init__(self)
60 self.ppa_path = ppa_path62 self.ppa_path = ppa_path
63 self.keyserver = (keyserver if keyserver is not None
64 else DEFAULT_KEYSERVER)
61 65
62 def run(self):66 def run(self):
63 self.add_ppa_signing_key(self.ppa_path)67 self.add_ppa_signing_key(self.ppa_path)
@@ -86,7 +90,7 @@
86 # the load90 # the load
87 res = subprocess.call(91 res = subprocess.call(
88 ["apt-key", "adv", 92 ["apt-key", "adv",
89 "--keyserver", "hkp://keyserver.ubuntu.com:80/",93 "--keyserver", self.keyserver,
90 "--recv", signing_key_fingerprint[0]])94 "--recv", signing_key_fingerprint[0]])
91 return (res == 0)95 return (res == 0)
92 except URLError, e:96 except URLError, e:

Subscribers

People subscribed via source and target branches

to status/vote changes: