Merge lp:~diegosarmentero/ubuntuone-client/ipcmenu into lp:ubuntuone-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 1298
Merged at revision: 1290
Proposed branch: lp:~diegosarmentero/ubuntuone-client/ipcmenu
Merge into: lp:ubuntuone-client
Prerequisite: lp:~diegosarmentero/ubuntuone-client/menu
Diff against target: 346 lines (+126/-11)
12 files modified
contrib/testing/testcase.py (+6/-0)
tests/platform/ipc/test_external_interface.py (+14/-0)
tests/platform/test_tools.py (+10/-0)
tests/status/test_aggregator.py (+16/-7)
ubuntuone/platform/ipc/ipc_client.py (+16/-0)
ubuntuone/platform/ipc/linux.py (+33/-0)
ubuntuone/platform/ipc/perspective_broker.py (+5/-0)
ubuntuone/platform/tools/__init__.py (+7/-0)
ubuntuone/status/aggregator.py (+1/-1)
ubuntuone/syncdaemon/__init__.py (+5/-0)
ubuntuone/syncdaemon/interaction_interfaces.py (+4/-0)
ubuntuone/syncdaemon/status_listener.py (+9/-3)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-client/ipcmenu
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Brian Curtin (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+118621@code.launchpad.net

Commit message

- Adding ipc support to share the menu data (LP: #1032659).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
Revision history for this message
Brian Curtin (brian.curtin) :
review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Please make constants out of the keys for the data dict ('recent-transfers' and 'uploading'), so that the strings are only defined once and use those constants through the branch. This makes it faster to catch mistakes.

Please provide detailed information on the keys, and very detailed info too on the dbus types of each of the possible values, of the dbus dictionary of variants returned by the method exposed on dbus. This should be done as a multiline docstring of the exported method.

review: Needs Fixing
1296. By Diego Sarmentero

Adding more complete doctrings and making some strings constants.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> Please make constants out of the keys for the data dict ('recent-transfers'
> and 'uploading'), so that the strings are only defined once and use those
> constants through the branch. This makes it faster to catch mistakes.
>
> Please provide detailed information on the keys, and very detailed info too on
> the dbus types of each of the possible values, of the dbus dictionary of
> variants returned by the method exposed on dbus. This should be done as a
> multiline docstring of the exported method.

Fixed!

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

19 + return {RECENT_TRANSFERS: (), UPLOADING: ()}

123 + {UPLOADING: expected, RECENT_TRANSFERS: ()})

133 + {UPLOADING: expected, RECENT_TRANSFERS: ()})

All of this should be empty lists, not tuples.
Both in Python and DBus, lists are used to signify collections of homogeneous items, while tuples or dbus.Structs are used for collections of heterogeneous items, so it makes better sense to use lists there.

---

162 +
163 + This method return the following structure:
164 + {
165 + 'recent-transfers': (str),
166 + 'uploading': (str, int, int)
167 + }

This notation does not imply that each of those are lists, and also the doc is not explicit about the contents of each field. Please replace with something like this:

"""
This method returns a dictionary, with the following keys and values:

Key: 'recent-transfers'
Value: a list of strings, each being the name of a file that was recently transferred.

Key: 'uploading'
Value: a list of tuples, with each tuple having the following items:
 * str: the name of a file that's currently being uploaded
 * int: ???
 * int: ???
"""

---

review: Needs Fixing
1297. By Diego Sarmentero

fixing docstrings

1298. By Diego Sarmentero

fixing tests

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'contrib/testing/testcase.py'
--- contrib/testing/testcase.py 2012-06-22 09:59:14 +0000
+++ contrib/testing/testcase.py 2012-08-13 15:04:21 +0000
@@ -57,6 +57,8 @@
57 main,57 main,
58 local_rescan,58 local_rescan,
59 tritcask,59 tritcask,
60 RECENT_TRANSFERS,
61 UPLOADING,
60)62)
61from ubuntuone.syncdaemon import logger63from ubuntuone.syncdaemon import logger
62from ubuntuone import platform64from ubuntuone import platform
@@ -208,6 +210,10 @@
208210
209 show_all_notifications = True211 show_all_notifications = True
210212
213 def menu_data(self):
214 """Fake menu_data."""
215 return {RECENT_TRANSFERS: [], UPLOADING: []}
216
211217
212class FakeMain(main.Main):218class FakeMain(main.Main):
213 """ A fake Main class to setup the tests """219 """ A fake Main class to setup the tests """
214220
=== modified file 'tests/platform/ipc/test_external_interface.py'
--- tests/platform/ipc/test_external_interface.py 2012-08-03 14:56:05 +0000
+++ tests/platform/ipc/test_external_interface.py 2012-08-13 15:04:21 +0000
@@ -40,6 +40,10 @@
40 StatusTestCase,40 StatusTestCase,
41 SyncDaemonTestCase,41 SyncDaemonTestCase,
42)42)
43from ubuntuone.syncdaemon import (
44 RECENT_TRANSFERS,
45 UPLOADING,
46)
4347
44STR = 'something'48STR = 'something'
45STR_STR_DICT = {'foo': 'bar'}49STR_STR_DICT = {'foo': 'bar'}
@@ -132,6 +136,16 @@
132 self.assert_remote_method('waiting_metadata',136 self.assert_remote_method('waiting_metadata',
133 in_signature=None, out_signature='a(sa{ss})')137 in_signature=None, out_signature='a(sa{ss})')
134138
139 @defer.inlineCallbacks
140 def test_sync_menu(self):
141 """Test sync_menu."""
142 result = {RECENT_TRANSFERS: [], UPLOADING: []}
143 method = 'sync_menu'
144 yield self.assert_method_called(self.service.status,
145 method, result)
146 self.assert_remote_method(method,
147 in_signature=None, out_signature='a{sv}')
148
135149
136class EventsTests(EventsTestCase):150class EventsTests(EventsTestCase):
137 """Basic tests for the Events exposed object."""151 """Basic tests for the Events exposed object."""
138152
=== modified file 'tests/platform/test_tools.py'
--- tests/platform/test_tools.py 2012-05-30 15:35:49 +0000
+++ tests/platform/test_tools.py 2012-08-13 15:04:21 +0000
@@ -36,12 +36,15 @@
36from ubuntuone.devtools.handlers import MementoHandler36from ubuntuone.devtools.handlers import MementoHandler
3737
38from contrib.testing.testcase import FakeCommand, skipIfOS38from contrib.testing.testcase import FakeCommand, skipIfOS
39
39from ubuntuone.syncdaemon import (40from ubuntuone.syncdaemon import (
40 action_queue,41 action_queue,
41 event_queue,42 event_queue,
42 interaction_interfaces,43 interaction_interfaces,
43 states,44 states,
44 volume_manager,45 volume_manager,
46 RECENT_TRANSFERS,
47 UPLOADING,
45)48)
46from ubuntuone.platform import tools49from ubuntuone.platform import tools
47from tests.platform import IPCTestCase50from tests.platform import IPCTestCase
@@ -243,6 +246,13 @@
243 self.assertEqual('share_id', result['volume_id'])246 self.assertEqual('share_id', result['volume_id'])
244 self.assertEqual(False, self.main.vm.shares['share_id'].accepted)247 self.assertEqual(False, self.main.vm.shares['share_id'].accepted)
245248
249 @defer.inlineCallbacks
250 def test_sync_menu(self):
251 """Test accept_share method."""
252 result = yield self.tool.sync_menu()
253 self.assertIn(RECENT_TRANSFERS, result)
254 self.assertIn(UPLOADING, result)
255
246256
247class TestWaitForSignals(TestToolsBase):257class TestWaitForSignals(TestToolsBase):
248 """Test case for the wait_for_signals method from SyncDaemonTool."""258 """Test case for the wait_for_signals method from SyncDaemonTool."""
249259
=== modified file 'tests/status/test_aggregator.py'
--- tests/status/test_aggregator.py 2012-08-06 14:25:15 +0000
+++ tests/status/test_aggregator.py 2012-08-13 15:04:21 +0000
@@ -42,7 +42,11 @@
42from ubuntuone.status import aggregator42from ubuntuone.status import aggregator
43from ubuntuone.status.notification import AbstractNotification43from ubuntuone.status.notification import AbstractNotification
44from ubuntuone.status.messaging import AbstractMessaging44from ubuntuone.status.messaging import AbstractMessaging
45from ubuntuone.syncdaemon import status_listener45from ubuntuone.syncdaemon import (
46 status_listener,
47 RECENT_TRANSFERS,
48 UPLOADING,
49)
46from ubuntuone.syncdaemon.volume_manager import Share, UDF, Root50from ubuntuone.syncdaemon.volume_manager import Share, UDF, Root
4751
48FILENAME = 'example.txt'52FILENAME = 'example.txt'
@@ -813,11 +817,12 @@
813 self.listener.handle_SYS_QUEUE_ADDED(fake_command)817 self.listener.handle_SYS_QUEUE_ADDED(fake_command)
814 self.listener.handle_SYS_QUEUE_REMOVED(fake_command)818 self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
815 transfers = self.status_frontend.recent_transfers()819 transfers = self.status_frontend.recent_transfers()
816 expected = ('path1', 'path2', 'path3')820 expected = ['path1', 'path2', 'path3']
817 self.assertEqual(transfers, expected)821 self.assertEqual(transfers, expected)
818822
819 menu_data = self.listener.menu_data()823 menu_data = self.listener.menu_data()
820 self.assertEqual(menu_data, ([], expected))824 self.assertEqual(menu_data,
825 {UPLOADING: [], RECENT_TRANSFERS: expected})
821826
822 def test_file_uploading(self):827 def test_file_uploading(self):
823 """Check that it returns a list with the path, size, and progress."""828 """Check that it returns a list with the path, size, and progress."""
@@ -827,7 +832,8 @@
827 expected = [('testfile.txt', 0, 0)]832 expected = [('testfile.txt', 0, 0)]
828 self.assertEqual(uploading, expected)833 self.assertEqual(uploading, expected)
829 menu_data = self.listener.menu_data()834 menu_data = self.listener.menu_data()
830 self.assertEqual(menu_data, (expected, ()))835 self.assertEqual(menu_data,
836 {UPLOADING: expected, RECENT_TRANSFERS: []})
831837
832 fc.size = 1000838 fc.size = 1000
833 fc.n_bytes_written = 200839 fc.n_bytes_written = 200
@@ -840,7 +846,8 @@
840 self.assertEqual(uploading, expected)846 self.assertEqual(uploading, expected)
841847
842 menu_data = self.listener.menu_data()848 menu_data = self.listener.menu_data()
843 self.assertEqual(menu_data, (expected, ()))849 self.assertEqual(menu_data,
850 {UPLOADING: expected, RECENT_TRANSFERS: []})
844851
845 def test_menu_data_full_response(self):852 def test_menu_data_full_response(self):
846 """Check that listener.menu_data returns both uploading and recent."""853 """Check that listener.menu_data returns both uploading and recent."""
@@ -854,9 +861,11 @@
854 self.status_frontend.upload_started(fc)861 self.status_frontend.upload_started(fc)
855 uploading = self.status_frontend.files_uploading()862 uploading = self.status_frontend.files_uploading()
856 transfers = self.status_frontend.recent_transfers()863 transfers = self.status_frontend.recent_transfers()
857 expected = ([('testfile.txt', 1000, 200)], ('path1',))864 expected = {UPLOADING: [('testfile.txt', 1000, 200)],
865 RECENT_TRANSFERS: ['path1']}
858866
859 self.assertEqual((uploading, transfers), expected)867 self.assertEqual(
868 {UPLOADING: uploading, RECENT_TRANSFERS: transfers}, expected)
860869
861 def test_file_published(self):870 def test_file_published(self):
862 """A file published event is processed."""871 """A file published event is processed."""
863872
=== modified file 'ubuntuone/platform/ipc/ipc_client.py'
--- ubuntuone/platform/ipc/ipc_client.py 2012-05-22 14:28:56 +0000
+++ ubuntuone/platform/ipc/ipc_client.py 2012-08-13 15:04:21 +0000
@@ -197,6 +197,22 @@
197 def current_uploads(self):197 def current_uploads(self):
198 """Return a list of files with a upload in progress."""198 """Return a list of files with a upload in progress."""
199199
200 @remote
201 def sync_menu(self):
202 """
203 This method returns a dictionary, with the following keys and values:
204
205 Key: 'recent-transfers'
206 Value: a list of strings (paths), each being the name of a file that
207 was recently transferred.
208
209 Key: 'uploading'
210 Value: a list of tuples, with each tuple having the following items:
211 * str: the path of a file that's currently being uploaded
212 * int: size of the file
213 * int: bytes written
214 """
215
200 @signal216 @signal
201 def on_content_queue_changed(self):217 def on_content_queue_changed(self):
202 """Emit ContentQueueChanged."""218 """Emit ContentQueueChanged."""
203219
=== modified file 'ubuntuone/platform/ipc/linux.py'
--- ubuntuone/platform/ipc/linux.py 2012-05-22 14:07:55 +0000
+++ ubuntuone/platform/ipc/linux.py 2012-08-13 15:04:21 +0000
@@ -38,6 +38,10 @@
38from xml.etree import ElementTree38from xml.etree import ElementTree
3939
40from ubuntuone.platform.launcher import UbuntuOneLauncher40from ubuntuone.platform.launcher import UbuntuOneLauncher
41from ubuntuone.syncdaemon import (
42 RECENT_TRANSFERS,
43 UPLOADING,
44)
4145
42# Disable the "Invalid Name" check here, as we have lots of DBus style names46# Disable the "Invalid Name" check here, as we have lots of DBus style names
43# pylint: disable-msg=C010347# pylint: disable-msg=C0103
@@ -173,6 +177,35 @@
173 warnings.warn('Use "waiting" method instead.', DeprecationWarning)177 warnings.warn('Use "waiting" method instead.', DeprecationWarning)
174 return self.service.status.waiting_content()178 return self.service.status.waiting_content()
175179
180 @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='a{sv}')
181 def sync_menu(self):
182 """
183 This method returns a dictionary, with the following keys and values:
184
185 Key: 'recent-transfers'
186 Value: a list of strings (paths), each being the name of a file that
187 was recently transferred.
188
189 Key: 'uploading'
190 Value: a list of tuples, with each tuple having the following items:
191 * str: the path of a file that's currently being uploaded
192 * int: size of the file
193 * int: bytes written
194 """
195 data = self.service.status.sync_menu()
196 uploading = data[UPLOADING]
197 transfers = data[RECENT_TRANSFERS]
198 upload_data = dbus.Array(signature="(sii)")
199 transfer_data = dbus.Array(signature="s")
200 for up in uploading:
201 upload_data.append(dbus.Struct(up, signature="sii"))
202 for transfer in transfers:
203 transfer_data.append(transfer)
204 result = dbus.Dictionary(signature="sv")
205 result[UPLOADING] = upload_data
206 result[RECENT_TRANSFERS] = transfer_data
207 return result
208
176 @dbus.service.signal(DBUS_IFACE_STATUS_NAME)209 @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
177 def DownloadStarted(self, path):210 def DownloadStarted(self, path):
178 """Fire a signal to notify that a download has started."""211 """Fire a signal to notify that a download has started."""
179212
=== modified file 'ubuntuone/platform/ipc/perspective_broker.py'
--- ubuntuone/platform/ipc/perspective_broker.py 2012-07-13 16:06:27 +0000
+++ ubuntuone/platform/ipc/perspective_broker.py 2012-08-13 15:04:21 +0000
@@ -231,6 +231,7 @@
231 'waiting',231 'waiting',
232 'waiting_metadata',232 'waiting_metadata',
233 'waiting_content',233 'waiting_content',
234 'sync_menu',
234 ]235 ]
235236
236 signal_mapping = {237 signal_mapping = {
@@ -291,6 +292,10 @@
291 warnings.warn('Use "waiting" method instead.', DeprecationWarning)292 warnings.warn('Use "waiting" method instead.', DeprecationWarning)
292 return self.service.status.waiting_content()293 return self.service.status.waiting_content()
293294
295 def sync_menu(self):
296 """Return the info necessary to construct the menu."""
297 return self.service.status.sync_menu()
298
294 @signal299 @signal
295 def DownloadStarted(self, path):300 def DownloadStarted(self, path):
296 """Fire a signal to notify that a download has started."""301 """Fire a signal to notify that a download has started."""
297302
=== modified file 'ubuntuone/platform/tools/__init__.py'
--- ubuntuone/platform/tools/__init__.py 2012-05-30 15:35:49 +0000
+++ ubuntuone/platform/tools/__init__.py 2012-08-13 15:04:21 +0000
@@ -326,6 +326,13 @@
326326
327 @defer.inlineCallbacks327 @defer.inlineCallbacks
328 @log_call(logger.debug)328 @log_call(logger.debug)
329 def sync_menu(self):
330 """Return a deferred that will be fired with the sync menu data."""
331 results = yield self.proxy.call_method('status', 'sync_menu')
332 defer.returnValue(results)
333
334 @defer.inlineCallbacks
335 @log_call(logger.debug)
329 def accept_share(self, share_id):336 def accept_share(self, share_id):
330 """Accept the share with id: share_id."""337 """Accept the share with id: share_id."""
331 d = self.wait_for_signals(signal_ok='ShareAnswerResponse',338 d = self.wait_for_signals(signal_ok='ShareAnswerResponse',
332339
=== modified file 'ubuntuone/status/aggregator.py'
--- ubuntuone/status/aggregator.py 2012-08-06 14:25:15 +0000
+++ ubuntuone/status/aggregator.py 2012-08-13 15:04:21 +0000
@@ -810,7 +810,7 @@
810810
811 def recent_transfers(self):811 def recent_transfers(self):
812 """Return a tuple with the recent transfers paths."""812 """Return a tuple with the recent transfers paths."""
813 return tuple(self.aggregator.recent_transfers)813 return list(self.aggregator.recent_transfers)
814814
815 def files_uploading(self):815 def files_uploading(self):
816 """Return a list with the files being uploading."""816 """Return a list with the files being uploading."""
817817
=== modified file 'ubuntuone/syncdaemon/__init__.py'
--- ubuntuone/syncdaemon/__init__.py 2012-04-09 20:07:05 +0000
+++ ubuntuone/syncdaemon/__init__.py 2012-08-13 15:04:21 +0000
@@ -36,3 +36,8 @@
36 "volumes",36 "volumes",
37 "generations",37 "generations",
38 ])38 ])
39
40
41#Sync Menu data constants
42RECENT_TRANSFERS = 'recent-transfers'
43UPLOADING = 'uploading'
3944
=== modified file 'ubuntuone/syncdaemon/interaction_interfaces.py'
--- ubuntuone/syncdaemon/interaction_interfaces.py 2012-08-08 18:36:17 +0000
+++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-08-13 15:04:21 +0000
@@ -302,6 +302,10 @@
302 waiting_content.append(data)302 waiting_content.append(data)
303 return waiting_content303 return waiting_content
304304
305 def sync_menu(self):
306 """Return the info necessary to construct the menu."""
307 return self.main.status_listener.menu_data()
308
305309
306class SyncdaemonFileSystem(SyncdaemonObject):310class SyncdaemonFileSystem(SyncdaemonObject):
307 """An interface to the FileSystem Manager."""311 """An interface to the FileSystem Manager."""
308312
=== modified file 'ubuntuone/syncdaemon/status_listener.py'
--- ubuntuone/syncdaemon/status_listener.py 2012-08-03 14:56:05 +0000
+++ ubuntuone/syncdaemon/status_listener.py 2012-08-13 15:04:21 +0000
@@ -31,7 +31,12 @@
31"""Listener for event queue that updates the UI to show syncdaemon status."""31"""Listener for event queue that updates the UI to show syncdaemon status."""
3232
33from ubuntuone.status.aggregator import StatusFrontend33from ubuntuone.status.aggregator import StatusFrontend
34from ubuntuone.syncdaemon import action_queue, config34from ubuntuone.syncdaemon import (
35 action_queue,
36 config,
37 RECENT_TRANSFERS,
38 UPLOADING,
39)
35from ubuntuone.syncdaemon.interaction_interfaces import (40from ubuntuone.syncdaemon.interaction_interfaces import (
36 get_share_dict, get_udf_dict)41 get_share_dict, get_udf_dict)
37from ubuntuone.syncdaemon.volume_manager import UDF, Root42from ubuntuone.syncdaemon.volume_manager import UDF, Root
@@ -68,9 +73,10 @@
6873
69 def menu_data(self):74 def menu_data(self):
70 """Return the info necessary to construct the sync menu."""75 """Return the info necessary to construct the sync menu."""
76 uploading = self.status_frontend.files_uploading()
71 transfers = self.status_frontend.recent_transfers()77 transfers = self.status_frontend.recent_transfers()
72 uploading = self.status_frontend.files_uploading()78 data = {RECENT_TRANSFERS: transfers, UPLOADING: uploading}
73 return uploading, transfers79 return data
7480
75 def get_show_all_notifications(self):81 def get_show_all_notifications(self):
76 """Get the value of show_all_notifications."""82 """Get the value of show_all_notifications."""

Subscribers

People subscribed via source and target branches