Merge lp:~nataliabidart/ubuntuone-control-panel/improve-volume-retrieval into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 50
Merged at revision: 49
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/improve-volume-retrieval
Merge into: lp:ubuntuone-control-panel
Diff against target: 308 lines (+134/-46)
7 files modified
ubuntuone/controlpanel/backend.py (+10/-1)
ubuntuone/controlpanel/dbus_client.py (+8/-0)
ubuntuone/controlpanel/dbus_service.py (+15/-1)
ubuntuone/controlpanel/integrationtests/test_dbus_client_sd.py (+28/-0)
ubuntuone/controlpanel/integrationtests/test_dbus_service.py (+4/-20)
ubuntuone/controlpanel/tests/__init__.py (+49/-23)
ubuntuone/controlpanel/tests/test_backend.py (+20/-1)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/improve-volume-retrieval
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+46916@code.launchpad.net

Commit message

- Backend provides a richer list of volumes, including the root info (LP: #705444).

Description of the change

The backend provides a richer volumes list info as per the new doc:

volumes_info
This is called by the gui to find out the volumes info for the current logged in user. The signals returned are:

       * VolumesInfoReady with a list of volume information. Each volume is represented by a tuple with 3 fields: the volume owner (empty string for current user), the amount of free bytes in the volume, and a list of "volumes_dict". Each "volumes_dict" has (at least) the following values (depending on the type, there might be extra parameters):
          o "volume_id" (unicode representation of an uuid)
          o “path” (unicode)
          o "suggested_path" (unicode)
          o "subscribed" (boolean, same convention as before)
          o "type" (unicode, either ROOT, UDF or SHARE)
    * VolumesInfoError with the error

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

+1 but I only looked at the code.

Revision history for this message
Roberto Alsina (ralsina) wrote :

And I forgot to approve in the previous comment ;-)

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Code looks good, all tests pass.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntuone/controlpanel/backend.py'
--- ubuntuone/controlpanel/backend.py 2011-01-18 21:24:31 +0000
+++ ubuntuone/controlpanel/backend.py 2011-01-20 17:38:08 +0000
@@ -327,7 +327,16 @@
327 @inlineCallbacks327 @inlineCallbacks
328 def volumes_info(self):328 def volumes_info(self):
329 """Get the volumes info."""329 """Get the volumes info."""
330 result = yield dbus_client.get_folders()330 account = yield self.account_info()
331 root_dir = yield dbus_client.get_root_dir()
332 folders = yield dbus_client.get_folders()
333
334 free_bytes = int(account['quota_total']) - int(account['quota_used'])
335 root_volume = {u'volume_id': u'', u'path': root_dir,
336 u'subscribed': 'True', u'type': u'ROOT'}
337
338 result = [(u'', unicode(free_bytes), [root_volume] + folders)]
339
331 # later, we may request shares info as well340 # later, we may request shares info as well
332 returnValue(result)341 returnValue(result)
333342
334343
=== modified file 'ubuntuone/controlpanel/dbus_client.py'
--- ubuntuone/controlpanel/dbus_client.py 2011-01-18 13:42:12 +0000
+++ ubuntuone/controlpanel/dbus_client.py 2011-01-20 17:38:08 +0000
@@ -213,6 +213,14 @@
213 return d213 return d
214214
215215
216def get_root_dir():
217 """Retrieve the root information from syncdaemon."""
218 d = defer.Deferred()
219 proxy = get_syncdaemon_proxy("/", sd_dbus_iface.DBUS_IFACE_SYNC_NAME)
220 proxy.get_rootdir(reply_handler=d.callback, error_handler=d.errback)
221 return d
222
223
216def get_folders():224def get_folders():
217 """Retrieve the folders information from syncdaemon."""225 """Retrieve the folders information from syncdaemon."""
218 d = defer.Deferred()226 d = defer.Deferred()
219227
=== modified file 'ubuntuone/controlpanel/dbus_service.py'
--- ubuntuone/controlpanel/dbus_service.py 2011-01-18 20:35:47 +0000
+++ ubuntuone/controlpanel/dbus_service.py 2011-01-20 17:38:08 +0000
@@ -19,6 +19,8 @@
1919
20"""Export the control backend thru DBus."""20"""Export the control backend thru DBus."""
2121
22from functools import wraps
23
22import dbus.service24import dbus.service
23import gobject25import gobject
2426
@@ -93,6 +95,18 @@
93 return inner95 return inner
9496
9597
98def debug(f):
99 """Debug the call to 'f'."""
100
101 @wraps(f)
102 def inner(self, *args, **kwargs):
103 """Fake the call to 'f'."""
104 print '\n===', self, f, args, kwargs
105 return f(self, *args, **kwargs)
106
107 return inner
108
109
96class ControlPanelBackend(dbus.service.Object):110class ControlPanelBackend(dbus.service.Object):
97 """Export the Control Panel backend thru DBus."""111 """Export the Control Panel backend thru DBus."""
98112
@@ -413,7 +427,7 @@
413 d.addErrback(transform_failure(self.VolumesInfoError))427 d.addErrback(transform_failure(self.VolumesInfoError))
414428
415 @log_call(logger.debug)429 @log_call(logger.debug)
416 @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="aa{ss}")430 @signal(dbus_interface=DBUS_PREFERENCES_IFACE, signature="a(ssaa{ss})")
417 def VolumesInfoReady(self, info):431 def VolumesInfoReady(self, info):
418 """The info for the volumes is available right now."""432 """The info for the volumes is available right now."""
419433
420434
=== modified file 'ubuntuone/controlpanel/integrationtests/test_dbus_client_sd.py'
--- ubuntuone/controlpanel/integrationtests/test_dbus_client_sd.py 2011-01-18 13:42:12 +0000
+++ ubuntuone/controlpanel/integrationtests/test_dbus_client_sd.py 2011-01-20 17:38:08 +0000
@@ -543,3 +543,31 @@
543 yield dbus_client.stop_file_sync()543 yield dbus_client.stop_file_sync()
544544
545 self.assertEqual(self._called, ((), {}))545 self.assertEqual(self._called, ((), {}))
546
547
548class MockDBusSyncDaemon(dbus.service.Object):
549 """A mock object that mimicks syncdaemon."""
550
551 ROOT_DIR = u'/yadda/yoda/Test me'
552
553 @dbus.service.method(sd_dbus_iface.DBUS_IFACE_SYNC_NAME,
554 in_signature='', out_signature='s')
555 def get_rootdir(self):
556 """Return the root dir/mount point."""
557 return self.ROOT_DIR
558
559
560class BasicTestCase(DBusClientTestCase):
561 """Test for the basic dbus client methods."""
562
563 def setUp(self):
564 super(BasicTestCase, self).setUp()
565 self.register_mockserver(sd_dbus_iface.DBUS_IFACE_NAME,
566 "/", MockDBusSyncDaemon)
567
568 @inlineCallbacks
569 def test_get_root_dir(self):
570 """Retrieve current syncdaemon root dir."""
571 root = yield dbus_client.get_root_dir()
572
573 self.assertEqual(MockDBusSyncDaemon.ROOT_DIR, root)
546574
=== modified file 'ubuntuone/controlpanel/integrationtests/test_dbus_service.py'
--- ubuntuone/controlpanel/integrationtests/test_dbus_service.py 2011-01-18 20:35:47 +0000
+++ ubuntuone/controlpanel/integrationtests/test_dbus_service.py 2011-01-20 17:38:08 +0000
@@ -27,7 +27,8 @@
2727
28from ubuntuone.controlpanel import dbus_service28from ubuntuone.controlpanel import dbus_service
29from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH,29from ubuntuone.controlpanel import (DBUS_BUS_NAME, DBUS_PREFERENCES_PATH,
30 DBUS_PREFERENCES_IFACE)30 DBUS_PREFERENCES_IFACE)
31from ubuntuone.controlpanel.tests import SAMPLE_FOLDERS
31from ubuntuone.controlpanel.integrationtests import TestCase32from ubuntuone.controlpanel.integrationtests import TestCase
3233
3334
@@ -64,24 +65,7 @@
64]65]
6566
66SAMPLE_VOLUMES_INFO = [67SAMPLE_VOLUMES_INFO = [
67 {68 (u'', u'1253698', SAMPLE_FOLDERS),
68 "volume_id": "volume-0",
69 "path": "/home/user/Documents",
70 "suggested_path": "~/Documents",
71 "subscribed": 'True',
72 },
73 {
74 "volume_id": "volume-1",
75 "path": "/home/user/Music",
76 "suggested_path": "~/Music",
77 "subscribed": '',
78 },
79 {
80 "volume_id": "volume-2",
81 "path": "/home/user/Pictures/Photos",
82 "suggested_path": "~/Pictures/Photos",
83 "subscribed": '',
84 },
85]69]
8670
87SAMPLE_REPLICATIONS_INFO = [71SAMPLE_REPLICATIONS_INFO = [
@@ -524,7 +508,7 @@
524508
525 def test_change_volume_settings(self):509 def test_change_volume_settings(self):
526 """The volume settings are successfully changed."""510 """The volume settings are successfully changed."""
527 expected_volume_id = SAMPLE_VOLUMES_INFO[0]['volume_id']511 expected_volume_id = SAMPLE_FOLDERS[0]['volume_id']
528512
529 def got_signal(volume_id):513 def got_signal(volume_id):
530 """The correct volume was changed."""514 """The correct volume was changed."""
531515
=== modified file 'ubuntuone/controlpanel/tests/__init__.py'
--- ubuntuone/controlpanel/tests/__init__.py 2011-01-06 20:33:15 +0000
+++ ubuntuone/controlpanel/tests/__init__.py 2011-01-20 17:38:08 +0000
@@ -136,40 +136,66 @@
136]136]
137137
138SAMPLE_FOLDERS = [138SAMPLE_FOLDERS = [
139 {u'generation': u'2', u'node_id': u'341da068-81d8-437a-8f75-5bb9d86455ba',139 {u'generation': u'2',
140 u'path': u'/home/tester/Public', u'subscribed': u'True',140 u'node_id': u'341da068-81d8-437a-8f75-5bb9d86455ba',
141 u'path': u'/home/tester/Public',
142 u'subscribed': u'True',
141 u'suggested_path': u'~/Public',143 u'suggested_path': u'~/Public',
142 u'type': u'UDF', u'volume_id': u'9ea892f8-15fa-4201-bdbf-8de99fa5f588'},144 u'type': u'UDF',
143 {u'generation': u'', u'node_id': u'11fbc86c-0d7a-49f5-ae83-8402caf66c6a',145 u'volume_id': u'9ea892f8-15fa-4201-bdbf-8de99fa5f588'},
144 u'path': u'/home/tester/Documents', u'subscribed': u'',146
147 {u'generation': u'',
148 u'node_id': u'11fbc86c-0d7a-49f5-ae83-8402caf66c6a',
149 u'path': u'/home/tester/Documents',
150 u'subscribed': u'',
145 u'suggested_path': u'~/Documents',151 u'suggested_path': u'~/Documents',
146 u'type': u'UDF', u'volume_id': u'2db262f5-a151-4c19-969c-bb5ced753c61'},152 u'type': u'UDF',
147 {u'generation': u'24', u'node_id': u'9ee0e130-a7c7-4d76-a5e3-5df506221b48',153 u'volume_id': u'2db262f5-a151-4c19-969c-bb5ced753c61'},
148 u'path': u'/home/tester/Pictures/Photos', u'subscribed': u'True',154
155 {u'generation': u'24',
156 u'node_id': u'9ee0e130-a7c7-4d76-a5e3-5df506221b48',
157 u'path': u'/home/tester/Pictures/Photos',
158 u'subscribed': u'True',
149 u'suggested_path': u'~/Pictures/Photos',159 u'suggested_path': u'~/Pictures/Photos',
150 u'type': u'UDF', u'volume_id': u'1deb2874-3d28-46ae-9999-d5f48de9f460'},160 u'type': u'UDF',
161 u'volume_id': u'1deb2874-3d28-46ae-9999-d5f48de9f460'},
151]162]
152163
153SAMPLE_SHARES = [164SAMPLE_SHARES = [
154 {u'accepted': u'True', u'access_level': u'View',165 {u'accepted': u'True',
155 u'free_bytes': u'39892622746', u'generation': u'2704',166 u'access_level': u'View',
156 u'name': u're', u'node_id': u'c483f419-ed28-490a-825d-a8c074e2d795',167 u'free_bytes': u'39892622746',
157 u'other_username': u'otheruser', u'other_visible_name': u'Other User',168 u'generation': u'2704',
169 u'name': u're',
170 u'node_id': u'c483f419-ed28-490a-825d-a8c074e2d795',
171 u'other_username': u'otheruser',
172 u'other_visible_name': u'Other User',
158 u'path': u'/home/tester/.local/share/ubuntuone/shares/re from Other User',173 u'path': u'/home/tester/.local/share/ubuntuone/shares/re from Other User',
159 u'type': u'Share', u'volume_id': u'4a1b263b-a2b3-4f66-9e66-4cd18050810d'},174 u'type': u'Share',
160 {u'accepted': u'True', u'access_level': u'Modify',175 u'volume_id': u'4a1b263b-a2b3-4f66-9e66-4cd18050810d'},
161 u'free_bytes': u'39892622746', u'generation': u'2704',176
162 u'name': u'do', u'node_id': u'84544ea4-aefe-4f91-9bb9-ed7b0a805baf',177 {u'accepted': u'True',
163 u'other_username': u'otheruser', u'other_visible_name': u'Other User',178 u'access_level': u'Modify',
179 u'free_bytes': u'39892622746',
180 u'generation': u'2704',
181 u'name': u'do',
182 u'node_id': u'84544ea4-aefe-4f91-9bb9-ed7b0a805baf',
183 u'other_username': u'otheruser',
184 u'other_visible_name': u'Other User',
164 u'path': u'/home/tester/.local/share/ubuntuone/shares/do from Other User',185 u'path': u'/home/tester/.local/share/ubuntuone/shares/do from Other User',
165 u'type': u'Share', u'volume_id': u'7d130dfe-98b2-4bd5-8708-9eeba9838ac0'},186 u'type': u'Share',
187 u'volume_id': u'7d130dfe-98b2-4bd5-8708-9eeba9838ac0'},
166]188]
167189
168SAMPLE_SHARED = [190SAMPLE_SHARED = [
169 {u'accepted': u'True', u'access_level': u'View',191 {u'accepted': u'True',
170 u'free_bytes': u'', u'generation': u'',192 u'access_level': u'View',
171 u'name': u'bar', u'node_id': u'31e47530-9448-4f03-b4dc-4154fdf35225',193 u'free_bytes': u'',
172 u'other_username': u'otheruser', u'other_visible_name': u'Other User',194 u'generation': u'',
195 u'name': u'bar',
196 u'node_id': u'31e47530-9448-4f03-b4dc-4154fdf35225',
197 u'other_username': u'otheruser',
198 u'other_visible_name': u'Other User',
173 u'path': u'/home/tester/Ubuntu One/bar',199 u'path': u'/home/tester/Ubuntu One/bar',
174 u'type': u'Shared',200 u'type': u'Shared',
175 u'volume_id': u'79584900-517f-4dff-b2f3-20e8c1e79365'},201 u'volume_id': u'79584900-517f-4dff-b2f3-20e8c1e79365'},
176202
=== modified file 'ubuntuone/controlpanel/tests/test_backend.py'
--- ubuntuone/controlpanel/tests/test_backend.py 2011-01-18 21:24:31 +0000
+++ ubuntuone/controlpanel/tests/test_backend.py 2011-01-20 17:38:08 +0000
@@ -87,6 +87,7 @@
87 status_changed_handler = None87 status_changed_handler = None
88 subscribed_folders = []88 subscribed_folders = []
89 actions = []89 actions = []
90 root_dir = u'/home/tester/Something/Pepe Mosquito'
9091
91 def get_credentials(self):92 def get_credentials(self):
92 """Return the mock credentials."""93 """Return the mock credentials."""
@@ -142,6 +143,10 @@
142 """Stop the file_sync service."""143 """Stop the file_sync service."""
143 MockDBusClient.actions.append('stop')144 MockDBusClient.actions.append('stop')
144145
146 def get_root_dir(self):
147 """Grab the root dir."""
148 return self.root_dir
149
145 def get_folders(self):150 def get_folders(self):
146 """Grab list of folders."""151 """Grab list of folders."""
147 return SAMPLE_FOLDERS152 return SAMPLE_FOLDERS
@@ -368,9 +373,23 @@
368 @inlineCallbacks373 @inlineCallbacks
369 def test_volumes_info(self):374 def test_volumes_info(self):
370 """The volumes_info method exercises its callback."""375 """The volumes_info method exercises its callback."""
376 # fake quota info and calculate free bytes
377 # pylint: disable=E1101
378 self.be.wc.results[ACCOUNT_API] = SAMPLE_ACCOUNT_NO_CURRENT_PLAN
379 self.be.wc.results[QUOTA_API] = SAMPLE_QUOTA_JSON
380 result = yield self.be.account_info()
381 free_bytes = int(result['quota_total']) - int(result['quota_used'])
382
383 # get root dir info
384 root_dir = MockDBusClient.root_dir
385 root_volume = {u'volume_id': u'', u'path': root_dir,
386 u'subscribed': 'True', u'type': u'ROOT'}
387
371 result = yield self.be.volumes_info()388 result = yield self.be.volumes_info()
389
390 expected = [('', unicode(free_bytes), [root_volume] + SAMPLE_FOLDERS)]
372 # later, we should unify folders and shares info391 # later, we should unify folders and shares info
373 self.assertEqual(result, SAMPLE_FOLDERS)392 self.assertEqual(result, expected)
374393
375 @inlineCallbacks394 @inlineCallbacks
376 def test_subscribe_volume(self):395 def test_subscribe_volume(self):

Subscribers

People subscribed via source and target branches