Merge lp:~brian.curtin/ubuntuone-control-panel/updater-logging into lp:ubuntuone-control-panel

Proposed by Brian Curtin
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
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.

To post a comment you must log in.
Revision history for this message
Mike McCracken (mikemc) wrote :

Looks good, works for me on osx CLI

review: Approve
Revision history for this message
Paul Hummer (rockstar) :
review: Approve
Revision history for this message
dobey (dobey) :
review: Needs Fixing
Revision history for this message
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.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (46.8 KiB)

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.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [OK]
    ...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (167.7 KiB)

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.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [OK]
    ...

402. By Brian Curtin

Remove unused import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntuone-updater'
--- bin/ubuntuone-updater 2012-12-11 22:18:08 +0000
+++ bin/ubuntuone-updater 2013-01-28 18:15:26 +0000
@@ -20,10 +20,10 @@
20from __future__ import print_function20from __future__ import print_function
2121
22try:22try:
23 from urllib.request import urlopen, URLError23 from urllib.request import urlopen
24 from urllib.parse import urljoin24 from urllib.parse import urljoin
25except ImportError:25except ImportError:
26 from urllib2 import urlopen, URLError26 from urllib2 import urlopen
27 from urlparse import urljoin27 from urlparse import urljoin
2828
29import argparse29import argparse
@@ -36,13 +36,17 @@
3636
37from dirspec.utils import get_program_path37from dirspec.utils import get_program_path
3838
39from ubuntuone.controlpanel.logger import setup_logging
40
41
42logger = setup_logging("updater")
3943
40U1SDTOOL_EXECUTABLE = 'u1sdtool'44U1SDTOOL_EXECUTABLE = 'u1sdtool'
41DARWIN_APP_NAMES = {U1SDTOOL_EXECUTABLE: 'U1SDTool.app'}45DARWIN_APP_NAMES = {U1SDTOOL_EXECUTABLE: 'U1SDTool.app'}
4246
4347
44if sys.platform == "darwin":48if sys.platform == "darwin":
45 from Cocoa import NSRunningApplication, NSLog49 from Cocoa import NSRunningApplication
46 # IDs to terminate: Leave syncdaemon off this list, it is50 # IDs to terminate: Leave syncdaemon off this list, it is
47 # terminated separately.51 # terminated separately.
48 BUNDLE_IDS = ["com.ubuntu.sso.login-qt",52 BUNDLE_IDS = ["com.ubuntu.sso.login-qt",
@@ -58,8 +62,9 @@
58def _do_download(url):62def _do_download(url):
59 """Download a URL and return the data it contains."""63 """Download a URL and return the data it contains."""
60 resource = urlopen(url)64 resource = urlopen(url)
61 if resource:65 logger.info("Downloading {}".format(url))
62 data = resource.read()66 data = resource.read()
67 logger.info("Downloaded {}".format(url))
63 return data68 return data
6469
6570
@@ -72,7 +77,10 @@
7277
73 md5 = hashlib.md5()78 md5 = hashlib.md5()
74 md5.update(data)79 md5.update(data)
75 if checksum != md5.hexdigest():80 digest = md5.hexdigest()
81 if checksum != digest:
82 logger.error("Checksum mismatch. Expected {}, computed {}".format(
83 checksum, digest))
76 raise Exception("Checksum mismatch")84 raise Exception("Checksum mismatch")
7785
78 fd, name = tempfile.mkstemp()86 fd, name = tempfile.mkstemp()
@@ -89,7 +97,7 @@
89 args.insert(0, 'open')97 args.insert(0, 'open')
90 subprocess.Popen(args)98 subprocess.Popen(args)
91 except Exception as exc:99 except Exception as exc:
92 print("Unable to install {}: {}".format(url, exc))100 logger.error("Unable to install {}: {}".format(url, exc))
93 return False101 return False
94 return True102 return True
95103
@@ -100,8 +108,8 @@
100108
101 try:109 try:
102 data = _do_download(args.url)110 data = _do_download(args.url)
103 except URLError as err:111 except Exception as exc:
104 print("Download failed: {}".format(err))112 logger.error("Download failed: {}".format(exc))
105 return error113 return error
106114
107 try:115 try:
@@ -110,21 +118,20 @@
110 avail_ver = available["version"]118 avail_ver = available["version"]
111 upgrade_available = avail_ver > args.current119 upgrade_available = avail_ver > args.current
112 if upgrade_available:120 if upgrade_available:
113 msg = "A new {} version is available at {}."121 logger.info("A new {} version is available at {}.".format(
114 print(msg.format(args.release, available["url"]))122 args.release, available["url"]))
115 elif avail_ver == args.current:123 elif avail_ver == args.current:
116 print("Version {} is the latest {}.".format(args.current,124 logger.info("Version {} is the latest {}.".format(args.current,
117 args.release))125 args.release))
118 else:126 else:
119 print("Warning: installed version {} newer than advertised"127 logger.info("Installed version {} newer than advertised"
120 " available version {} somehow.".format(args.current,128 " available version {}.".format(args.current, avail_ver))
121 avail_ver))
122129
123 except Exception as exc:130 except Exception as exc:
124 # Catch everything here.131 # Catch everything here.
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.
126 print("Exception while reading {}:".format(args.url),133 logger.error("Exception while reading {}: {}, {}".format(
127 exc.__class__, exc.message)134 args.url, exc.__class__, exc.message))
128 return error135 return error
129136
130 return upgrade_available, available["url"], available["checksum"]137 return upgrade_available, available["url"], available["checksum"]
@@ -134,21 +141,24 @@
134 """Kill any running u1 processes."""141 """Kill any running u1 processes."""
135 if sys.platform != "darwin":142 if sys.platform != "darwin":
136 return143 return
137 NSLog("in kill")144 logger.info("Killing running processes")
138145
139 try:146 try:
140 u1sdtoolpath = get_program_path(U1SDTOOL_EXECUTABLE,147 u1sdtoolpath = get_program_path(U1SDTOOL_EXECUTABLE,
141 app_names=DARWIN_APP_NAMES)148 app_names=DARWIN_APP_NAMES)
142
143 out = subprocess.check_output([u1sdtoolpath, '-q'])
144 NSLog("u1sdtool said: {}".format(out))
145 except Exception as e:149 except Exception as e:
146 NSLog("exception running {} -q: {}".format(u1sdtoolpath, e))150 logger.error("exception getting u1sdtool's path: {}".format(e))
151 else:
152 try:
153 out = subprocess.check_output([u1sdtoolpath, '-q'])
154 logger.info("u1sdtool said: {}".format(out))
155 except Exception as e:
156 logger.error("exception running {} -q: {}".format(u1sdtoolpath, e))
147157
148 for id in BUNDLE_IDS:158 for id in BUNDLE_IDS:
149 NSRA = NSRunningApplication159 NSRA = NSRunningApplication
150 apps = NSRA.runningApplicationsWithBundleIdentifier_(id)160 apps = NSRA.runningApplicationsWithBundleIdentifier_(id)
151 NSLog("id: {} apps: {}".format(id, apps))161 logger.info("id: {} apps: {}".format(id, apps))
152162
153 for app in apps:163 for app in apps:
154 app.terminate()164 app.terminate()
@@ -175,7 +185,7 @@
175185
176 if args.install and new_available:186 if args.install and new_available:
177 installer = urljoin(args.url, file)187 installer = urljoin(args.url, file)
178 print("Downloading and installing", installer)188 logger.info("Downloading and installing {}".format(installer))
179 kill_running_processes()189 kill_running_processes()
180 return 1 if run_install(installer, checksum) else 0190 return 1 if run_install(installer, checksum) else 0
181191
182192
=== modified file 'ubuntuone/controlpanel/tests/test_web_client.py'
--- ubuntuone/controlpanel/tests/test_web_client.py 2012-10-26 15:55:18 +0000
+++ ubuntuone/controlpanel/tests/test_web_client.py 2013-01-28 18:15:26 +0000
@@ -19,7 +19,7 @@
19from urlparse import urlparse, parse_qs19from urlparse import urlparse, parse_qs
2020
21from twisted.internet import defer21from twisted.internet import defer
22from twisted.web import resource22from twisted.web import http, resource
2323
24from ubuntuone.devtools.testing.txwebserver import HTTPWebServer24from ubuntuone.devtools.testing.txwebserver import HTTPWebServer
2525
@@ -83,7 +83,7 @@
83 devices_resource.contents = SAMPLE_RESOURCE83 devices_resource.contents = SAMPLE_RESOURCE
84 root.putChild("devices", devices_resource)84 root.putChild("devices", devices_resource)
85 root.putChild("throwerror", resource.NoResource())85 root.putChild("throwerror", resource.NoResource())
86 unauthorized = resource.ErrorPage(resource.http.UNAUTHORIZED,86 unauthorized = resource.ErrorPage(http.UNAUTHORIZED,
87 "Unauthrorized", "Unauthrorized")87 "Unauthrorized", "Unauthrorized")
88 root.putChild("unauthorized", unauthorized)88 root.putChild("unauthorized", unauthorized)
89 super(MockWebServer, self).__init__(root)89 super(MockWebServer, self).__init__(root)

Subscribers

People subscribed via source and target branches