Merge lp:~nataliabidart/ubuntuone-client/platform-details into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1113
Merged at revision: 1108
Proposed branch: lp:~nataliabidart/ubuntuone-client/platform-details
Merge into: lp:ubuntuone-client
Diff against target: 506 lines (+125/-57)
14 files modified
bin/ubuntuone-login (+4/-2)
po/POTFILES.in (+1/-1)
tests/platform/linux/test_credentials.py (+8/-4)
tests/platform/test_credentials.py (+33/-1)
tests/platform/windows/test_credentials.py (+8/-7)
ubuntuone/logger.py (+27/-0)
ubuntuone/platform/__init__.py (+2/-0)
ubuntuone/platform/credentials/__init__.py (+32/-9)
ubuntuone/platform/credentials/linux.py (+6/-15)
ubuntuone/platform/credentials/windows.py (+2/-14)
ubuntuone/platform/linux/__init__.py (+0/-1)
ubuntuone/platform/linux/dbus_interface.py (+1/-1)
ubuntuone/platform/windows/__init__.py (+0/-1)
ubuntuone/platform/windows/ipc.py (+1/-1)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/platform-details
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+71723@code.launchpad.net

Commit message

- Platform details are now sent in the PING_URL (LP: #827343).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

looks nice!

review: Approve
1110. By Natalia Bidart

* Using urlencode to encode ping url platform params.
* Added the logging of the result when using the log_call decorator.

1111. By Natalia Bidart

Merged trunk in.

Revision history for this message
John Lenton (chipaca) wrote :

even without the fix to the test, this is +1.

review: Approve
1112. By Natalia Bidart

Removed randomness to test_ping_url to ensure platform data is correct.

1113. By Natalia Bidart

Removing unused import, and debug print.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntuone-login'
2--- bin/ubuntuone-login 2011-07-28 21:28:35 +0000
3+++ bin/ubuntuone-login 2011-08-17 13:31:24 +0000
4@@ -32,9 +32,10 @@
5
6 from ubuntuone.logger import basic_formatter
7 from ubuntuone.platform.credentials import logger
8-from ubuntuone.platform.linux.credentials import (
9+from ubuntuone.platform.credentials.linux import (
10 DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,
11- CredentialsManagement)
12+ CredentialsManagement,
13+)
14
15 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
16
17@@ -52,6 +53,7 @@
18 debug_handler = logging.StreamHandler(sys.stderr)
19 debug_handler.setFormatter(basic_formatter)
20 debug_handler.setLevel(logging.DEBUG)
21+ logger.setLevel(logging.DEBUG)
22 logger.addHandler(debug_handler)
23
24 logger.info("Starting Ubuntu One login manager for bus %r.", DBUS_BUS_NAME)
25
26=== modified file 'po/POTFILES.in'
27--- po/POTFILES.in 2011-07-21 15:24:02 +0000
28+++ po/POTFILES.in 2011-08-17 13:31:24 +0000
29@@ -1,6 +1,6 @@
30 ubuntuone/clientdefs.py.in
31 ubuntuone/status/aggregator.py
32-ubuntuone/credentials.py
33+ubuntuone/platform/credentials/__init__.py
34 data/emblem-ubuntuone-downloading.icon.in
35 data/emblem-ubuntuone-unsynchronized.icon.in
36 data/emblem-ubuntuone-uploading.icon.in
37
38=== modified file 'tests/platform/linux/test_credentials.py'
39--- tests/platform/linux/test_credentials.py 2011-07-27 17:31:25 +0000
40+++ tests/platform/linux/test_credentials.py 2011-08-17 13:31:24 +0000
41@@ -18,18 +18,22 @@
42
43 """Tests for the Ubuntu One credentials management dbus service."""
44
45+import logging
46+
47 from functools import wraps
48
49 from twisted.internet.defer import Deferred, inlineCallbacks
50 from ubuntuone.devtools.testcase import DBusTestCase
51 from ubuntuone.devtools.handlers import MementoHandler
52
53-from ubuntuone.credentials import logging, logger
54-from ubuntuone.platform.linux.credentials import (
55+from ubuntuone.platform.credentials import (
56+ CredentialsError,
57+ CredentialsManagementTool,
58+ logger,
59+)
60+from ubuntuone.platform.credentials.linux import (
61 APP_NAME,
62- CredentialsError,
63 CredentialsManagement,
64- CredentialsManagementTool,
65 dbus,
66 DBUS_BUS_NAME,
67 DBUS_CREDENTIALS_IFACE,
68
69=== renamed file 'tests/test_credentials.py' => 'tests/platform/test_credentials.py'
70--- tests/test_credentials.py 2011-07-29 16:03:27 +0000
71+++ tests/platform/test_credentials.py 2011-08-17 13:31:24 +0000
72@@ -18,10 +18,20 @@
73 # with this program. If not, see <http://www.gnu.org/licenses/>.
74 """Platform independent tests for the credentials management."""
75
76+import platform
77+import urlparse
78+
79 from mocker import MockerTestCase, MATCH
80 from twisted.internet import defer
81+from twisted.trial.unittest import TestCase
82
83-from ubuntuone.platform.credentials import CredentialsManagementTool
84+from ubuntuone import clientdefs
85+from ubuntuone.platform.credentials import (
86+ BASE_PING_URL,
87+ CredentialsManagementTool,
88+ PING_URL,
89+ PLATFORM_DATA,
90+)
91
92
93 class TestCredentialsManagementTool(MockerTestCase):
94@@ -132,3 +142,25 @@
95 self.get_cred_proxy = lambda: defer.succeed(real_get_cred_proxy())
96 self.management_tool = CredentialsManagementTool()
97 self.management_tool.get_creds_proxy = self.get_cred_proxy
98+
99+
100+class PingURLPlatformDetails(TestCase):
101+
102+ def test_ping_url(self):
103+ """The PING_URL is BASE_PING_URL followed by encoded PLATFORM_DATA."""
104+ result = urlparse.urlparse(PING_URL)
105+
106+ expected_base = urlparse.urljoin(result.scheme + '://' + result.netloc,
107+ result.path)
108+ self.assertEqual(expected_base, BASE_PING_URL)
109+
110+ expected_query = dict(urlparse.parse_qsl(result.query))
111+ self.assertEqual(expected_query, PLATFORM_DATA)
112+
113+ def test_platform_data(self):
114+ """The platform data is correct."""
115+ expected = {"platform": platform.system(),
116+ "platform_version": platform.release(),
117+ "platform_arch": platform.machine(),
118+ "client_version": clientdefs.VERSION}
119+ self.assertEqual(expected, PLATFORM_DATA)
120
121=== modified file 'tests/platform/windows/test_credentials.py'
122--- tests/platform/windows/test_credentials.py 2011-07-19 00:06:04 +0000
123+++ tests/platform/windows/test_credentials.py 2011-08-17 13:31:24 +0000
124@@ -20,7 +20,10 @@
125 from twisted.internet import defer
126 from twisted.trial.unittest import TestCase
127
128-from ubuntuone.platform.windows import credentials
129+from ubuntuone.platform.credentials.windows import (
130+ CredentialsManagement,
131+ RemovableSignal,
132+)
133
134 TEST_APP_NAME = "test application"
135 TEST_ERROR_DICT = {}
136@@ -93,8 +96,7 @@
137 """__call__ works as expected."""
138 sample_store = []
139 test_cb = lambda app_name, creds: sample_store.append(creds)
140- rs = credentials.RemovableSignal(self.proxy, "on_credentials_found_cb",
141- test_cb)
142+ rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
143 rs(TEST_APP_NAME, TEST_CREDENTIALS)
144 self.assertEqual(sample_store[0], TEST_CREDENTIALS)
145
146@@ -102,8 +104,7 @@
147 """The signal has a .remove that removes the callback."""
148 sample_store = []
149 test_cb = lambda app_name, creds: sample_store.append(creds)
150- rs = credentials.RemovableSignal(self.proxy, "on_credentials_found_cb",
151- test_cb)
152+ rs = RemovableSignal(self.proxy, "on_credentials_found_cb", test_cb)
153 rs.remove()
154 rs(TEST_APP_NAME, TEST_CREDENTIALS)
155 self.assertEqual(len(sample_store), 0)
156@@ -117,7 +118,7 @@
157 def setUp(self):
158 """Initialize these tests."""
159 self.proxy = FakeSSOProxy()
160- self.cm = credentials.CredentialsManagement(self.proxy)
161+ self.cm = CredentialsManagement(self.proxy)
162
163 def test_find_credentials(self):
164 """Test the find_credentials method."""
165@@ -177,7 +178,7 @@
166 d = defer.Deferred()
167
168 def signal_handler(*args):
169- """Fake the behaviour of CredentialsManagementToolRoot."""
170+ """Fake the behaviour of CredentialsManagementTool."""
171 d.callback(args[0] if len(args) > 0 else None)
172
173 register = getattr(self.cm, "register_to_" + signal_name)
174
175=== modified file 'ubuntuone/logger.py'
176--- ubuntuone/logger.py 2011-07-26 16:07:08 +0000
177+++ ubuntuone/logger.py 2011-08-17 13:31:24 +0000
178@@ -240,6 +240,33 @@
179 return True
180
181
182+def log_call(log_func):
183+ """Decorator to add a log entry using 'log_func'.
184+
185+ An example of use would be:
186+
187+ @log_call(logger.debug)
188+ def f(a, b, c):
189+ ....
190+
191+ """
192+
193+ def middle(f):
194+ """Add logging when calling 'f'."""
195+
196+ @functools.wraps(f)
197+ def inner(*args, **kwargs):
198+ """Call f(*args, **kwargs)."""
199+ log_func('%s: args %r, kwargs %r.', f.__name__, args, kwargs)
200+ res = f(*args, **kwargs)
201+ log_func('%s: result %r.', f.__name__, res)
202+ return res
203+
204+ return inner
205+
206+ return middle
207+
208+
209 ### configure the thing ###
210 LOGBACKUP = 5 # the number of log files to keep around
211
212
213=== modified file 'ubuntuone/platform/__init__.py'
214--- ubuntuone/platform/__init__.py 2011-08-02 17:26:22 +0000
215+++ ubuntuone/platform/__init__.py 2011-08-17 13:31:24 +0000
216@@ -10,6 +10,8 @@
217 from ubuntuone.platform import linux
218 source = linux
219
220+from ubuntuone.platform import credentials
221+
222 target = sys.modules[__name__]
223 for k in dir(source):
224 setattr(target, k, getattr(source, k))
225
226=== added directory 'ubuntuone/platform/credentials'
227=== renamed file 'ubuntuone/credentials.py' => 'ubuntuone/platform/credentials/__init__.py'
228--- ubuntuone/credentials.py 2011-07-29 16:15:53 +0000
229+++ ubuntuone/platform/credentials/__init__.py 2011-08-17 13:31:24 +0000
230@@ -18,16 +18,20 @@
231 # with this program. If not, see <http://www.gnu.org/licenses/>.
232 """Common code for the credentials management."""
233
234+import gettext
235 import logging
236 import os
237-import gettext
238+import platform
239+import urllib
240+import sys
241
242 from twisted.internet import defer
243
244-from ubuntuone.clientdefs import GETTEXT_PACKAGE
245+from ubuntuone import clientdefs
246 from ubuntuone.logger import (
247 basic_formatter,
248 CustomRotatingFileHandler,
249+ log_call,
250 )
251 from ubuntuone.platform.xdg_base_directory import ubuntuone_log_dir
252
253@@ -42,29 +46,35 @@
254 logger.addHandler(MAIN_HANDLER)
255
256 NO_OP = lambda *args, **kwargs: None
257-Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string)
258+Q_ = lambda string: gettext.dgettext(clientdefs.GETTEXT_PACKAGE, string)
259 APP_NAME = "Ubuntu One"
260 TC_URL = "https://one.ubuntu.com/terms/"
261-PING_URL = "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"
262+BASE_PING_URL = \
263+ "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/{email}"
264+PLATFORM_DATA = {'platform': platform.system(),
265+ 'platform_version': platform.release(),
266+ 'platform_arch': platform.machine(),
267+ 'client_version': clientdefs.VERSION}
268+PING_URL = BASE_PING_URL + "?" + urllib.urlencode(PLATFORM_DATA)
269 DESCRIPTION = Q_('Ubuntu One requires an Ubuntu Single Sign On (SSO) account. '
270 'This process will allow you to create a new account, '
271 'if you do not yet have one.')
272
273+
274 class CredentialsError(Exception):
275 """A general exception when hadling credentilas."""
276
277
278-class CredentialsManagementToolRoot(object):
279+class CredentialsManagementTool(object):
280 """Wrapper to CredentialsManagement.
281
282- The goal of this class is to abstract the caller from calling the DBus
283+ The goal of this class is to abstract the caller from calling the IPC
284 service implemented in the class CredentialsManagement.
285
286 """
287
288- def __init__(self, get_proxy_fn):
289+ def __init__(self):
290 self._cleanup_signals = []
291- self.get_proxy_fn = get_proxy_fn
292
293 def cleanup(self, _):
294 """Disconnect all the DBus signals."""
295@@ -77,8 +87,16 @@
296
297 def get_creds_proxy(self):
298 """Call the get_proxy_fn, and perhaps wrap the result in a defer."""
299- return defer.maybeDeferred(self.get_proxy_fn)
300+ if sys.platform == 'win32':
301+ from ubuntuone.platform.credentials import windows
302+ source = windows
303+ else:
304+ from ubuntuone.platform.credentials import linux
305+ source = linux
306+ result = defer.maybeDeferred(source.get_creds_proxy)
307+ return result
308
309+ @log_call(logger.debug)
310 @defer.inlineCallbacks
311 def find_credentials(self):
312 """Find credentials for Ubuntu One.
313@@ -121,6 +139,7 @@
314 result = yield d
315 defer.returnValue(result)
316
317+ @log_call(logger.debug)
318 @defer.inlineCallbacks
319 def clear_credentials(self):
320 """Clear credentials for Ubuntu One.
321@@ -149,6 +168,7 @@
322
323 yield d
324
325+ @log_call(logger.debug)
326 @defer.inlineCallbacks
327 def store_credentials(self, token):
328 """Store credentials for Ubuntu One.
329@@ -181,6 +201,7 @@
330
331 yield d
332
333+ @log_call(logger.debug)
334 @defer.inlineCallbacks
335 def register(self, window_id=0):
336 """Register to Ubuntu One.
337@@ -226,6 +247,7 @@
338 result = yield d
339 defer.returnValue(result)
340
341+ @log_call(logger.debug)
342 @defer.inlineCallbacks
343 def login(self, window_id=0):
344 """Login to Ubuntu One.
345@@ -272,6 +294,7 @@
346 result = yield d
347 defer.returnValue(result)
348
349+ @log_call(logger.debug)
350 @defer.inlineCallbacks
351 def login_email_password(self, email, password):
352 """Login to Ubuntu One.
353
354=== renamed file 'ubuntuone/platform/linux/credentials.py' => 'ubuntuone/platform/credentials/linux.py'
355--- ubuntuone/platform/linux/credentials.py 2011-07-29 15:36:12 +0000
356+++ ubuntuone/platform/credentials/linux.py 2011-08-17 13:31:24 +0000
357@@ -17,7 +17,6 @@
358 # with this program. If not, see <http://www.gnu.org/licenses/>.
359 """Ubuntu One credentials management dbus service."""
360
361-
362 import dbus.service
363 import ubuntu_sso
364
365@@ -26,16 +25,14 @@
366 PING_URL_KEY,
367 TC_URL_KEY,
368 )
369-from ubuntuone.credentials import (
370- CredentialsManagementToolRoot,
371- logger,
372+from ubuntuone.platform.credentials import (
373 APP_NAME,
374 DESCRIPTION,
375+ logger,
376 NO_OP,
377 PING_URL,
378 TC_URL,
379 )
380-from ubuntuone.credentials import CredentialsError as CredentialsErrorRoot
381
382
383 TIMEOUT_INTERVAL = 10000 # 10 seconds
384@@ -45,8 +42,6 @@
385 DBUS_CREDENTIALS_PATH = "/credentials"
386 DBUS_CREDENTIALS_IFACE = "com.ubuntuone.CredentialsManagement"
387
388-CredentialsError = CredentialsErrorRoot
389-
390
391 class CredentialsManagement(dbus.service.Object):
392 """DBus object that manages Ubuntu One credentials."""
393@@ -242,7 +237,7 @@
394 """Proxy that allows to work with the dbus api.
395
396 This proxy has been added to hide the exact details of
397- how the signals are connected. This allows the reuse of
398+ how the signals are connected. This allows the reuse of
399 the CredentialsManagementTool in diff platforms.
400 """
401
402@@ -307,10 +302,6 @@
403 return self.proxy.connect_to_signal('CredentialsError', callback)
404
405
406-class CredentialsManagementTool(CredentialsManagementToolRoot):
407- """Wrapper used to manage the creds of ubuntu one."""
408-
409- def __init__(self):
410- """Create a new instance."""
411- super(CredentialsManagementTool, self).__init__(
412- CredentialsManagementProxy)
413+def get_creds_proxy():
414+ """Get the CredentialsManagement proxy."""
415+ return CredentialsManagementProxy()
416
417=== renamed file 'ubuntuone/platform/windows/credentials.py' => 'ubuntuone/platform/credentials/windows.py'
418--- ubuntuone/platform/windows/credentials.py 2011-07-29 18:12:27 +0000
419+++ ubuntuone/platform/credentials/windows.py 2011-08-17 13:31:24 +0000
420@@ -27,17 +27,13 @@
421 PING_URL_KEY,
422 TC_URL_KEY,
423 )
424-from ubuntuone.credentials import (
425- CredentialsManagementToolRoot,
426+from ubuntuone.platform.credentials import (
427 APP_NAME,
428 DESCRIPTION,
429 NO_OP,
430 PING_URL,
431 TC_URL,
432 )
433-from ubuntuone.credentials import CredentialsError as CredentialsErrorRoot
434-
435-CredentialsError = CredentialsErrorRoot
436
437
438 class RemovableSignal(object):
439@@ -144,16 +140,8 @@
440
441 @defer.inlineCallbacks
442 def get_creds_proxy():
443- """Get the CredentialsManagement dbus proxy."""
444+ """Get the CredentialsManagement proxy."""
445 client = UbuntuSSOClient()
446 client = yield client.connect()
447 yield client.cred_management.register_to_signals()
448 defer.returnValue(CredentialsManagement(client.cred_management))
449-
450-
451-class CredentialsManagementTool(CredentialsManagementToolRoot):
452- """Wrapper used to manage the creds of ubuntu one."""
453-
454- def __init__(self):
455- """Create a new instance."""
456- super(CredentialsManagementTool, self).__init__(get_creds_proxy)
457
458=== modified file 'ubuntuone/platform/linux/__init__.py'
459--- ubuntuone/platform/linux/__init__.py 2011-08-11 16:07:23 +0000
460+++ ubuntuone/platform/linux/__init__.py 2011-08-17 13:31:24 +0000
461@@ -56,7 +56,6 @@
462 stat_path,
463 walk,
464 )
465-from ubuntuone.platform.linux.credentials import CredentialsManagementTool
466 from ubuntuone.platform.linux.logger import setup_filesystem_logging, get_filesystem_logger
467 from ubuntuone.platform.linux.filesystem_notifications import FilesystemMonitor
468 from ubuntuone.platform.linux.notification import Notification
469
470=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
471--- ubuntuone/platform/linux/dbus_interface.py 2011-07-21 20:39:54 +0000
472+++ ubuntuone/platform/linux/dbus_interface.py 2011-08-17 13:31:24 +0000
473@@ -28,7 +28,7 @@
474 from twisted.internet import defer
475 from twisted.python.failure import Failure
476 from ubuntuone.syncdaemon.interfaces import IMarker
477-from ubuntuone.platform.linux.credentials import (
478+from ubuntuone.platform.credentials.linux import (
479 DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,
480 DBUS_CREDENTIALS_IFACE)
481 from ubuntuone.platform.linux.launcher import UbuntuOneLauncher
482
483=== modified file 'ubuntuone/platform/windows/__init__.py'
484--- ubuntuone/platform/windows/__init__.py 2011-08-11 16:07:23 +0000
485+++ ubuntuone/platform/windows/__init__.py 2011-08-17 13:31:24 +0000
486@@ -55,7 +55,6 @@
487 stat_path,
488 walk,
489 )
490-from ubuntuone.platform.windows.credentials import CredentialsManagementTool
491 from ubuntuone.platform.windows import event_logging
492 from ubuntuone.platform.windows.logger import (
493 setup_filesystem_logging,
494
495=== modified file 'ubuntuone/platform/windows/ipc.py'
496--- ubuntuone/platform/windows/ipc.py 2011-08-08 13:20:23 +0000
497+++ ubuntuone/platform/windows/ipc.py 2011-08-17 13:31:24 +0000
498@@ -38,7 +38,7 @@
499 AlreadyStartedError,
500 )
501 from ubuntuone.syncdaemon.interfaces import IMarker
502-from ubuntuone.platform.windows import CredentialsManagementTool
503+from ubuntuone.platform.credentials import CredentialsManagementTool
504 from ubuntuone.platform.windows.network_manager import NetworkManager
505 from ubuntuone.syncdaemon.interaction_interfaces import (
506 bool_str,

Subscribers

People subscribed via source and target branches