Merge lp:~smoser/software-properties/trunk.lp1532855 into lp:software-properties

Proposed by Scott Moser
Status: Merged
Merged at revision: 988
Proposed branch: lp:~smoser/software-properties/trunk.lp1532855
Merge into: lp:software-properties
Diff against target: 72 lines (+32/-4)
1 file modified
softwareproperties/SoftwareProperties.py (+32/-4)
To merge this branch: bzr merge lp:~smoser/software-properties/trunk.lp1532855
Reviewer Review Type Date Requested Status
Dimitri John Ledkov with prejudice Approve
Review via email: mp+318132@code.launchpad.net

Description of the change

This is not the world's cleanest change, and I'm not sure how error messages should be printed, but it does catch the error correctly.

To post a comment you must log in.
988. By Dimitri John Ledkov

When failing to retrieve a GPG key, raise an exception such that
e.g. add-apt-repository can fail when it did not manage to retrieve a
GPG key for the shortcut repository. LP: #1532855

Revision history for this message
Dimitri John Ledkov (xnox) :
review: Approve (with prejudice)
Revision history for this message
Iain Lane (laney) wrote :

Please see https://code.launchpad.net/~laney/software-properties/test-fixes/+merge/318784 - I think this change broke the testsuite.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwareproperties/SoftwareProperties.py'
2--- softwareproperties/SoftwareProperties.py 2016-03-16 09:17:42 +0000
3+++ softwareproperties/SoftwareProperties.py 2017-02-23 16:44:58 +0000
4@@ -666,7 +666,8 @@
5
6 def check_and_add_key_for_whitelisted_channels(self, srcline):
7 # This is maintained for any legacy callers
8- return self.check_and_add_key_for_whitelisted_shortcut(shortcut_handler(srcline))
9+ worker, _queue = self.check_and_add_key_for_whitelisted_shortcut(shortcut_handler(srcline))
10+ return worker
11
12 def check_and_add_key_for_whitelisted_shortcut(self, shortcut):
13 """
14@@ -683,13 +684,31 @@
15
16 cdata = (shortcut.add_key, {'keyserver': (self.options and
17 self.options.keyserver)})
18+ try:
19+ import queue
20+ except ImportError:
21+ import Queue as queue
22+
23+ myqueue = queue.Queue()
24+
25 def addkey_func():
26 func, kwargs = cdata
27- func(**kwargs)
28+ ret = None
29+ msg = None
30+ try:
31+ ret = func(**kwargs)
32+ if ret:
33+ msg = "Added key."
34+ else:
35+ msg = "Failed to add key."
36+ except Exception as e:
37+ ret = False
38+ msg = str(e)
39+ myqueue.put([ret, msg])
40
41 worker = threading.Thread(target=addkey_func)
42 worker.start()
43- return worker
44+ return (worker, myqueue)
45
46 def update_interface(self):
47 " abstract interface to keep the UI alive "
48@@ -734,7 +753,7 @@
49 new_debsrc_entry = SourceEntry(debsrc_line, file)
50 if new_deb_entry.invalid or new_debsrc_entry.invalid:
51 return False
52- worker = self.check_and_add_key_for_whitelisted_shortcut(shortcut)
53+ worker, rqueue = self.check_and_add_key_for_whitelisted_shortcut(shortcut)
54 self.sourceslist.add(new_deb_entry.type,
55 new_deb_entry.uri,
56 new_deb_entry.dist,
57@@ -753,6 +772,15 @@
58 if worker:
59 # wait for GPG key to be downloaded
60 worker.join(30)
61+ if worker.isAlive():
62+ # thread timed out.
63+ print("Error: retrieving gpg key timed out.")
64+ return False
65+ result, msg = rqueue.get()
66+ if not result:
67+ print(msg)
68+ return result
69+
70 if self.options and self.options.update:
71 import apt
72 cache = apt.Cache()

Subscribers

People subscribed via source and target branches

to status/vote changes: