Merge lp:~mvo/aptdaemon/exception-fixes into lp:aptdaemon

Proposed by Michael Vogt
Status: Merged
Merged at revision: 728
Proposed branch: lp:~mvo/aptdaemon/exception-fixes
Merge into: lp:aptdaemon
Diff against target: 139 lines (+16/-15)
3 files modified
aptdaemon/worker.py (+14/-13)
gtk-demo.py (+1/-1)
gtk3-demo.py (+1/-1)
To merge this branch: bzr merge lp:~mvo/aptdaemon/exception-fixes
Reviewer Review Type Date Requested Status
Aptdaemon Developers Pending
Review via email: mp+83322@code.launchpad.net

Description of the change

Be more py3 friendly when it comes to exception handling. I also think the new synatx is cleaner to read. This is supported since python 2.6 (see http://docs.python.org/whatsnew/2.6.html see pep3110).

Patch is not complete, but if you like the aporoach I will make it complete.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'aptdaemon/worker.py'
2--- aptdaemon/worker.py 2011-11-24 16:20:11 +0000
3+++ aptdaemon/worker.py 2011-11-24 16:26:26 +0000
4@@ -153,7 +153,7 @@
5 log.debug("Calling %s plugin: %s", name, plugin)
6 try:
7 plugin(resolver, self._cache)
8- except Exception, error:
9+ except Exception as error:
10 log.critical("Failed to call %s plugin:\n%s" % (plugin, error))
11 return True
12
13@@ -254,7 +254,7 @@
14 trans.exit = EXIT_FAILED
15 except (KeyboardInterrupt, SystemExit):
16 trans.exit = EXIT_CANCELLED
17- except Exception, excep:
18+ except Exception as excep:
19 tbk = traceback.format_exc()
20 trans.error = TransactionFailed(ERROR_UNKNOWN, tbk)
21 trans.exit = EXIT_FAILED
22@@ -460,7 +460,7 @@
23 import grp
24 try:
25 os.chown(sourcesfile, 0, grp.getgrnam("admin")[2])
26- except Exception, e:
27+ except Exception as e:
28 logging.warn("os.chmod() failed '%s'" % e)
29 finally:
30 os.umask(old_umask)
31@@ -517,7 +517,7 @@
32 #FIXME: use --dry-run before?
33 auth = AptAuth()
34 auth.add(os.path.expanduser(path))
35- except Exception, error:
36+ except Exception as error:
37 raise TransactionFailed(ERROR_KEY_NOT_INSTALLED,
38 _("Key file %s couldn't be installed: %s"),
39 path, error)
40@@ -537,7 +537,7 @@
41 #FIXME: use --dry-run before?
42 auth = AptAuth()
43 auth.rm(fingerprint)
44- except Exception, error:
45+ except Exception as error:
46 raise TransactionFailed(ERROR_KEY_NOT_REMOVED,
47 _("Key with fingerprint %s couldn't be "
48 "removed: %s"), fingerprint, error)
49@@ -780,7 +780,7 @@
50 sources_list = os.path.join(basedir, sources_list)
51 try:
52 self._cache.update(progress, sources_list=sources_list)
53- except apt.cache.FetchFailedException, error:
54+ except apt.cache.FetchFailedException as error:
55 # ListUpdate() method of apt handles a cancelled operation
56 # as a failed one, see LP #162441
57 if trans.cancelled:
58@@ -892,7 +892,7 @@
59 self._cache = apt.cache.Cache(progress)
60 else:
61 self._cache.open(progress)
62- except SystemError, excep:
63+ except SystemError as excep:
64 raise TransactionFailed(ERROR_NO_CACHE, excep.message)
65
66 def is_dpkg_journal_clean(self):
67@@ -943,12 +943,12 @@
68 with self._frozen_status():
69 try:
70 self._cache.commit(fetch_progress, inst_progress)
71- except apt.cache.FetchFailedException, error:
72+ except apt.cache.FetchFailedException as error:
73 raise TransactionFailed(ERROR_PACKAGE_DOWNLOAD_FAILED,
74 str(error.message))
75 except apt.cache.FetchCancelledException:
76 raise TransactionCancelled()
77- except SystemError, excep:
78+ except SystemError as excep:
79 # Run dpkg --configure -a to recover from a failed transaction
80 trans.status = STATUS_CLEANING_UP
81 progress = DaemonDpkgRecoverProgress(trans, begin=90, end=95)
82@@ -997,10 +997,10 @@
83 try:
84 trans.depends, trans.download, trans.space, \
85 trans.unauthenticated = self.__simulate(trans)
86- except TransactionFailed, excep:
87+ except TransactionFailed as excep:
88 trans.error = excep
89 trans.exit = EXIT_FAILED
90- except Exception, excep:
91+ except Exception as excep:
92 tbk = traceback.format_exc()
93 trans.error = TransactionFailed(ERROR_UNKNOWN, tbk)
94 try:
95@@ -1177,7 +1177,7 @@
96 deb = apt.debfile.DebPackage(path, self._cache)
97 except IOError:
98 raise TransactionFailed(ERROR_UNREADABLE_PACKAGE_FILE, path)
99- except Exception, error:
100+ except Exception as error:
101 raise TransactionFailed(ERROR_INVALID_PACKAGE_FILE, str(error))
102 if not deb.check():
103 raise TransactionFailed(ERROR_DEP_RESOLUTION_FAILED,
104@@ -1217,7 +1217,8 @@
105 license_key, license_key_path = \
106 self.plugins["get_license_key"][0](trans.uid, pkg_name,
107 json_token, server_name)
108- except Exception, error:
109+ except Exception as error:
110+ logging.exception("get_license_key plugin failed")
111 raise TransactionFailed(ERROR_LICENSE_KEY_DOWNLOAD_FAILED,
112 str(error))
113 # ensure stuff is good
114
115=== modified file 'gtk-demo.py'
116--- gtk-demo.py 2010-12-06 05:10:53 +0000
117+++ gtk-demo.py 2011-11-24 16:26:26 +0000
118@@ -68,7 +68,7 @@
119 return
120 except aptdaemon.errors.TransactionFailed, error:
121 pass
122- except Exception, error:
123+ except Exception as error:
124 error = aptdaemon.errors.TransactionFailed(ERROR_UNKNOWN,
125 str(error))
126 dia = AptErrorDialog(error)
127
128=== modified file 'gtk3-demo.py'
129--- gtk3-demo.py 2011-08-17 05:33:59 +0000
130+++ gtk3-demo.py 2011-11-24 16:26:26 +0000
131@@ -73,7 +73,7 @@
132 return
133 except aptdaemon.errors.TransactionFailed, error:
134 pass
135- except Exception, error:
136+ except Exception as error:
137 error = aptdaemon.errors.TransactionFailed(ERROR_UNKNOWN,
138 str(error))
139 dia = AptErrorDialog(error)

Subscribers

People subscribed via source and target branches

to status/vote changes: