Merge lp:~brian.curtin/ubuntuone-control-panel/updater-logging into lp:ubuntuone-control-panel
- updater-logging
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Brian Curtin | ||||
Approved revision: | 402 | ||||
Merged at revision: | 394 | ||||
Proposed branch: | lp:~brian.curtin/ubuntuone-control-panel/updater-logging | ||||
Merge into: | lp:ubuntuone-control-panel | ||||
Diff against target: |
171 lines (+37/-27) 2 files modified
bin/ubuntuone-updater (+35/-25) ubuntuone/controlpanel/tests/test_web_client.py (+2/-2) |
||||
To merge this branch: | bzr merge lp:~brian.curtin/ubuntuone-control-panel/updater-logging | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
dobey (community) | Approve | ||
Paul Hummer (community) | Approve | ||
Mike McCracken (community) | Approve | ||
Review via email: mp+145030@code.launchpad.net |
Commit message
- Use logging functionality instead of printing messages to stdout (lp:1105447)
Description of the change
In order to make it easy (or even possible) to figure out what the updater is doing in a real environment, we need to move away from printing and to logging.
Paul Hummer (rockstar) : | # |
dobey (dobey) : | # |
dobey (dobey) wrote : | # |
8 -from __future__ import print_function
We should leave these, even when not calling print(), so that if anyone does add a print call in the future, it will fail if the old print statement style is used. I'd also ask to use unicode_literals here, but I'm not sure if it will cause problems in this code or not.
dobey (dobey) : | # |
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~brian.curtin/ubuntuone-control-panel/updater-logging into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.
*** Running DBus test suite ***
ubuntuone.
BaseTestCase
runTest ... [OK]
DBusServiceMa
test_
test_
DBusServiceTe
test_
test_
test_
test_
test_
test_
test_
test_
FileSyncTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
OperationsAut
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
...
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~brian.curtin/ubuntuone-control-panel/updater-logging into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.
*** Running DBus test suite ***
ubuntuone.
BaseTestCase
runTest ... [OK]
DBusServiceMa
test_
test_
DBusServiceTe
test_
test_
test_
test_
test_
test_
test_
test_
FileSyncTestCase
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
OperationsAut
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
test_
...
- 402. By Brian Curtin
-
Remove unused import
Preview Diff
1 | === modified file 'bin/ubuntuone-updater' | |||
2 | --- bin/ubuntuone-updater 2012-12-11 22:18:08 +0000 | |||
3 | +++ bin/ubuntuone-updater 2013-01-28 18:15:26 +0000 | |||
4 | @@ -20,10 +20,10 @@ | |||
5 | 20 | from __future__ import print_function | 20 | from __future__ import print_function |
6 | 21 | 21 | ||
7 | 22 | try: | 22 | try: |
9 | 23 | from urllib.request import urlopen, URLError | 23 | from urllib.request import urlopen |
10 | 24 | from urllib.parse import urljoin | 24 | from urllib.parse import urljoin |
11 | 25 | except ImportError: | 25 | except ImportError: |
13 | 26 | from urllib2 import urlopen, URLError | 26 | from urllib2 import urlopen |
14 | 27 | from urlparse import urljoin | 27 | from urlparse import urljoin |
15 | 28 | 28 | ||
16 | 29 | import argparse | 29 | import argparse |
17 | @@ -36,13 +36,17 @@ | |||
18 | 36 | 36 | ||
19 | 37 | from dirspec.utils import get_program_path | 37 | from dirspec.utils import get_program_path |
20 | 38 | 38 | ||
21 | 39 | from ubuntuone.controlpanel.logger import setup_logging | ||
22 | 40 | |||
23 | 41 | |||
24 | 42 | logger = setup_logging("updater") | ||
25 | 39 | 43 | ||
26 | 40 | U1SDTOOL_EXECUTABLE = 'u1sdtool' | 44 | U1SDTOOL_EXECUTABLE = 'u1sdtool' |
27 | 41 | DARWIN_APP_NAMES = {U1SDTOOL_EXECUTABLE: 'U1SDTool.app'} | 45 | DARWIN_APP_NAMES = {U1SDTOOL_EXECUTABLE: 'U1SDTool.app'} |
28 | 42 | 46 | ||
29 | 43 | 47 | ||
30 | 44 | if sys.platform == "darwin": | 48 | if sys.platform == "darwin": |
32 | 45 | from Cocoa import NSRunningApplication, NSLog | 49 | from Cocoa import NSRunningApplication |
33 | 46 | # IDs to terminate: Leave syncdaemon off this list, it is | 50 | # IDs to terminate: Leave syncdaemon off this list, it is |
34 | 47 | # terminated separately. | 51 | # terminated separately. |
35 | 48 | BUNDLE_IDS = ["com.ubuntu.sso.login-qt", | 52 | BUNDLE_IDS = ["com.ubuntu.sso.login-qt", |
36 | @@ -58,8 +62,9 @@ | |||
37 | 58 | def _do_download(url): | 62 | def _do_download(url): |
38 | 59 | """Download a URL and return the data it contains.""" | 63 | """Download a URL and return the data it contains.""" |
39 | 60 | resource = urlopen(url) | 64 | resource = urlopen(url) |
42 | 61 | if resource: | 65 | logger.info("Downloading {}".format(url)) |
43 | 62 | data = resource.read() | 66 | data = resource.read() |
44 | 67 | logger.info("Downloaded {}".format(url)) | ||
45 | 63 | return data | 68 | return data |
46 | 64 | 69 | ||
47 | 65 | 70 | ||
48 | @@ -72,7 +77,10 @@ | |||
49 | 72 | 77 | ||
50 | 73 | md5 = hashlib.md5() | 78 | md5 = hashlib.md5() |
51 | 74 | md5.update(data) | 79 | md5.update(data) |
53 | 75 | if checksum != md5.hexdigest(): | 80 | digest = md5.hexdigest() |
54 | 81 | if checksum != digest: | ||
55 | 82 | logger.error("Checksum mismatch. Expected {}, computed {}".format( | ||
56 | 83 | checksum, digest)) | ||
57 | 76 | raise Exception("Checksum mismatch") | 84 | raise Exception("Checksum mismatch") |
58 | 77 | 85 | ||
59 | 78 | fd, name = tempfile.mkstemp() | 86 | fd, name = tempfile.mkstemp() |
60 | @@ -89,7 +97,7 @@ | |||
61 | 89 | args.insert(0, 'open') | 97 | args.insert(0, 'open') |
62 | 90 | subprocess.Popen(args) | 98 | subprocess.Popen(args) |
63 | 91 | except Exception as exc: | 99 | except Exception as exc: |
65 | 92 | print("Unable to install {}: {}".format(url, exc)) | 100 | logger.error("Unable to install {}: {}".format(url, exc)) |
66 | 93 | return False | 101 | return False |
67 | 94 | return True | 102 | return True |
68 | 95 | 103 | ||
69 | @@ -100,8 +108,8 @@ | |||
70 | 100 | 108 | ||
71 | 101 | try: | 109 | try: |
72 | 102 | data = _do_download(args.url) | 110 | data = _do_download(args.url) |
75 | 103 | except URLError as err: | 111 | except Exception as exc: |
76 | 104 | print("Download failed: {}".format(err)) | 112 | logger.error("Download failed: {}".format(exc)) |
77 | 105 | return error | 113 | return error |
78 | 106 | 114 | ||
79 | 107 | try: | 115 | try: |
80 | @@ -110,21 +118,20 @@ | |||
81 | 110 | avail_ver = available["version"] | 118 | avail_ver = available["version"] |
82 | 111 | upgrade_available = avail_ver > args.current | 119 | upgrade_available = avail_ver > args.current |
83 | 112 | if upgrade_available: | 120 | if upgrade_available: |
86 | 113 | msg = "A new {} version is available at {}." | 121 | logger.info("A new {} version is available at {}.".format( |
87 | 114 | print(msg.format(args.release, available["url"])) | 122 | args.release, available["url"])) |
88 | 115 | elif avail_ver == args.current: | 123 | elif avail_ver == args.current: |
91 | 116 | print("Version {} is the latest {}.".format(args.current, | 124 | logger.info("Version {} is the latest {}.".format(args.current, |
92 | 117 | args.release)) | 125 | args.release)) |
93 | 118 | else: | 126 | else: |
97 | 119 | print("Warning: installed version {} newer than advertised" | 127 | logger.info("Installed version {} newer than advertised" |
98 | 120 | " available version {} somehow.".format(args.current, | 128 | " available version {}.".format(args.current, avail_ver)) |
96 | 121 | avail_ver)) | ||
99 | 122 | 129 | ||
100 | 123 | except Exception as exc: | 130 | except Exception as exc: |
101 | 124 | # Catch everything here. | 131 | # Catch everything here. |
102 | 125 | # KeyError is most likely, but we can't let this take us down. | 132 | # KeyError is most likely, but we can't let this take us down. |
105 | 126 | print("Exception while reading {}:".format(args.url), | 133 | logger.error("Exception while reading {}: {}, {}".format( |
106 | 127 | exc.__class__, exc.message) | 134 | args.url, exc.__class__, exc.message)) |
107 | 128 | return error | 135 | return error |
108 | 129 | 136 | ||
109 | 130 | return upgrade_available, available["url"], available["checksum"] | 137 | return upgrade_available, available["url"], available["checksum"] |
110 | @@ -134,21 +141,24 @@ | |||
111 | 134 | """Kill any running u1 processes.""" | 141 | """Kill any running u1 processes.""" |
112 | 135 | if sys.platform != "darwin": | 142 | if sys.platform != "darwin": |
113 | 136 | return | 143 | return |
115 | 137 | NSLog("in kill") | 144 | logger.info("Killing running processes") |
116 | 138 | 145 | ||
117 | 139 | try: | 146 | try: |
118 | 140 | u1sdtoolpath = get_program_path(U1SDTOOL_EXECUTABLE, | 147 | u1sdtoolpath = get_program_path(U1SDTOOL_EXECUTABLE, |
119 | 141 | app_names=DARWIN_APP_NAMES) | 148 | app_names=DARWIN_APP_NAMES) |
120 | 142 | |||
121 | 143 | out = subprocess.check_output([u1sdtoolpath, '-q']) | ||
122 | 144 | NSLog("u1sdtool said: {}".format(out)) | ||
123 | 145 | except Exception as e: | 149 | except Exception as e: |
125 | 146 | NSLog("exception running {} -q: {}".format(u1sdtoolpath, e)) | 150 | logger.error("exception getting u1sdtool's path: {}".format(e)) |
126 | 151 | else: | ||
127 | 152 | try: | ||
128 | 153 | out = subprocess.check_output([u1sdtoolpath, '-q']) | ||
129 | 154 | logger.info("u1sdtool said: {}".format(out)) | ||
130 | 155 | except Exception as e: | ||
131 | 156 | logger.error("exception running {} -q: {}".format(u1sdtoolpath, e)) | ||
132 | 147 | 157 | ||
133 | 148 | for id in BUNDLE_IDS: | 158 | for id in BUNDLE_IDS: |
134 | 149 | NSRA = NSRunningApplication | 159 | NSRA = NSRunningApplication |
135 | 150 | apps = NSRA.runningApplicationsWithBundleIdentifier_(id) | 160 | apps = NSRA.runningApplicationsWithBundleIdentifier_(id) |
137 | 151 | NSLog("id: {} apps: {}".format(id, apps)) | 161 | logger.info("id: {} apps: {}".format(id, apps)) |
138 | 152 | 162 | ||
139 | 153 | for app in apps: | 163 | for app in apps: |
140 | 154 | app.terminate() | 164 | app.terminate() |
141 | @@ -175,7 +185,7 @@ | |||
142 | 175 | 185 | ||
143 | 176 | if args.install and new_available: | 186 | if args.install and new_available: |
144 | 177 | installer = urljoin(args.url, file) | 187 | installer = urljoin(args.url, file) |
146 | 178 | print("Downloading and installing", installer) | 188 | logger.info("Downloading and installing {}".format(installer)) |
147 | 179 | kill_running_processes() | 189 | kill_running_processes() |
148 | 180 | return 1 if run_install(installer, checksum) else 0 | 190 | return 1 if run_install(installer, checksum) else 0 |
149 | 181 | 191 | ||
150 | 182 | 192 | ||
151 | === modified file 'ubuntuone/controlpanel/tests/test_web_client.py' | |||
152 | --- ubuntuone/controlpanel/tests/test_web_client.py 2012-10-26 15:55:18 +0000 | |||
153 | +++ ubuntuone/controlpanel/tests/test_web_client.py 2013-01-28 18:15:26 +0000 | |||
154 | @@ -19,7 +19,7 @@ | |||
155 | 19 | from urlparse import urlparse, parse_qs | 19 | from urlparse import urlparse, parse_qs |
156 | 20 | 20 | ||
157 | 21 | from twisted.internet import defer | 21 | from twisted.internet import defer |
159 | 22 | from twisted.web import resource | 22 | from twisted.web import http, resource |
160 | 23 | 23 | ||
161 | 24 | from ubuntuone.devtools.testing.txwebserver import HTTPWebServer | 24 | from ubuntuone.devtools.testing.txwebserver import HTTPWebServer |
162 | 25 | 25 | ||
163 | @@ -83,7 +83,7 @@ | |||
164 | 83 | devices_resource.contents = SAMPLE_RESOURCE | 83 | devices_resource.contents = SAMPLE_RESOURCE |
165 | 84 | root.putChild("devices", devices_resource) | 84 | root.putChild("devices", devices_resource) |
166 | 85 | root.putChild("throwerror", resource.NoResource()) | 85 | root.putChild("throwerror", resource.NoResource()) |
168 | 86 | unauthorized = resource.ErrorPage(resource.http.UNAUTHORIZED, | 86 | unauthorized = resource.ErrorPage(http.UNAUTHORIZED, |
169 | 87 | "Unauthrorized", "Unauthrorized") | 87 | "Unauthrorized", "Unauthrorized") |
170 | 88 | root.putChild("unauthorized", unauthorized) | 88 | root.putChild("unauthorized", unauthorized) |
171 | 89 | super(MockWebServer, self).__init__(root) | 89 | super(MockWebServer, self).__init__(root) |
Looks good, works for me on osx CLI