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
1=== modified file 'contrib/testing/testcase.py'
2--- contrib/testing/testcase.py 2012-06-22 09:59:14 +0000
3+++ contrib/testing/testcase.py 2012-08-13 15:04:21 +0000
4@@ -57,6 +57,8 @@
5 main,
6 local_rescan,
7 tritcask,
8+ RECENT_TRANSFERS,
9+ UPLOADING,
10 )
11 from ubuntuone.syncdaemon import logger
12 from ubuntuone import platform
13@@ -208,6 +210,10 @@
14
15 show_all_notifications = True
16
17+ def menu_data(self):
18+ """Fake menu_data."""
19+ return {RECENT_TRANSFERS: [], UPLOADING: []}
20+
21
22 class FakeMain(main.Main):
23 """ A fake Main class to setup the tests """
24
25=== modified file 'tests/platform/ipc/test_external_interface.py'
26--- tests/platform/ipc/test_external_interface.py 2012-08-03 14:56:05 +0000
27+++ tests/platform/ipc/test_external_interface.py 2012-08-13 15:04:21 +0000
28@@ -40,6 +40,10 @@
29 StatusTestCase,
30 SyncDaemonTestCase,
31 )
32+from ubuntuone.syncdaemon import (
33+ RECENT_TRANSFERS,
34+ UPLOADING,
35+)
36
37 STR = 'something'
38 STR_STR_DICT = {'foo': 'bar'}
39@@ -132,6 +136,16 @@
40 self.assert_remote_method('waiting_metadata',
41 in_signature=None, out_signature='a(sa{ss})')
42
43+ @defer.inlineCallbacks
44+ def test_sync_menu(self):
45+ """Test sync_menu."""
46+ result = {RECENT_TRANSFERS: [], UPLOADING: []}
47+ method = 'sync_menu'
48+ yield self.assert_method_called(self.service.status,
49+ method, result)
50+ self.assert_remote_method(method,
51+ in_signature=None, out_signature='a{sv}')
52+
53
54 class EventsTests(EventsTestCase):
55 """Basic tests for the Events exposed object."""
56
57=== modified file 'tests/platform/test_tools.py'
58--- tests/platform/test_tools.py 2012-05-30 15:35:49 +0000
59+++ tests/platform/test_tools.py 2012-08-13 15:04:21 +0000
60@@ -36,12 +36,15 @@
61 from ubuntuone.devtools.handlers import MementoHandler
62
63 from contrib.testing.testcase import FakeCommand, skipIfOS
64+
65 from ubuntuone.syncdaemon import (
66 action_queue,
67 event_queue,
68 interaction_interfaces,
69 states,
70 volume_manager,
71+ RECENT_TRANSFERS,
72+ UPLOADING,
73 )
74 from ubuntuone.platform import tools
75 from tests.platform import IPCTestCase
76@@ -243,6 +246,13 @@
77 self.assertEqual('share_id', result['volume_id'])
78 self.assertEqual(False, self.main.vm.shares['share_id'].accepted)
79
80+ @defer.inlineCallbacks
81+ def test_sync_menu(self):
82+ """Test accept_share method."""
83+ result = yield self.tool.sync_menu()
84+ self.assertIn(RECENT_TRANSFERS, result)
85+ self.assertIn(UPLOADING, result)
86+
87
88 class TestWaitForSignals(TestToolsBase):
89 """Test case for the wait_for_signals method from SyncDaemonTool."""
90
91=== modified file 'tests/status/test_aggregator.py'
92--- tests/status/test_aggregator.py 2012-08-06 14:25:15 +0000
93+++ tests/status/test_aggregator.py 2012-08-13 15:04:21 +0000
94@@ -42,7 +42,11 @@
95 from ubuntuone.status import aggregator
96 from ubuntuone.status.notification import AbstractNotification
97 from ubuntuone.status.messaging import AbstractMessaging
98-from ubuntuone.syncdaemon import status_listener
99+from ubuntuone.syncdaemon import (
100+ status_listener,
101+ RECENT_TRANSFERS,
102+ UPLOADING,
103+)
104 from ubuntuone.syncdaemon.volume_manager import Share, UDF, Root
105
106 FILENAME = 'example.txt'
107@@ -813,11 +817,12 @@
108 self.listener.handle_SYS_QUEUE_ADDED(fake_command)
109 self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
110 transfers = self.status_frontend.recent_transfers()
111- expected = ('path1', 'path2', 'path3')
112+ expected = ['path1', 'path2', 'path3']
113 self.assertEqual(transfers, expected)
114
115 menu_data = self.listener.menu_data()
116- self.assertEqual(menu_data, ([], expected))
117+ self.assertEqual(menu_data,
118+ {UPLOADING: [], RECENT_TRANSFERS: expected})
119
120 def test_file_uploading(self):
121 """Check that it returns a list with the path, size, and progress."""
122@@ -827,7 +832,8 @@
123 expected = [('testfile.txt', 0, 0)]
124 self.assertEqual(uploading, expected)
125 menu_data = self.listener.menu_data()
126- self.assertEqual(menu_data, (expected, ()))
127+ self.assertEqual(menu_data,
128+ {UPLOADING: expected, RECENT_TRANSFERS: []})
129
130 fc.size = 1000
131 fc.n_bytes_written = 200
132@@ -840,7 +846,8 @@
133 self.assertEqual(uploading, expected)
134
135 menu_data = self.listener.menu_data()
136- self.assertEqual(menu_data, (expected, ()))
137+ self.assertEqual(menu_data,
138+ {UPLOADING: expected, RECENT_TRANSFERS: []})
139
140 def test_menu_data_full_response(self):
141 """Check that listener.menu_data returns both uploading and recent."""
142@@ -854,9 +861,11 @@
143 self.status_frontend.upload_started(fc)
144 uploading = self.status_frontend.files_uploading()
145 transfers = self.status_frontend.recent_transfers()
146- expected = ([('testfile.txt', 1000, 200)], ('path1',))
147+ expected = {UPLOADING: [('testfile.txt', 1000, 200)],
148+ RECENT_TRANSFERS: ['path1']}
149
150- self.assertEqual((uploading, transfers), expected)
151+ self.assertEqual(
152+ {UPLOADING: uploading, RECENT_TRANSFERS: transfers}, expected)
153
154 def test_file_published(self):
155 """A file published event is processed."""
156
157=== modified file 'ubuntuone/platform/ipc/ipc_client.py'
158--- ubuntuone/platform/ipc/ipc_client.py 2012-05-22 14:28:56 +0000
159+++ ubuntuone/platform/ipc/ipc_client.py 2012-08-13 15:04:21 +0000
160@@ -197,6 +197,22 @@
161 def current_uploads(self):
162 """Return a list of files with a upload in progress."""
163
164+ @remote
165+ def sync_menu(self):
166+ """
167+ This method returns a dictionary, with the following keys and values:
168+
169+ Key: 'recent-transfers'
170+ Value: a list of strings (paths), each being the name of a file that
171+ was recently transferred.
172+
173+ Key: 'uploading'
174+ Value: a list of tuples, with each tuple having the following items:
175+ * str: the path of a file that's currently being uploaded
176+ * int: size of the file
177+ * int: bytes written
178+ """
179+
180 @signal
181 def on_content_queue_changed(self):
182 """Emit ContentQueueChanged."""
183
184=== modified file 'ubuntuone/platform/ipc/linux.py'
185--- ubuntuone/platform/ipc/linux.py 2012-05-22 14:07:55 +0000
186+++ ubuntuone/platform/ipc/linux.py 2012-08-13 15:04:21 +0000
187@@ -38,6 +38,10 @@
188 from xml.etree import ElementTree
189
190 from ubuntuone.platform.launcher import UbuntuOneLauncher
191+from ubuntuone.syncdaemon import (
192+ RECENT_TRANSFERS,
193+ UPLOADING,
194+)
195
196 # Disable the "Invalid Name" check here, as we have lots of DBus style names
197 # pylint: disable-msg=C0103
198@@ -173,6 +177,35 @@
199 warnings.warn('Use "waiting" method instead.', DeprecationWarning)
200 return self.service.status.waiting_content()
201
202+ @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='a{sv}')
203+ def sync_menu(self):
204+ """
205+ This method returns a dictionary, with the following keys and values:
206+
207+ Key: 'recent-transfers'
208+ Value: a list of strings (paths), each being the name of a file that
209+ was recently transferred.
210+
211+ Key: 'uploading'
212+ Value: a list of tuples, with each tuple having the following items:
213+ * str: the path of a file that's currently being uploaded
214+ * int: size of the file
215+ * int: bytes written
216+ """
217+ data = self.service.status.sync_menu()
218+ uploading = data[UPLOADING]
219+ transfers = data[RECENT_TRANSFERS]
220+ upload_data = dbus.Array(signature="(sii)")
221+ transfer_data = dbus.Array(signature="s")
222+ for up in uploading:
223+ upload_data.append(dbus.Struct(up, signature="sii"))
224+ for transfer in transfers:
225+ transfer_data.append(transfer)
226+ result = dbus.Dictionary(signature="sv")
227+ result[UPLOADING] = upload_data
228+ result[RECENT_TRANSFERS] = transfer_data
229+ return result
230+
231 @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
232 def DownloadStarted(self, path):
233 """Fire a signal to notify that a download has started."""
234
235=== modified file 'ubuntuone/platform/ipc/perspective_broker.py'
236--- ubuntuone/platform/ipc/perspective_broker.py 2012-07-13 16:06:27 +0000
237+++ ubuntuone/platform/ipc/perspective_broker.py 2012-08-13 15:04:21 +0000
238@@ -231,6 +231,7 @@
239 'waiting',
240 'waiting_metadata',
241 'waiting_content',
242+ 'sync_menu',
243 ]
244
245 signal_mapping = {
246@@ -291,6 +292,10 @@
247 warnings.warn('Use "waiting" method instead.', DeprecationWarning)
248 return self.service.status.waiting_content()
249
250+ def sync_menu(self):
251+ """Return the info necessary to construct the menu."""
252+ return self.service.status.sync_menu()
253+
254 @signal
255 def DownloadStarted(self, path):
256 """Fire a signal to notify that a download has started."""
257
258=== modified file 'ubuntuone/platform/tools/__init__.py'
259--- ubuntuone/platform/tools/__init__.py 2012-05-30 15:35:49 +0000
260+++ ubuntuone/platform/tools/__init__.py 2012-08-13 15:04:21 +0000
261@@ -326,6 +326,13 @@
262
263 @defer.inlineCallbacks
264 @log_call(logger.debug)
265+ def sync_menu(self):
266+ """Return a deferred that will be fired with the sync menu data."""
267+ results = yield self.proxy.call_method('status', 'sync_menu')
268+ defer.returnValue(results)
269+
270+ @defer.inlineCallbacks
271+ @log_call(logger.debug)
272 def accept_share(self, share_id):
273 """Accept the share with id: share_id."""
274 d = self.wait_for_signals(signal_ok='ShareAnswerResponse',
275
276=== modified file 'ubuntuone/status/aggregator.py'
277--- ubuntuone/status/aggregator.py 2012-08-06 14:25:15 +0000
278+++ ubuntuone/status/aggregator.py 2012-08-13 15:04:21 +0000
279@@ -810,7 +810,7 @@
280
281 def recent_transfers(self):
282 """Return a tuple with the recent transfers paths."""
283- return tuple(self.aggregator.recent_transfers)
284+ return list(self.aggregator.recent_transfers)
285
286 def files_uploading(self):
287 """Return a list with the files being uploading."""
288
289=== modified file 'ubuntuone/syncdaemon/__init__.py'
290--- ubuntuone/syncdaemon/__init__.py 2012-04-09 20:07:05 +0000
291+++ ubuntuone/syncdaemon/__init__.py 2012-08-13 15:04:21 +0000
292@@ -36,3 +36,8 @@
293 "volumes",
294 "generations",
295 ])
296+
297+
298+#Sync Menu data constants
299+RECENT_TRANSFERS = 'recent-transfers'
300+UPLOADING = 'uploading'
301
302=== modified file 'ubuntuone/syncdaemon/interaction_interfaces.py'
303--- ubuntuone/syncdaemon/interaction_interfaces.py 2012-08-08 18:36:17 +0000
304+++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-08-13 15:04:21 +0000
305@@ -302,6 +302,10 @@
306 waiting_content.append(data)
307 return waiting_content
308
309+ def sync_menu(self):
310+ """Return the info necessary to construct the menu."""
311+ return self.main.status_listener.menu_data()
312+
313
314 class SyncdaemonFileSystem(SyncdaemonObject):
315 """An interface to the FileSystem Manager."""
316
317=== modified file 'ubuntuone/syncdaemon/status_listener.py'
318--- ubuntuone/syncdaemon/status_listener.py 2012-08-03 14:56:05 +0000
319+++ ubuntuone/syncdaemon/status_listener.py 2012-08-13 15:04:21 +0000
320@@ -31,7 +31,12 @@
321 """Listener for event queue that updates the UI to show syncdaemon status."""
322
323 from ubuntuone.status.aggregator import StatusFrontend
324-from ubuntuone.syncdaemon import action_queue, config
325+from ubuntuone.syncdaemon import (
326+ action_queue,
327+ config,
328+ RECENT_TRANSFERS,
329+ UPLOADING,
330+)
331 from ubuntuone.syncdaemon.interaction_interfaces import (
332 get_share_dict, get_udf_dict)
333 from ubuntuone.syncdaemon.volume_manager import UDF, Root
334@@ -68,9 +73,10 @@
335
336 def menu_data(self):
337 """Return the info necessary to construct the sync menu."""
338+ uploading = self.status_frontend.files_uploading()
339 transfers = self.status_frontend.recent_transfers()
340- uploading = self.status_frontend.files_uploading()
341- return uploading, transfers
342+ data = {RECENT_TRANSFERS: transfers, UPLOADING: uploading}
343+ return data
344
345 def get_show_all_notifications(self):
346 """Get the value of show_all_notifications."""

Subscribers

People subscribed via source and target branches