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

Proposed by Diego Sarmentero on 2012-08-03
Status: Merged
Approved by: Diego Sarmentero on 2012-08-08
Approved revision: 1286
Merged at revision: 1288
Proposed branch: lp:~diegosarmentero/ubuntuone-client/menu
Merge into: lp:ubuntuone-client
Diff against target: 174 lines (+92/-1)
3 files modified
tests/status/test_aggregator.py (+71/-0)
ubuntuone/status/aggregator.py (+15/-1)
ubuntuone/syncdaemon/status_listener.py (+6/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-client/menu
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2012-08-07
Roberto Alsina (community) 2012-08-03 Approve on 2012-08-03
Review via email: mp+118117@code.launchpad.net

Commit Message

- Collect and return the data for the menu from aggregator (LP: #1032659).

To post a comment you must log in.
Roberto Alsina (ralsina) wrote :

Nice!

review: Approve
Alejandro J. Cura (alecu) wrote :

deque ftw!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/status/test_aggregator.py'
2--- tests/status/test_aggregator.py 2012-04-09 20:07:05 +0000
3+++ tests/status/test_aggregator.py 2012-08-06 14:27:25 +0000
4@@ -706,6 +706,8 @@
5 self.share_id = path
6 self.node_id = path
7 self.deflated_size = 10000
8+ self.size = 0
9+ self.n_bytes_written = 0
10
11
12 class FakeVolumeManager(object):
13@@ -733,6 +735,7 @@
14 self.files_uploading = []
15 self.files_downloading = []
16 self.progress_events = []
17+ self.recent_transfers = aggregator.deque(maxlen=10)
18
19 def queue_done(self):
20 """The queue completed all operations."""
21@@ -762,6 +765,7 @@
22 """An upload just finished."""
23 if command in self.files_uploading:
24 self.files_uploading.remove(command)
25+ self.recent_transfers.append(command.path)
26 self.queued_commands.discard(command)
27
28 def progress_made(self, share_id, node_id, n_bytes, deflated_size):
29@@ -796,6 +800,64 @@
30 self.fakevm,
31 self.status_frontend)
32
33+ def test_recent_transfers(self):
34+ """Check that it generates a tuple with the recent transfers."""
35+ self.patch(status_listener.action_queue, "Upload", FakeCommand)
36+ fake_command = FakeCommand('path1')
37+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
38+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
39+ fake_command = FakeCommand('path2')
40+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
41+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
42+ fake_command = FakeCommand('path3')
43+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
44+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
45+ transfers = self.status_frontend.recent_transfers()
46+ expected = ('path1', 'path2', 'path3')
47+ self.assertEqual(transfers, expected)
48+
49+ menu_data = self.listener.menu_data()
50+ self.assertEqual(menu_data, ([], expected))
51+
52+ def test_file_uploading(self):
53+ """Check that it returns a list with the path, size, and progress."""
54+ fc = FakeCommand(path='testfile.txt')
55+ self.status_frontend.upload_started(fc)
56+ uploading = self.status_frontend.files_uploading()
57+ expected = [('testfile.txt', 0, 0)]
58+ self.assertEqual(uploading, expected)
59+ menu_data = self.listener.menu_data()
60+ self.assertEqual(menu_data, (expected, ()))
61+
62+ fc.size = 1000
63+ fc.n_bytes_written = 200
64+ fc2 = FakeCommand(path='testfile2.txt')
65+ fc2.size = 2000
66+ fc2.n_bytes_written = 450
67+ self.status_frontend.upload_started(fc2)
68+ uploading = self.status_frontend.files_uploading()
69+ expected = [('testfile.txt', 1000, 200), ('testfile2.txt', 2000, 450)]
70+ self.assertEqual(uploading, expected)
71+
72+ menu_data = self.listener.menu_data()
73+ self.assertEqual(menu_data, (expected, ()))
74+
75+ def test_menu_data_full_response(self):
76+ """Check that listener.menu_data returns both uploading and recent."""
77+ self.patch(status_listener.action_queue, "Upload", FakeCommand)
78+ fake_command = FakeCommand('path1')
79+ self.listener.handle_SYS_QUEUE_ADDED(fake_command)
80+ self.listener.handle_SYS_QUEUE_REMOVED(fake_command)
81+ fc = FakeCommand(path='testfile.txt')
82+ fc.size = 1000
83+ fc.n_bytes_written = 200
84+ self.status_frontend.upload_started(fc)
85+ uploading = self.status_frontend.files_uploading()
86+ transfers = self.status_frontend.recent_transfers()
87+ expected = ([('testfile.txt', 1000, 200)], ('path1',))
88+
89+ self.assertEqual((uploading, transfers), expected)
90+
91 def test_file_published(self):
92 """A file published event is processed."""
93 share_id = "fake share id"
94@@ -1308,6 +1370,15 @@
95 self.assertEqual(
96 {(fc.share_id, fc.node_id): (fc.deflated_size)},
97 self.aggregator.progress)
98+ self.assertEqual(len(self.aggregator.recent_transfers), 1)
99+
100+ def test_max_recent_files(self):
101+ """Check that the queue doesn't exceed the 10 items."""
102+ for i in range(15):
103+ fc = FakeCommand()
104+ self.status_frontend.upload_started(fc)
105+ self.status_frontend.upload_finished(fc)
106+ self.assertEqual(len(self.aggregator.recent_transfers), 10)
107
108 def test_progress_made(self):
109 """Progress on up and downloads is tracked."""
110
111=== modified file 'ubuntuone/status/aggregator.py'
112--- ubuntuone/status/aggregator.py 2012-04-09 20:07:05 +0000
113+++ ubuntuone/status/aggregator.py 2012-08-06 14:27:25 +0000
114@@ -33,7 +33,7 @@
115 import itertools
116 import operator
117 import os
118-
119+from collections import deque
120
121 import gettext
122
123@@ -624,6 +624,7 @@
124 self.finished_delay = 10
125 self.progress = {}
126 self.to_do = {}
127+ self.recent_transfers = deque(maxlen=10)
128
129 def get_notification(self):
130 """Create a new toggleable notification object."""
131@@ -775,6 +776,7 @@
132 if command.deflated_size is not None:
133 self.progress[
134 (command.share_id, command.node_id)] = command.deflated_size
135+ self.recent_transfers.append(command.path)
136 logger.debug("unqueueing command: %s", command.__class__.__name__)
137 self.update_progressbar()
138
139@@ -806,6 +808,18 @@
140 self.messaging = Messaging()
141 self.quota_timer = None
142
143+ def recent_transfers(self):
144+ """Return a tuple with the recent transfers paths."""
145+ return tuple(self.aggregator.recent_transfers)
146+
147+ def files_uploading(self):
148+ """Return a list with the files being uploading."""
149+ uploading = []
150+ for upload in self.aggregator.files_uploading:
151+ uploading.append((upload.path, upload.size,
152+ upload.n_bytes_written))
153+ return uploading
154+
155 def file_published(self, public_url):
156 """A file was published."""
157 status_event = FilePublishingStatus(new_public_url=public_url)
158
159=== modified file 'ubuntuone/syncdaemon/status_listener.py'
160--- ubuntuone/syncdaemon/status_listener.py 2012-04-09 20:07:05 +0000
161+++ ubuntuone/syncdaemon/status_listener.py 2012-08-06 14:27:25 +0000
162@@ -66,6 +66,12 @@
163 user_conf = config.get_user_config()
164 self.show_all_notifications = user_conf.get_show_all_notifications()
165
166+ def menu_data(self):
167+ """Return the info necessary to construct the sync menu."""
168+ transfers = self.status_frontend.recent_transfers()
169+ uploading = self.status_frontend.files_uploading()
170+ return uploading, transfers
171+
172 def get_show_all_notifications(self):
173 """Get the value of show_all_notifications."""
174 return self._show_all_notifications

Subscribers

People subscribed via source and target branches