Merge lp:~brian-murray/update-notifier/python3 into lp:update-notifier/ubuntu
- python3
- Merge into ubuntu
Status: | Merged |
---|---|
Merged at revision: | 716 |
Proposed branch: | lp:~brian-murray/update-notifier/python3 |
Merge into: | lp:update-notifier/ubuntu |
Diff against target: |
552 lines (+106/-74) 8 files modified
data/apt_check.py (+35/-25) data/backend_helper.py (+17/-14) data/hooks.py (+25/-19) data/package-data-downloader (+9/-7) debian/changelog (+9/-0) debian/control (+9/-7) debian/rules (+1/-1) tests/test_package-data-downloader.py (+1/-1) |
To merge this branch: | bzr merge lp:~brian-murray/update-notifier/python3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Adam Conrad | Pending | ||
Steve Langasek | Pending | ||
Review via email: mp+110429@code.launchpad.net |
This proposal supersedes a proposal from 2012-06-13.
Commit message
Description of the change
Porting of update-notifier to python3.
This is also dependent on python3-debian being available.
Adam Conrad (adconrad) wrote : Posted in a previous version of this proposal | # |
Steve Langasek (vorlon) wrote : Posted in a previous version of this proposal | # |
+ outstream.
isn't the map() redundant here?
-SYNPATIC_DESKTOP = ["--desktop",
- "/usr/share/
+SYNPATIC_DESKTOP = ["--desktop",
+ "/usr/share/
Unrelated, but I guess the variable name could be spell-checked :)
There's one point in the data/package-
Steve Langasek (vorlon) wrote : Posted in a previous version of this proposal | # |
Merge conflict from landing the PEP8 whitespace changes separately on each branch; should be resolved so we can review.
Brian Murray (brian-murray) wrote : Posted in a previous version of this proposal | # |
My local diff of package-
--- ../main/
+++ data/package-
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""Process new requests to download per-package data"""
# Copyright (C) 2012 Canonical Ltd
@@ -16,13 +16,15 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+from __future__ import print_function
+
import glob
import os
import sys
import subprocess
import re
import traceback
-import urllib
+import urllib.request
import debian.deb822
import string
import apt
@@ -184,7 +186,7 @@ def process_
if proxies:
- urllib._urlopener = urllib.
+ urllib.
except Exception:
pass
@@ -209,13 +211,13 @@ def process_
files = []
sums = []
for para in hook.iter_
- if para.has_
+ if 'script' in para:
if not files:
- if para.has_
+ if 'should-download' in para:
@@ -230,8 +232,8 @@ def process_
# Download each file and verify the sum
- print "%s: downloading %s" % (relfile, files[i])
- dest_file = urllib.
+ print("%s: downloading %s" % (relfile, files[i]))
+ dest_file = urllib.
I hope that Launchpad is just slow here.
- 716. By Brian Murray
-
merge with upstream
Preview Diff
1 | === modified file 'data/apt_check.py' | |||
2 | --- data/apt_check.py 2012-06-12 09:09:32 +0000 | |||
3 | +++ data/apt_check.py 2012-06-14 22:18:20 +0000 | |||
4 | @@ -1,5 +1,6 @@ | |||
6 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python3 |
7 | 2 | 2 | ||
8 | 3 | from __future__ import print_function | ||
9 | 3 | 4 | ||
10 | 4 | #nice apt-get -s -o Debug::NoLocking=true upgrade | grep ^Inst | 5 | #nice apt-get -s -o Debug::NoLocking=true upgrade | grep ^Inst |
11 | 5 | 6 | ||
12 | @@ -15,27 +16,32 @@ | |||
13 | 15 | DISTRO = subprocess.Popen(["lsb_release","-c","-s"], | 16 | DISTRO = subprocess.Popen(["lsb_release","-c","-s"], |
14 | 16 | stdout=subprocess.PIPE).communicate()[0].strip() | 17 | stdout=subprocess.PIPE).communicate()[0].strip() |
15 | 17 | 18 | ||
16 | 19 | |||
17 | 18 | def _(msg): | 20 | def _(msg): |
18 | 19 | return gettext.dgettext("update-notifier", msg) | 21 | return gettext.dgettext("update-notifier", msg) |
19 | 20 | 22 | ||
20 | 23 | |||
21 | 21 | def _handleException(type, value, tb): | 24 | def _handleException(type, value, tb): |
22 | 22 | sys.stderr.write("E: "+ _("Unknown Error: '%s' (%s)") % (type,value)) | 25 | sys.stderr.write("E: "+ _("Unknown Error: '%s' (%s)") % (type,value)) |
23 | 23 | sys.exit(-1) | 26 | sys.exit(-1) |
24 | 24 | 27 | ||
26 | 25 | def clean(cache,depcache): | 28 | |
27 | 29 | def clean(cache, depcache): | ||
28 | 26 | " unmark (clean) all changes from the given depcache " | 30 | " unmark (clean) all changes from the given depcache " |
29 | 27 | # mvo: looping is too inefficient with the new auto-mark code | 31 | # mvo: looping is too inefficient with the new auto-mark code |
30 | 28 | #for pkg in cache.Packages: | 32 | #for pkg in cache.Packages: |
31 | 29 | # depcache.MarkKeep(pkg) | 33 | # depcache.MarkKeep(pkg) |
32 | 30 | depcache.init() | 34 | depcache.init() |
33 | 31 | 35 | ||
35 | 32 | def saveDistUpgrade(cache,depcache): | 36 | |
36 | 37 | def saveDistUpgrade(cache, depcache): | ||
37 | 33 | """ this functions mimics a upgrade but will never remove anything """ | 38 | """ this functions mimics a upgrade but will never remove anything """ |
38 | 34 | depcache.upgrade(True) | 39 | depcache.upgrade(True) |
39 | 35 | if depcache.del_count > 0: | 40 | if depcache.del_count > 0: |
41 | 36 | clean(cache,depcache) | 41 | clean(cache, depcache) |
42 | 37 | depcache.upgrade() | 42 | depcache.upgrade() |
43 | 38 | 43 | ||
44 | 44 | |||
45 | 39 | def isSecurityUpgrade(ver): | 45 | def isSecurityUpgrade(ver): |
46 | 40 | " check if the given version is a security update (or masks one) " | 46 | " check if the given version is a security update (or masks one) " |
47 | 41 | security_pockets = [("Ubuntu", "%s-security" % DISTRO), | 47 | security_pockets = [("Ubuntu", "%s-security" % DISTRO), |
48 | @@ -48,12 +54,13 @@ | |||
49 | 48 | return True | 54 | return True |
50 | 49 | return False | 55 | return False |
51 | 50 | 56 | ||
52 | 57 | |||
53 | 51 | def write_package_names(outstream, cache, depcache): | 58 | def write_package_names(outstream, cache, depcache): |
54 | 52 | " write out package names that change to outstream " | 59 | " write out package names that change to outstream " |
59 | 53 | pkgs = filter(lambda pkg: | 60 | pkgs = [pkg for pkg in cache.packages if depcache.marked_install(pkg) or |
60 | 54 | depcache.marked_install(pkg) or depcache.marked_upgrade(pkg), | 61 | depcache.marked_upgrade(pkg)] |
61 | 55 | cache.packages) | 62 | outstream.write("\n".join(map([p.name for p in pkgs]))) |
62 | 56 | outstream.write("\n".join(map(lambda p: p.name, pkgs))) | 63 | |
63 | 57 | 64 | ||
64 | 58 | def write_human_readable_summary(outstream, upgrades, security_updates): | 65 | def write_human_readable_summary(outstream, upgrades, security_updates): |
65 | 59 | " write out human summary summary to outstream " | 66 | " write out human summary summary to outstream " |
66 | @@ -67,6 +74,8 @@ | |||
67 | 67 | "%i updates are security updates.", | 74 | "%i updates are security updates.", |
68 | 68 | security_updates) % security_updates) | 75 | security_updates) % security_updates) |
69 | 69 | outstream.write("\n") | 76 | outstream.write("\n") |
70 | 77 | |||
71 | 78 | |||
72 | 70 | def init(): | 79 | def init(): |
73 | 71 | " init the system, be nice " | 80 | " init the system, be nice " |
74 | 72 | # FIXME: do a ionice here too? | 81 | # FIXME: do a ionice here too? |
75 | @@ -74,24 +83,25 @@ | |||
76 | 74 | apt_pkg.init() | 83 | apt_pkg.init() |
77 | 75 | # force apt to build its caches in memory for now to make sure | 84 | # force apt to build its caches in memory for now to make sure |
78 | 76 | # that there is no race when the pkgcache file gets re-generated | 85 | # that there is no race when the pkgcache file gets re-generated |
81 | 77 | apt_pkg.config.set("Dir::Cache::pkgcache","") | 86 | apt_pkg.config.set("Dir::Cache::pkgcache", "") |
82 | 78 | 87 | ||
83 | 88 | |||
84 | 79 | def run(options=None): | 89 | def run(options=None): |
85 | 80 | 90 | ||
86 | 81 | # we are run in "are security updates installed automatically?" | 91 | # we are run in "are security updates installed automatically?" |
87 | 82 | # question mode | 92 | # question mode |
88 | 83 | if options.security_updates_unattended: | 93 | if options.security_updates_unattended: |
89 | 84 | res = apt_pkg.config.find_i("APT::Periodic::Unattended-Upgrade", 0) | 94 | res = apt_pkg.config.find_i("APT::Periodic::Unattended-Upgrade", 0) |
91 | 85 | #print res | 95 | #print(res) |
92 | 86 | sys.exit(res) | 96 | sys.exit(res) |
93 | 87 | 97 | ||
94 | 88 | # get caches | 98 | # get caches |
95 | 89 | try: | 99 | try: |
96 | 90 | cache = apt_pkg.Cache(apt.progress.base.OpProgress()) | 100 | cache = apt_pkg.Cache(apt.progress.base.OpProgress()) |
98 | 91 | except SystemError, e: | 101 | except SystemError as e: |
99 | 92 | sys.stderr.write("E: "+ _("Error: Opening the cache (%s)") % e) | 102 | sys.stderr.write("E: "+ _("Error: Opening the cache (%s)") % e) |
100 | 93 | sys.exit(-1) | 103 | sys.exit(-1) |
102 | 94 | depcache = apt_pkg.DepCache(cache) | 104 | depcache = apt_pkg.GetDepCache(cache) |
103 | 95 | 105 | ||
104 | 96 | # read the pin files | 106 | # read the pin files |
105 | 97 | depcache.read_pinfile() | 107 | depcache.read_pinfile() |
106 | @@ -108,8 +118,8 @@ | |||
107 | 108 | 118 | ||
108 | 109 | # do the upgrade (not dist-upgrade!) | 119 | # do the upgrade (not dist-upgrade!) |
109 | 110 | try: | 120 | try: |
112 | 111 | saveDistUpgrade(cache,depcache) | 121 | saveDistUpgrade(cache, depcache) |
113 | 112 | except SystemError, e: | 122 | except SystemError as e: |
114 | 113 | sys.stderr.write("E: "+ _("Error: Marking the upgrade (%s)") % e) | 123 | sys.stderr.write("E: "+ _("Error: Marking the upgrade (%s)") % e) |
115 | 114 | sys.exit(-1) | 124 | sys.exit(-1) |
116 | 115 | 125 | ||
117 | @@ -128,16 +138,16 @@ | |||
118 | 128 | continue | 138 | continue |
119 | 129 | 139 | ||
120 | 130 | # check for security upgrades | 140 | # check for security upgrades |
122 | 131 | upgrades = upgrades + 1 | 141 | upgrades = upgrades + 1 |
123 | 132 | if isSecurityUpgrade(cand_ver): | 142 | if isSecurityUpgrade(cand_ver): |
124 | 133 | security_updates += 1 | 143 | security_updates += 1 |
125 | 134 | continue | 144 | continue |
126 | 135 | 145 | ||
128 | 136 | # now check for security updates that are masked by a | 146 | # now check for security updates that are masked by a |
129 | 137 | # canidate version from another repo (-proposed or -updates) | 147 | # canidate version from another repo (-proposed or -updates) |
130 | 138 | for ver in pkg.version_list: | 148 | for ver in pkg.version_list: |
131 | 139 | if (inst_ver and apt_pkg.version_compare(ver.ver_str, inst_ver.ver_str) <= 0): | 149 | if (inst_ver and apt_pkg.version_compare(ver.ver_str, inst_ver.ver_str) <= 0): |
133 | 140 | #print "skipping '%s' " % ver.VerStr | 150 | #print("skipping '%s' " % ver.VerStr) |
134 | 141 | continue | 151 | continue |
135 | 142 | if isSecurityUpgrade(ver): | 152 | if isSecurityUpgrade(ver): |
136 | 143 | security_updates += 1 | 153 | security_updates += 1 |
137 | @@ -149,19 +159,19 @@ | |||
138 | 149 | elif options and options.readable_output: | 159 | elif options and options.readable_output: |
139 | 150 | write_human_readable_summary(sys.stdout, upgrades, security_updates) | 160 | write_human_readable_summary(sys.stdout, upgrades, security_updates) |
140 | 151 | else: | 161 | else: |
142 | 152 | # print the number of regular upgrades and the number of | 162 | # print the number of regular upgrades and the number of |
143 | 153 | # security upgrades | 163 | # security upgrades |
145 | 154 | sys.stderr.write("%s;%s" % (upgrades,security_updates)) | 164 | sys.stderr.write("%s;%s" % (upgrades, security_updates)) |
146 | 155 | 165 | ||
147 | 156 | # return the number of upgrades (if its used as a module) | 166 | # return the number of upgrades (if its used as a module) |
152 | 157 | return(upgrades,security_updates) | 167 | return(upgrades, security_updates) |
153 | 158 | 168 | ||
154 | 159 | 169 | ||
155 | 160 | if __name__ == "__main__": | 170 | if __name__ == "__main__": |
156 | 161 | # setup a exception handler to make sure that uncaught stuff goes | 171 | # setup a exception handler to make sure that uncaught stuff goes |
157 | 162 | # to the notifier | 172 | # to the notifier |
158 | 163 | sys.excepthook = _handleException | 173 | sys.excepthook = _handleException |
160 | 164 | 174 | ||
161 | 165 | # gettext | 175 | # gettext |
162 | 166 | APP="update-notifier" | 176 | APP="update-notifier" |
163 | 167 | DIR="/usr/share/locale" | 177 | DIR="/usr/share/locale" |
164 | 168 | 178 | ||
165 | === modified file 'data/backend_helper.py' | |||
166 | --- data/backend_helper.py 2011-08-10 13:54:37 +0000 | |||
167 | +++ data/backend_helper.py 2012-06-14 22:18:20 +0000 | |||
168 | @@ -1,4 +1,4 @@ | |||
170 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python3 |
171 | 2 | 2 | ||
172 | 3 | import argparse | 3 | import argparse |
173 | 4 | import dbus | 4 | import dbus |
174 | @@ -8,8 +8,8 @@ | |||
175 | 8 | import sys | 8 | import sys |
176 | 9 | 9 | ||
177 | 10 | GKSU = ["/usr/bin/gksu"] | 10 | GKSU = ["/usr/bin/gksu"] |
180 | 11 | SYNPATIC_DESKTOP = ["--desktop", | 11 | SYNAPTIC_DESKTOP = ["--desktop", |
181 | 12 | "/usr/share/applications/synaptic.desktop", | 12 | "/usr/share/applications/synaptic.desktop", |
182 | 13 | "--"] | 13 | "--"] |
183 | 14 | HAVE_APTDAEMON = False | 14 | HAVE_APTDAEMON = False |
184 | 15 | try: | 15 | try: |
185 | @@ -18,6 +18,7 @@ | |||
186 | 18 | except ImportError: | 18 | except ImportError: |
187 | 19 | pass | 19 | pass |
188 | 20 | 20 | ||
189 | 21 | |||
190 | 21 | # show updates | 22 | # show updates |
191 | 22 | def show_updates(): | 23 | def show_updates(): |
192 | 23 | """ show updates using update-manager """ | 24 | """ show updates using update-manager """ |
193 | @@ -38,9 +39,10 @@ | |||
194 | 38 | dia.run() | 39 | dia.run() |
195 | 39 | Gtk.main() | 40 | Gtk.main() |
196 | 40 | return trans.exit == enums.EXIT_SUCCESS | 41 | return trans.exit == enums.EXIT_SUCCESS |
198 | 41 | 42 | ||
199 | 43 | |||
200 | 42 | def _install_all_updates_gksu(): | 44 | def _install_all_updates_gksu(): |
202 | 43 | cmd = GKSU + SYNPATIC_DESKTOP + [ "/usr/sbin/synaptic ", | 45 | cmd = GKSU + SYNAPTIC_DESKTOP + ["/usr/sbin/synaptic ", |
203 | 44 | "--dist-upgrade-mode", | 46 | "--dist-upgrade-mode", |
204 | 45 | "--non-interactive", | 47 | "--non-interactive", |
205 | 46 | "--hide-main-window", | 48 | "--hide-main-window", |
206 | @@ -48,6 +50,7 @@ | |||
207 | 48 | ] | 50 | ] |
208 | 49 | return subprocess.call(cmd) | 51 | return subprocess.call(cmd) |
209 | 50 | 52 | ||
210 | 53 | |||
211 | 51 | def install_all_updates(): | 54 | def install_all_updates(): |
212 | 52 | """ install all updates either with synaptic or aptdaemon """ | 55 | """ install all updates either with synaptic or aptdaemon """ |
213 | 53 | if HAVE_APTDAEMON: | 56 | if HAVE_APTDAEMON: |
214 | @@ -69,14 +72,16 @@ | |||
215 | 69 | Gtk.main() | 72 | Gtk.main() |
216 | 70 | return trans.exit == enums.EXIT_SUCCESS | 73 | return trans.exit == enums.EXIT_SUCCESS |
217 | 71 | 74 | ||
218 | 75 | |||
219 | 72 | def _check_updates_gtk(): | 76 | def _check_updates_gtk(): |
221 | 73 | cmd = GKSU + SYNPATIC_DESKTOP + ["/usr/sbin/synaptic", | 77 | cmd = GKSU + SYNAPTIC_DESKTOP + ["/usr/sbin/synaptic", |
222 | 74 | "--update-at-startup", | 78 | "--update-at-startup", |
223 | 75 | "--non-interactive", | 79 | "--non-interactive", |
224 | 76 | "--hide-main-window", | 80 | "--hide-main-window", |
225 | 77 | ] | 81 | ] |
226 | 78 | subprocess.call(cmd) | 82 | subprocess.call(cmd) |
227 | 79 | 83 | ||
228 | 84 | |||
229 | 80 | def check_updates(): | 85 | def check_updates(): |
230 | 81 | """ check for updates either with aptdaemon or synaptic """ | 86 | """ check for updates either with aptdaemon or synaptic """ |
231 | 82 | if HAVE_APTDAEMON: | 87 | if HAVE_APTDAEMON: |
232 | @@ -88,7 +93,7 @@ | |||
233 | 88 | # start packagemanager | 93 | # start packagemanager |
234 | 89 | def start_packagemanager(): | 94 | def start_packagemanager(): |
235 | 90 | if os.path.exists("/usr/sbin/synaptic"): | 95 | if os.path.exists("/usr/sbin/synaptic"): |
237 | 91 | cmd = GKSU + SYNPATIC_DESKTOP + ["/usr/sbin/synaptic"] | 96 | cmd = GKSU + SYNAPTIC_DESKTOP + ["/usr/sbin/synaptic"] |
238 | 92 | return subprocess.call(cmd) | 97 | return subprocess.call(cmd) |
239 | 93 | elif os.path.exists("/usr/bin/software-center"): | 98 | elif os.path.exists("/usr/bin/software-center"): |
240 | 94 | return subprocess.call(["/usr/bin/software-center"]) | 99 | return subprocess.call(["/usr/bin/software-center"]) |
241 | @@ -111,18 +116,17 @@ | |||
242 | 111 | if os.path.exists("/usr/bin/software-center"): | 116 | if os.path.exists("/usr/bin/software-center"): |
243 | 112 | subprocess.call(["/usr/bin/software-center"]) | 117 | subprocess.call(["/usr/bin/software-center"]) |
244 | 113 | 118 | ||
245 | 119 | |||
246 | 114 | def _add_cdrom_synaptic(mount_path): | 120 | def _add_cdrom_synaptic(mount_path): |
248 | 115 | cmd = GKSU + SYNPATIC_DESKTOP + ["synaptic", "--add-cdrom", mount_path] | 121 | cmd = GKSU + SYNAPTIC_DESKTOP + ["synaptic", "--add-cdrom", mount_path] |
249 | 116 | return subprocess.call(cmd) | 122 | return subprocess.call(cmd) |
250 | 117 | 123 | ||
251 | 124 | |||
252 | 118 | def add_cdrom(mount_path): | 125 | def add_cdrom(mount_path): |
253 | 119 | if os.path.exists("/usr/sbin/synaptic"): | 126 | if os.path.exists("/usr/sbin/synaptic"): |
254 | 120 | _add_cdrom_synaptic(mount_path) | 127 | _add_cdrom_synaptic(mount_path) |
255 | 121 | else: | 128 | else: |
256 | 122 | _add_cdrom_sp(mount_path) | 129 | _add_cdrom_sp(mount_path) |
257 | 123 | |||
258 | 124 | |||
259 | 125 | |||
260 | 126 | 130 | ||
261 | 127 | 131 | ||
262 | 128 | if __name__ == "__main__": | 132 | if __name__ == "__main__": |
263 | @@ -149,7 +153,7 @@ | |||
264 | 149 | command = subparser.add_parser("add_cdrom") | 153 | command = subparser.add_parser("add_cdrom") |
265 | 150 | command.add_argument("mount_path") | 154 | command.add_argument("mount_path") |
266 | 151 | command.set_defaults(command="add_cdrom") | 155 | command.set_defaults(command="add_cdrom") |
268 | 152 | 156 | ||
269 | 153 | args = parser.parse_args() | 157 | args = parser.parse_args() |
270 | 154 | if args.debug: | 158 | if args.debug: |
271 | 155 | logging.basicConfig(level=logging.DEBUG) | 159 | logging.basicConfig(level=logging.DEBUG) |
272 | @@ -159,10 +163,9 @@ | |||
273 | 159 | func_name = args.command | 163 | func_name = args.command |
274 | 160 | f_kwargs = {} | 164 | f_kwargs = {} |
275 | 161 | f = globals()[func_name] | 165 | f = globals()[func_name] |
277 | 162 | if args.command == "add_cdrom": | 166 | if args.command == "add_cdrom": |
278 | 163 | f_kwargs["mount_path"] = args.mount_path | 167 | f_kwargs["mount_path"] = args.mount_path |
279 | 164 | res = f(**f_kwargs) | 168 | res = f(**f_kwargs) |
280 | 165 | 169 | ||
281 | 166 | if not res: | 170 | if not res: |
282 | 167 | sys.exit(1) | 171 | sys.exit(1) |
283 | 168 | |||
284 | 169 | 172 | ||
285 | === modified file 'data/hooks.py' | |||
286 | --- data/hooks.py 2010-08-23 08:58:54 +0000 | |||
287 | +++ data/hooks.py 2012-06-14 22:18:20 +0000 | |||
288 | @@ -1,19 +1,26 @@ | |||
290 | 1 | #!/usr/bin/python2.4 | 1 | #!/usr/bin/python3 |
291 | 2 | |||
292 | 3 | from __future__ import print_function | ||
293 | 2 | 4 | ||
294 | 3 | from optparse import OptionParser | 5 | from optparse import OptionParser |
298 | 4 | import user, string, dircache, sys, os.path | 6 | |
299 | 5 | 7 | import dircache | |
300 | 6 | 8 | import os.path | |
301 | 9 | import string | ||
302 | 10 | import sys | ||
303 | 11 | import user | ||
304 | 12 | |||
305 | 13 | |||
306 | 7 | class HookFiles(object): | 14 | class HookFiles(object): |
307 | 8 | """ represents all hook files """ | 15 | """ represents all hook files """ |
308 | 9 | 16 | ||
309 | 10 | # the hooks are stored here | 17 | # the hooks are stored here |
310 | 11 | hookDir = "/var/lib/update-notifier/user.d/" | 18 | hookDir = "/var/lib/update-notifier/user.d/" |
312 | 12 | 19 | ||
313 | 13 | class HookFile(object): | 20 | class HookFile(object): |
314 | 14 | """ represents a single hook file """ | 21 | """ represents a single hook file """ |
317 | 15 | __slots__ = [ "filename", "mtime", "cmd_run", "seen" ] | 22 | __slots__ = ["filename", "mtime", "cmd_run", "seen"] |
318 | 16 | 23 | ||
319 | 17 | def __init__(self, filename): | 24 | def __init__(self, filename): |
320 | 18 | self.filename = filename | 25 | self.filename = filename |
321 | 19 | self.mtime = os.stat(HookFiles.hookDir+filename).st_mtime | 26 | self.mtime = os.stat(HookFiles.hookDir+filename).st_mtime |
322 | @@ -24,17 +31,16 @@ | |||
323 | 24 | """ show the summary for the notification """ | 31 | """ show the summary for the notification """ |
324 | 25 | # FIXME: read rfc822 style file and get the i18n version of | 32 | # FIXME: read rfc822 style file and get the i18n version of |
325 | 26 | # "Name" | 33 | # "Name" |
327 | 27 | pass | 34 | pass |
328 | 28 | summary = property(summary) | 35 | summary = property(summary) |
329 | 29 | 36 | ||
330 | 30 | def description(self): | 37 | def description(self): |
331 | 31 | """ show a long description for the notification """ | 38 | """ show a long description for the notification """ |
332 | 32 | # FIXME: read rfc822 style file and get the i18n version of | 39 | # FIXME: read rfc822 style file and get the i18n version of |
333 | 33 | # "Description", convert "\n" -> " " and strstrip it afterwards | 40 | # "Description", convert "\n" -> " " and strstrip it afterwards |
335 | 34 | pass | 41 | pass |
336 | 35 | description = property(description) | 42 | description = property(description) |
337 | 36 | 43 | ||
338 | 37 | |||
339 | 38 | def __init__(self): | 44 | def __init__(self): |
340 | 39 | self._hooks = {} | 45 | self._hooks = {} |
341 | 40 | self._readSeenFile() | 46 | self._readSeenFile() |
342 | @@ -49,25 +55,25 @@ | |||
343 | 49 | if os.path.exists(hooks_seen): | 55 | if os.path.exists(hooks_seen): |
344 | 50 | for line in open(hooks_seen): | 56 | for line in open(hooks_seen): |
345 | 51 | filename, mtime, cmd_run = string.split(line) | 57 | filename, mtime, cmd_run = string.split(line) |
348 | 52 | if os.path.exists(self.hookDir+filename) and \ | 58 | if os.path.exists(self.hookDir + filename) and \ |
349 | 53 | not self._hooks.has_key(filename): | 59 | not filename in self._hooks: |
350 | 54 | h = self.HookFile(filename) | 60 | h = self.HookFile(filename) |
351 | 55 | h.mtime = mtime | 61 | h.mtime = mtime |
352 | 56 | h.cmd_run = cmd_run | 62 | h.cmd_run = cmd_run |
353 | 57 | h.seen = True | 63 | h.seen = True |
354 | 58 | # check if file was motified since we last saw it | 64 | # check if file was motified since we last saw it |
356 | 59 | if os.stat(self.hookDir+filename).st_mtime > int(mtime): | 65 | if os.stat(self.hookDir + filename).st_mtime > int(mtime): |
357 | 60 | h.seen = False | 66 | h.seen = False |
358 | 61 | self._hooks[filename] = h | 67 | self._hooks[filename] = h |
359 | 62 | 68 | ||
360 | 63 | def _update(self): | 69 | def _update(self): |
361 | 64 | """ update hook dict with the current state on the fs """ | 70 | """ update hook dict with the current state on the fs """ |
362 | 65 | for hook in dircache.listdir(self.hookDir): | 71 | for hook in dircache.listdir(self.hookDir): |
364 | 66 | if self._hooks.has_key(hook): | 72 | if hook in self._hooks: |
365 | 67 | # we have it already, check if it was motified since | 73 | # we have it already, check if it was motified since |
366 | 68 | # we last saw it | 74 | # we last saw it |
367 | 69 | h = self._hooks[hook] | 75 | h = self._hooks[hook] |
369 | 70 | if os.stat(self.hookDir+hook).st_mtime > int(h.mtime): | 76 | if os.stat(self.hookDir + hook).st_mtime > int(h.mtime): |
370 | 71 | h.seen = False | 77 | h.seen = False |
371 | 72 | else: | 78 | else: |
372 | 73 | self._hooks[hook] = self.HookFile(hook) | 79 | self._hooks[hook] = self.HookFile(hook) |
373 | @@ -80,19 +86,20 @@ | |||
374 | 80 | if not self._hooks[hook].seen: | 86 | if not self._hooks[hook].seen: |
375 | 81 | new.append(self._hooks[hook]) | 87 | new.append(self._hooks[hook]) |
376 | 82 | return new | 88 | return new |
378 | 83 | 89 | ||
379 | 84 | 90 | ||
380 | 85 | def check(): | 91 | def check(): |
381 | 86 | hooks = HookFiles() | 92 | hooks = HookFiles() |
382 | 87 | new = hooks.checkNew() | 93 | new = hooks.checkNew() |
383 | 88 | return len(new) | 94 | return len(new) |
384 | 89 | 95 | ||
385 | 96 | |||
386 | 90 | def test(): | 97 | def test(): |
387 | 91 | hooks = HookFiles() | 98 | hooks = HookFiles() |
388 | 92 | new = hooks.checkNew() | 99 | new = hooks.checkNew() |
390 | 93 | print "Hooks: %s" % len(new) | 100 | print("Hooks: %s" % len(new)) |
391 | 94 | for hook in hooks._hooks: | 101 | for hook in hooks._hooks: |
393 | 95 | print hooks._hooks[hook].notification | 102 | print(hooks._hooks[hook].notification) |
394 | 96 | 103 | ||
395 | 97 | 104 | ||
396 | 98 | if __name__ == "__main__": | 105 | if __name__ == "__main__": |
397 | @@ -105,7 +112,6 @@ | |||
398 | 105 | default=False, help="run test") | 112 | default=False, help="run test") |
399 | 106 | (options, args) = parser.parse_args() | 113 | (options, args) = parser.parse_args() |
400 | 107 | 114 | ||
401 | 108 | |||
402 | 109 | if options.check: | 115 | if options.check: |
403 | 110 | sys.exit(check()) | 116 | sys.exit(check()) |
404 | 111 | elif options.run: | 117 | elif options.run: |
405 | 112 | 118 | ||
406 | === modified file 'data/package-data-downloader' | |||
407 | --- data/package-data-downloader 2012-06-13 22:49:33 +0000 | |||
408 | +++ data/package-data-downloader 2012-06-14 22:18:20 +0000 | |||
409 | @@ -1,4 +1,4 @@ | |||
411 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python3 |
412 | 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
413 | 3 | """Process new requests to download per-package data""" | 3 | """Process new requests to download per-package data""" |
414 | 4 | # Copyright (C) 2012 Canonical Ltd | 4 | # Copyright (C) 2012 Canonical Ltd |
415 | @@ -16,13 +16,15 @@ | |||
416 | 16 | # with this program; if not, write to the Free Software Foundation, Inc., | 16 | # with this program; if not, write to the Free Software Foundation, Inc., |
417 | 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
418 | 18 | 18 | ||
419 | 19 | from __future__ import print_function | ||
420 | 20 | |||
421 | 19 | import glob | 21 | import glob |
422 | 20 | import os | 22 | import os |
423 | 21 | import sys | 23 | import sys |
424 | 22 | import subprocess | 24 | import subprocess |
425 | 23 | import re | 25 | import re |
426 | 24 | import traceback | 26 | import traceback |
428 | 25 | import urllib | 27 | import urllib.request |
429 | 26 | import debian.deb822 | 28 | import debian.deb822 |
430 | 27 | import string | 29 | import string |
431 | 28 | import apt | 30 | import apt |
432 | @@ -184,7 +186,7 @@ | |||
433 | 184 | pass | 186 | pass |
434 | 185 | 187 | ||
435 | 186 | if proxies: | 188 | if proxies: |
437 | 187 | urllib._urlopener = urllib.FancyURLopener(proxies) | 189 | urllib.request._urlopener = urllib.request.FancyURLopener(proxies) |
438 | 188 | except Exception: | 190 | except Exception: |
439 | 189 | pass | 191 | pass |
440 | 190 | 192 | ||
441 | @@ -209,13 +211,13 @@ | |||
442 | 209 | files = [] | 211 | files = [] |
443 | 210 | sums = [] | 212 | sums = [] |
444 | 211 | for para in hook.iter_paragraphs(open(file)): | 213 | for para in hook.iter_paragraphs(open(file)): |
446 | 212 | if para.has_key('script'): | 214 | if 'script' in para: |
447 | 213 | if not files: | 215 | if not files: |
448 | 214 | record_failure(relfile) | 216 | record_failure(relfile) |
449 | 215 | break | 217 | break |
450 | 216 | command = [para['script']] | 218 | command = [para['script']] |
451 | 217 | 219 | ||
453 | 218 | if para.has_key('should-download'): | 220 | if 'should-download' in para: |
454 | 219 | db = debconf.DebconfCommunicator('update-notifier') | 221 | db = debconf.DebconfCommunicator('update-notifier') |
455 | 220 | try: | 222 | try: |
456 | 221 | should = db.get(para['should-download']) | 223 | should = db.get(para['should-download']) |
457 | @@ -230,8 +232,8 @@ | |||
458 | 230 | # Download each file and verify the sum | 232 | # Download each file and verify the sum |
459 | 231 | try: | 233 | try: |
460 | 232 | for i in range(len(files)): | 234 | for i in range(len(files)): |
463 | 233 | print "%s: downloading %s" % (relfile, files[i]) | 235 | print("%s: downloading %s" % (relfile, files[i])) |
464 | 234 | dest_file = urllib.urlretrieve(files[i])[0] | 236 | dest_file = urllib.request.urlretrieve(files[i])[0] |
465 | 235 | output = subprocess.check_output(["sha256sum", dest_file]) | 237 | output = subprocess.check_output(["sha256sum", dest_file]) |
466 | 236 | output = output.split(' ')[0] | 238 | output = output.split(' ')[0] |
467 | 237 | if output == sums[i]: | 239 | if output == sums[i]: |
468 | 238 | 240 | ||
469 | === modified file 'debian/changelog' | |||
470 | --- debian/changelog 2012-06-12 09:12:28 +0000 | |||
471 | +++ debian/changelog 2012-06-14 22:18:20 +0000 | |||
472 | @@ -1,3 +1,12 @@ | |||
473 | 1 | update-notifier (0.119ubuntu14) UNRELEASED; urgency=low | ||
474 | 2 | |||
475 | 3 | * Port to Python 3 | ||
476 | 4 | - Use the new python-apt API since the legacy API is not available | ||
477 | 5 | in Python 3. | ||
478 | 6 | - Various and pyflakes, whitespace, style, line length fixes. | ||
479 | 7 | |||
480 | 8 | -- Brian Murray <brian@ubuntu.com> Tue, 12 Jun 2012 08:35:48 -0700 | ||
481 | 9 | |||
482 | 1 | update-notifier (0.119ubuntu13) quantal; urgency=low | 10 | update-notifier (0.119ubuntu13) quantal; urgency=low |
483 | 2 | 11 | ||
484 | 3 | * data/apt_check.py: | 12 | * data/apt_check.py: |
485 | 4 | 13 | ||
486 | === modified file 'debian/control' | |||
487 | --- debian/control 2012-05-14 22:31:36 +0000 | |||
488 | +++ debian/control 2012-06-14 22:18:20 +0000 | |||
489 | @@ -12,25 +12,27 @@ | |||
490 | 12 | libx11-dev, | 12 | libx11-dev, |
491 | 13 | autotools-dev, | 13 | autotools-dev, |
492 | 14 | libappindicator3-dev, | 14 | libappindicator3-dev, |
494 | 15 | po-debconf | 15 | po-debconf, |
495 | 16 | python3 | ||
496 | 16 | Standards-Version: 3.8.4 | 17 | Standards-Version: 3.8.4 |
497 | 17 | Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-core-dev/update-notifier/ubuntu | 18 | Vcs-Bzr: http://bazaar.launchpad.net/~ubuntu-core-dev/update-notifier/ubuntu |
498 | 19 | X-Python3-Version: >= 3.2 | ||
499 | 18 | 20 | ||
500 | 19 | Package: update-notifier | 21 | Package: update-notifier |
501 | 20 | Architecture: any | 22 | Architecture: any |
502 | 21 | Depends: ${shlibs:Depends}, | 23 | Depends: ${shlibs:Depends}, |
503 | 22 | ${misc:Depends}, | 24 | ${misc:Depends}, |
504 | 23 | update-notifier-common (= ${source:Version}), | 25 | update-notifier-common (= ${source:Version}), |
507 | 24 | python, | 26 | python3, |
508 | 25 | python-dbus, | 27 | python3-dbus, |
509 | 26 | update-manager-gnome | update-manager, | 28 | update-manager-gnome | update-manager, |
510 | 27 | notification-daemon, | 29 | notification-daemon, |
511 | 28 | gksu | 30 | gksu |
512 | 29 | Recommends: apport-gtk, | 31 | Recommends: apport-gtk, |
514 | 30 | python-aptdaemon.gtk3widgets | synaptic, | 32 | python3-aptdaemon.gtk3widgets | synaptic, |
515 | 31 | software-properties-gtk, | 33 | software-properties-gtk, |
516 | 32 | anacron, | 34 | anacron, |
518 | 33 | aptdaemon | 35 | python3-aptdaemon |
519 | 34 | Suggests: ubuntu-system-service | 36 | Suggests: ubuntu-system-service |
520 | 35 | Description: Daemon which notifies about package updates | 37 | Description: Daemon which notifies about package updates |
521 | 36 | Puts an icon in the user's notification area when package updates are | 38 | Puts an icon in the user's notification area when package updates are |
522 | @@ -42,8 +44,8 @@ | |||
523 | 42 | Pre-Depends: dpkg (>= 1.15.7.2) | 44 | Pre-Depends: dpkg (>= 1.15.7.2) |
524 | 43 | Depends: ${shlibs:Depends}, | 45 | Depends: ${shlibs:Depends}, |
525 | 44 | ${misc:Depends}, | 46 | ${misc:Depends}, |
528 | 45 | python, | 47 | python3, |
529 | 46 | python-apt (>= 0.6.12), python-debian, debconf | 48 | python3-apt (>= 0.6.12), python3-debian, debconf |
530 | 47 | Recommends: libpam-modules (>= 1.0.1-9ubuntu3) | 49 | Recommends: libpam-modules (>= 1.0.1-9ubuntu3) |
531 | 48 | Suggests: gksu | 50 | Suggests: gksu |
532 | 49 | Description: Files shared between update-notifier and other packages | 51 | Description: Files shared between update-notifier and other packages |
533 | 50 | 52 | ||
534 | === modified file 'debian/rules' | |||
535 | --- debian/rules 2010-06-01 13:28:36 +0000 | |||
536 | +++ debian/rules 2012-06-14 22:18:20 +0000 | |||
537 | @@ -3,4 +3,4 @@ | |||
538 | 3 | export LDFLAGS += -Wl,-z,defs -Wl,-O1 -Wl,--as-needed | 3 | export LDFLAGS += -Wl,-z,defs -Wl,-O1 -Wl,--as-needed |
539 | 4 | 4 | ||
540 | 5 | %: | 5 | %: |
542 | 6 | dh $@ | 6 | dh $@ --with python3 |
543 | 7 | 7 | ||
544 | === modified file 'tests/test_package-data-downloader.py' | |||
545 | --- tests/test_package-data-downloader.py 2012-03-23 09:11:45 +0000 | |||
546 | +++ tests/test_package-data-downloader.py 2012-06-14 22:18:20 +0000 | |||
547 | @@ -1,4 +1,4 @@ | |||
549 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python3 |
550 | 2 | 2 | ||
551 | 3 | import os | 3 | import os |
552 | 4 | import shutil | 4 | import shutil |
Looks good to me, with the latest revision.