Merge lp:~diegosarmentero/ubuntuone-client/ubuntuone-client-timer into lp:ubuntuone-client
- ubuntuone-client-timer
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Diego Sarmentero | ||||
Approved revision: | 1333 | ||||
Merged at revision: | 1325 | ||||
Proposed branch: | lp:~diegosarmentero/ubuntuone-client/ubuntuone-client-timer | ||||
Merge into: | lp:ubuntuone-client | ||||
Diff against target: |
492 lines (+121/-84) 9 files modified
tests/platform/sync_menu/test_linux.py (+32/-17) tests/status/test_aggregator.py (+15/-0) tests/syncdaemon/test_main.py (+0/-14) tests/syncdaemon/test_status_listener.py (+2/-2) ubuntuone/platform/sync_menu/common.py (+0/-10) ubuntuone/platform/sync_menu/linux.py (+38/-23) ubuntuone/status/aggregator.py (+29/-3) ubuntuone/syncdaemon/main.py (+3/-13) ubuntuone/syncdaemon/status_listener.py (+2/-2) |
||||
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntuone-client/ubuntuone-client-timer | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Mike McCracken (community) | Approve | ||
Review via email: mp+125499@code.launchpad.net |
Commit message
- Using a timer event that doesn't fire continuously if another update timer is in progress (LP: #1052922).
Description of the change
- 1322. By Diego Sarmentero
-
merge
- 1323. By Diego Sarmentero
-
adding logging
- 1324. By Diego Sarmentero
-
fixing test
- 1325. By Diego Sarmentero
-
adding test for register_listener
- 1326. By Diego Sarmentero
-
Improving timer
- 1327. By Diego Sarmentero
-
merge
- 1328. By Diego Sarmentero
-
Timer delay improved
- 1329. By Diego Sarmentero
-
raise error when the object is not callable
- 1330. By Diego Sarmentero
-
tests fixed
Mike McCracken (mikemc) wrote : | # |
OK. looks good - tests pass for me on linux, and there are no new tests to run on darwin or windows.
(I have a branch that'll add tests for windows and darwin)
Mike McCracken (mikemc) wrote : | # |
I should've added - I couldn't IRL test this because I don't have Q running yet, and IRL on darwin dies because of the bug that my other branch fixes...
Mike McCracken (mikemc) wrote : | # |
I just noticed this - this branch removes the method "start_timer" from the UbuntuOneSyncMe
The test in test_linux.py tests the dummy for start_timer, so it also needs to be updated.
Don't worry about fixing the same issue in common.py, my branch will do that.
- 1331. By Diego Sarmentero
-
removing start_timer from dummy
- 1332. By Diego Sarmentero
-
adding missing update_transfers for dummy and test
Alejandro J. Cura (alecu) wrote : | # |
A few quick fixes needed:
The name of test_dummy_
The docstring in test_register_
"listeners_
This docstring is wrong: """Create the sync menu and run the loop.""". It should be """Create the sync menu and register the progress listener."""
- 1333. By Diego Sarmentero
-
fixing naming and docstring problems
Preview Diff
1 | === modified file 'tests/platform/sync_menu/test_linux.py' | |||
2 | --- tests/platform/sync_menu/test_linux.py 2012-09-24 13:09:52 +0000 | |||
3 | +++ tests/platform/sync_menu/test_linux.py 2012-09-26 20:23:20 +0000 | |||
4 | @@ -28,6 +28,7 @@ | |||
5 | 28 | # files in the program, then also delete it here. | 28 | # files in the program, then also delete it here. |
6 | 29 | """Test the Sync Menu.""" | 29 | """Test the Sync Menu.""" |
7 | 30 | 30 | ||
8 | 31 | import time | ||
9 | 31 | from collections import Callable | 32 | from collections import Callable |
10 | 32 | 33 | ||
11 | 33 | from twisted.internet import defer | 34 | from twisted.internet import defer |
12 | @@ -57,18 +58,20 @@ | |||
13 | 57 | return self.uploading_data | 58 | return self.uploading_data |
14 | 58 | 59 | ||
15 | 59 | 60 | ||
28 | 60 | class FakeStatusListener(object): | 61 | class FakeTimer(object): |
29 | 61 | """Fake StatusListener.""" | 62 | """Fake Timer.""" |
30 | 62 | 63 | ||
31 | 63 | def __init__(self): | 64 | def __init__(self, delay): |
32 | 64 | self.status_frontend = FakeStatusFrontend() | 65 | self.delay = delay |
33 | 65 | 66 | self.callback = None | |
34 | 66 | 67 | ||
35 | 67 | class FakeMain(object): | 68 | def addCallback(self, callback): |
36 | 68 | """Fake Main.""" | 69 | """Add callback.""" |
37 | 69 | 70 | self.callback = callback | |
38 | 70 | def __init__(self): | 71 | |
39 | 71 | self.status_listener = FakeStatusListener() | 72 | |
40 | 73 | class FakeSyncdaemonService(object): | ||
41 | 74 | """Fake SyncdaemonService.""" | ||
42 | 72 | 75 | ||
43 | 73 | 76 | ||
44 | 74 | class FakeSyncMenuApp(object): | 77 | class FakeSyncMenuApp(object): |
45 | @@ -101,10 +104,10 @@ | |||
46 | 101 | dummy = linux.DummySyncMenu('random', 'args') | 104 | dummy = linux.DummySyncMenu('random', 'args') |
47 | 102 | self.assertIsInstance(dummy, linux.DummySyncMenu) | 105 | self.assertIsInstance(dummy, linux.DummySyncMenu) |
48 | 103 | 106 | ||
50 | 104 | def test_dummy_has_start_timer(self): | 107 | def test_dummy_has_update_transfers(self): |
51 | 105 | """Check that the dummy has the proper methods required by the API.""" | 108 | """Check that the dummy has the proper methods required by the API.""" |
52 | 106 | dummy = linux.DummySyncMenu('random', 'args') | 109 | dummy = linux.DummySyncMenu('random', 'args') |
54 | 107 | self.assertIsInstance(dummy.start_timer, Callable) | 110 | self.assertIsInstance(dummy.update_transfers, Callable) |
55 | 108 | 111 | ||
56 | 109 | 112 | ||
57 | 110 | class SyncMenuTestCase(TestCase): | 113 | class SyncMenuTestCase(TestCase): |
58 | @@ -117,12 +120,13 @@ | |||
59 | 117 | yield super(SyncMenuTestCase, self).setUp() | 120 | yield super(SyncMenuTestCase, self).setUp() |
60 | 118 | self.patch(linux.SyncMenu, "App", FakeSyncMenuApp) | 121 | self.patch(linux.SyncMenu, "App", FakeSyncMenuApp) |
61 | 119 | FakeSyncMenuApp.clean() | 122 | FakeSyncMenuApp.clean() |
64 | 120 | self.main = FakeMain() | 123 | self.syncdaemon_service = FakeSyncdaemonService() |
65 | 121 | self.status_frontend = self.main.status_listener.status_frontend | 124 | self.status_frontend = FakeStatusFrontend() |
66 | 122 | self._paused = False | 125 | self._paused = False |
67 | 123 | self.patch(sync_menu.UbuntuOneSyncMenu, "change_sync_status", | 126 | self.patch(sync_menu.UbuntuOneSyncMenu, "change_sync_status", |
68 | 124 | self._change_sync_status) | 127 | self._change_sync_status) |
70 | 125 | self.sync_menu = sync_menu.UbuntuOneSyncMenu(self.main) | 128 | self.sync_menu = sync_menu.UbuntuOneSyncMenu(self.status_frontend, |
71 | 129 | self.syncdaemon_service) | ||
72 | 126 | 130 | ||
73 | 127 | def _change_sync_status(self, *args): | 131 | def _change_sync_status(self, *args): |
74 | 128 | """Fake change_sync_status.""" | 132 | """Fake change_sync_status.""" |
75 | @@ -338,3 +342,14 @@ | |||
76 | 338 | self.assertEqual(item.property_get_int( | 342 | self.assertEqual(item.property_get_int( |
77 | 339 | linux.SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE), | 343 | linux.SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE), |
78 | 340 | percentage) | 344 | percentage) |
79 | 345 | |||
80 | 346 | def test_update_transfers_delay(self): | ||
81 | 347 | """Check that the timer is being handle properly.""" | ||
82 | 348 | self.patch(linux.status.aggregator, "Timer", FakeTimer) | ||
83 | 349 | self.sync_menu.next_update = time.time() + 3 | ||
84 | 350 | self.sync_menu.update_transfers() | ||
85 | 351 | self.assertLess(self.sync_menu.timer.delay, 3) | ||
86 | 352 | self.sync_menu.timer = None | ||
87 | 353 | self.sync_menu.next_update = time.time() / 2 | ||
88 | 354 | self.sync_menu.update_transfers() | ||
89 | 355 | self.assertEqual(self.sync_menu.timer.delay, 0) | ||
90 | 341 | 356 | ||
91 | === modified file 'tests/status/test_aggregator.py' | |||
92 | --- tests/status/test_aggregator.py 2012-08-20 13:18:43 +0000 | |||
93 | +++ tests/status/test_aggregator.py 2012-09-26 20:23:20 +0000 | |||
94 | @@ -1314,6 +1314,21 @@ | |||
95 | 1314 | self.assertEqual({}, self.aggregator.to_do) | 1314 | self.assertEqual({}, self.aggregator.to_do) |
96 | 1315 | self.assertIdentical(None, self.aggregator.queue_done_timer) | 1315 | self.assertIdentical(None, self.aggregator.queue_done_timer) |
97 | 1316 | 1316 | ||
98 | 1317 | def test_register_progress_listener(self): | ||
99 | 1318 | """Check that register listener handles properly additions.""" | ||
100 | 1319 | |||
101 | 1320 | def fake_callback(): | ||
102 | 1321 | """Do nothing.""" | ||
103 | 1322 | |||
104 | 1323 | self.aggregator.register_progress_listener(fake_callback) | ||
105 | 1324 | self.assertEqual(len(self.aggregator.progress_listeners), 1) | ||
106 | 1325 | |||
107 | 1326 | def test_register_progress_listener_fail(self): | ||
108 | 1327 | """Check that register listener fails with not Callable objects.""" | ||
109 | 1328 | self.assertRaises(TypeError, | ||
110 | 1329 | self.aggregator.register_progress_listener, []) | ||
111 | 1330 | self.assertEqual(len(self.aggregator.progress_listeners), 0) | ||
112 | 1331 | |||
113 | 1317 | def assertMiscCommandQueued(self, fc): | 1332 | def assertMiscCommandQueued(self, fc): |
114 | 1318 | """Assert that some command was queued.""" | 1333 | """Assert that some command was queued.""" |
115 | 1319 | self.assertEqual(len(self.aggregator.to_do), 1) | 1334 | self.assertEqual(len(self.aggregator.to_do), 1) |
116 | 1320 | 1335 | ||
117 | === modified file 'tests/syncdaemon/test_main.py' | |||
118 | --- tests/syncdaemon/test_main.py 2012-09-19 17:23:02 +0000 | |||
119 | +++ tests/syncdaemon/test_main.py 2012-09-26 20:23:20 +0000 | |||
120 | @@ -70,19 +70,6 @@ | |||
121 | 70 | return defer.succeed(None) | 70 | return defer.succeed(None) |
122 | 71 | 71 | ||
123 | 72 | 72 | ||
124 | 73 | class FakedSyncMenu(object): | ||
125 | 74 | """Do nothing.""" | ||
126 | 75 | |||
127 | 76 | def __init__(self, *args, **kwargs): | ||
128 | 77 | self.arguments = (args, kwargs) | ||
129 | 78 | |||
130 | 79 | def update_progress(self): | ||
131 | 80 | """Do nothing.""" | ||
132 | 81 | |||
133 | 82 | def start_timer(self): | ||
134 | 83 | """Do nothing.""" | ||
135 | 84 | |||
136 | 85 | |||
137 | 86 | class MainTests(BaseTwistedTestCase): | 73 | class MainTests(BaseTwistedTestCase): |
138 | 87 | """ Basic tests to check main.Main """ | 74 | """ Basic tests to check main.Main """ |
139 | 88 | 75 | ||
140 | @@ -100,7 +87,6 @@ | |||
141 | 100 | self.patch(main_mod.event_logging, "get_listener", lambda *a: None) | 87 | self.patch(main_mod.event_logging, "get_listener", lambda *a: None) |
142 | 101 | # no status listener by default | 88 | # no status listener by default |
143 | 102 | self.patch(main_mod.status_listener, "get_listener", lambda *a: None) | 89 | self.patch(main_mod.status_listener, "get_listener", lambda *a: None) |
144 | 103 | self.patch(main_mod.sync_menu, "UbuntuOneSyncMenu", FakedSyncMenu) | ||
145 | 104 | 90 | ||
146 | 105 | self.handler = MementoHandler() | 91 | self.handler = MementoHandler() |
147 | 106 | self.handler.setLevel(logging.DEBUG) | 92 | self.handler.setLevel(logging.DEBUG) |
148 | 107 | 93 | ||
149 | === modified file 'tests/syncdaemon/test_status_listener.py' | |||
150 | --- tests/syncdaemon/test_status_listener.py 2012-04-09 20:07:05 +0000 | |||
151 | +++ tests/syncdaemon/test_status_listener.py 2012-09-26 20:23:20 +0000 | |||
152 | @@ -84,7 +84,7 @@ | |||
153 | 84 | callback(args) | 84 | callback(args) |
154 | 85 | 85 | ||
155 | 86 | listener = Listener() | 86 | listener = Listener() |
157 | 87 | setattr(listener, 'handle_'+event, listener._handle_event) | 87 | setattr(listener, 'handle_' + event, listener._handle_event) |
158 | 88 | event_q.subscribe(listener) | 88 | event_q.subscribe(listener) |
159 | 89 | return listener | 89 | return listener |
160 | 90 | 90 | ||
161 | @@ -92,7 +92,7 @@ | |||
162 | 92 | class FakeStatusFrontend(object): | 92 | class FakeStatusFrontend(object): |
163 | 93 | """A fake status frontend.""" | 93 | """A fake status frontend.""" |
164 | 94 | 94 | ||
166 | 95 | def __init__(self): | 95 | def __init__(self, *args, **kwargs): |
167 | 96 | """Initialize this instance.""" | 96 | """Initialize this instance.""" |
168 | 97 | self.call_log = [] | 97 | self.call_log = [] |
169 | 98 | 98 | ||
170 | 99 | 99 | ||
171 | === modified file 'ubuntuone/platform/sync_menu/common.py' | |||
172 | --- ubuntuone/platform/sync_menu/common.py 2012-09-18 16:29:22 +0000 | |||
173 | +++ ubuntuone/platform/sync_menu/common.py 2012-09-26 20:23:20 +0000 | |||
174 | @@ -31,13 +31,3 @@ | |||
175 | 31 | 31 | ||
176 | 32 | class UbuntuOneSyncMenu(object): | 32 | class UbuntuOneSyncMenu(object): |
177 | 33 | """Integrate U1 with the Ubuntu Sync Menu.""" | 33 | """Integrate U1 with the Ubuntu Sync Menu.""" |
178 | 34 | |||
179 | 35 | def __init__(self, *args): | ||
180 | 36 | self.transfers = DummyTransfersMenu() | ||
181 | 37 | |||
182 | 38 | |||
183 | 39 | class DummyTransfersMenu(object): | ||
184 | 40 | """Dummy Transfers Menu.""" | ||
185 | 41 | |||
186 | 42 | def start_timer(self): | ||
187 | 43 | """Empty start timer, this is not needed on windows.""" | ||
188 | 44 | 34 | ||
189 | === modified file 'ubuntuone/platform/sync_menu/linux.py' | |||
190 | --- ubuntuone/platform/sync_menu/linux.py 2012-09-24 12:47:05 +0000 | |||
191 | +++ ubuntuone/platform/sync_menu/linux.py 2012-09-26 20:23:20 +0000 | |||
192 | @@ -29,6 +29,8 @@ | |||
193 | 29 | """Use SyncMenu lib to integrate U1 with the Systray Sync Icon.""" | 29 | """Use SyncMenu lib to integrate U1 with the Systray Sync Icon.""" |
194 | 30 | 30 | ||
195 | 31 | import gettext | 31 | import gettext |
196 | 32 | import logging | ||
197 | 33 | import time | ||
198 | 32 | import sys | 34 | import sys |
199 | 33 | import webbrowser | 35 | import webbrowser |
200 | 34 | 36 | ||
201 | @@ -50,10 +52,12 @@ | |||
202 | 50 | use_syncmenu = True | 52 | use_syncmenu = True |
203 | 51 | except: | 53 | except: |
204 | 52 | use_syncmenu = False | 54 | use_syncmenu = False |
205 | 53 | from twisted.internet import reactor | ||
206 | 54 | 55 | ||
207 | 55 | from ubuntuone.clientdefs import GETTEXT_PACKAGE | 56 | from ubuntuone.clientdefs import GETTEXT_PACKAGE |
209 | 56 | 57 | from ubuntuone import status | |
210 | 58 | |||
211 | 59 | |||
212 | 60 | logger = logging.getLogger("ubuntuone.platform.SyncMenu") | ||
213 | 57 | 61 | ||
214 | 58 | Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string) | 62 | Q_ = lambda string: gettext.dgettext(GETTEXT_PACKAGE, string) |
215 | 59 | 63 | ||
216 | @@ -63,6 +67,7 @@ | |||
217 | 63 | MORE_STORAGE = Q_("Get More Space") | 67 | MORE_STORAGE = Q_("Get More Space") |
218 | 64 | GET_HELP = Q_("Get Help on the Web") | 68 | GET_HELP = Q_("Get Help on the Web") |
219 | 65 | 69 | ||
220 | 70 | DELAY_BETWEEN_UPDATES = 3 | ||
221 | 66 | UBUNTUONE_LINK = u'https://one.ubuntu.com/' | 71 | UBUNTUONE_LINK = u'https://one.ubuntu.com/' |
222 | 67 | DASHBOARD = UBUNTUONE_LINK + u'dashboard/' | 72 | DASHBOARD = UBUNTUONE_LINK + u'dashboard/' |
223 | 68 | HELP_LINK = UBUNTUONE_LINK + u'support/' | 73 | HELP_LINK = UBUNTUONE_LINK + u'support/' |
224 | @@ -72,11 +77,12 @@ | |||
225 | 72 | class UbuntuOneSyncMenuLinux(object): | 77 | class UbuntuOneSyncMenuLinux(object): |
226 | 73 | """Integrate U1 with the Ubuntu Sync Menu.""" | 78 | """Integrate U1 with the Ubuntu Sync Menu.""" |
227 | 74 | 79 | ||
229 | 75 | def __init__(self, main): | 80 | def __init__(self, status, syncdaemon_service): |
230 | 76 | """Initialize menu.""" | 81 | """Initialize menu.""" |
233 | 77 | self._main = main | 82 | self._syncdaemon_service = syncdaemon_service |
232 | 78 | self.status_listener = main.status_listener | ||
234 | 79 | self._paused = False | 83 | self._paused = False |
235 | 84 | self.timer = None | ||
236 | 85 | self.next_update = time.time() | ||
237 | 80 | self.root_menu = Dbusmenu.Menuitem() | 86 | self.root_menu = Dbusmenu.Menuitem() |
238 | 81 | 87 | ||
239 | 82 | self.open_u1 = Dbusmenu.Menuitem() | 88 | self.open_u1 = Dbusmenu.Menuitem() |
240 | @@ -86,7 +92,7 @@ | |||
241 | 86 | self.go_to_web.property_set(Dbusmenu.MENUITEM_PROP_LABEL, | 92 | self.go_to_web.property_set(Dbusmenu.MENUITEM_PROP_LABEL, |
242 | 87 | GO_TO_WEB) | 93 | GO_TO_WEB) |
243 | 88 | 94 | ||
245 | 89 | self.transfers = TransfersMenu(self.status_listener) | 95 | self.transfers = TransfersMenu(status) |
246 | 90 | self.transfers.property_set(Dbusmenu.MENUITEM_PROP_LABEL, | 96 | self.transfers.property_set(Dbusmenu.MENUITEM_PROP_LABEL, |
247 | 91 | TRANSFERS) | 97 | TRANSFERS) |
248 | 92 | 98 | ||
249 | @@ -121,17 +127,13 @@ | |||
250 | 121 | self.app.set_menu(self.server) | 127 | self.app.set_menu(self.server) |
251 | 122 | self.app.connect("notify::paused", self.change_sync_status) | 128 | self.app.connect("notify::paused", self.change_sync_status) |
252 | 123 | 129 | ||
253 | 124 | def start_timer(self): | ||
254 | 125 | """Start the transfers timer.""" | ||
255 | 126 | self.transfers.start_timer() | ||
256 | 127 | |||
257 | 128 | def change_sync_status(self, *args): | 130 | def change_sync_status(self, *args): |
258 | 129 | """Triggered when the sync status is changed fromm the menu.""" | 131 | """Triggered when the sync status is changed fromm the menu.""" |
259 | 130 | if self._paused: | 132 | if self._paused: |
261 | 131 | self._main.external.connect() | 133 | self._syncdaemon_service.connect() |
262 | 132 | self._paused = False | 134 | self._paused = False |
263 | 133 | else: | 135 | else: |
265 | 134 | self._main.external.disconnect() | 136 | self._syncdaemon_service.disconnect() |
266 | 135 | self._paused = True | 137 | self._paused = True |
267 | 136 | 138 | ||
268 | 137 | def open_control_panel(self, *args): | 139 | def open_control_panel(self, *args): |
269 | @@ -150,34 +152,45 @@ | |||
270 | 150 | """Open the Ubunto One Help Page""" | 152 | """Open the Ubunto One Help Page""" |
271 | 151 | webbrowser.open(GET_STORAGE_LINK) | 153 | webbrowser.open(GET_STORAGE_LINK) |
272 | 152 | 154 | ||
273 | 155 | def _timeout(self, result): | ||
274 | 156 | """The aggregating timer has expired, so update the UI.""" | ||
275 | 157 | self.next_update = int(time.time()) + DELAY_BETWEEN_UPDATES | ||
276 | 158 | self.transfers.update_progress() | ||
277 | 159 | self.timer = None | ||
278 | 160 | |||
279 | 161 | def update_transfers(self): | ||
280 | 162 | """Set up a timer if there isn't one ticking and update the ui.""" | ||
281 | 163 | if not self.timer: | ||
282 | 164 | logger.debug("Updating Transfers.") | ||
283 | 165 | delay = int(max(0, min(DELAY_BETWEEN_UPDATES, | ||
284 | 166 | self.next_update - time.time()))) | ||
285 | 167 | self.timer = status.aggregator.Timer(delay) | ||
286 | 168 | self.timer.addCallback(self._timeout) | ||
287 | 169 | |||
288 | 153 | 170 | ||
289 | 154 | class TransfersMenu(Dbusmenu.Menuitem): | 171 | class TransfersMenu(Dbusmenu.Menuitem): |
290 | 155 | """Menu that handles the recent and current transfers.""" | 172 | """Menu that handles the recent and current transfers.""" |
291 | 156 | 173 | ||
293 | 157 | def __init__(self, listener): | 174 | def __init__(self, status_frontend): |
294 | 158 | super(TransfersMenu, self).__init__() | 175 | super(TransfersMenu, self).__init__() |
296 | 159 | self.listener = listener | 176 | self.status_frontend = status_frontend |
297 | 160 | self.uploading = {} | 177 | self.uploading = {} |
298 | 161 | self.previous_transfers = [] | 178 | self.previous_transfers = [] |
299 | 162 | self._transfers_items = {} | 179 | self._transfers_items = {} |
300 | 163 | self._uploading_items = {} | 180 | self._uploading_items = {} |
301 | 164 | self.separator = None | 181 | self.separator = None |
302 | 165 | 182 | ||
303 | 166 | def start_timer(self): | ||
304 | 167 | """Trigger an update in one second.""" | ||
305 | 168 | self.update_progress() | ||
306 | 169 | reactor.callLater(3, self.start_timer) | ||
307 | 170 | |||
308 | 171 | def update_progress(self): | 183 | def update_progress(self): |
309 | 172 | """Update the list of recent transfers and current transfers.""" | 184 | """Update the list of recent transfers and current transfers.""" |
311 | 173 | current_transfers = self.listener.status_frontend.recent_transfers() | 185 | current_transfers = self.status_frontend.recent_transfers() |
312 | 174 | uploading_data = {} | 186 | uploading_data = {} |
313 | 175 | for filename, size, written in \ | 187 | for filename, size, written in \ |
315 | 176 | self.listener.status_frontend.files_uploading(): | 188 | self.status_frontend.files_uploading(): |
316 | 177 | uploading_data[filename] = (size, written) | 189 | uploading_data[filename] = (size, written) |
317 | 178 | 190 | ||
318 | 179 | temp_transfers = {} | 191 | temp_transfers = {} |
319 | 180 | if current_transfers != self.previous_transfers: | 192 | if current_transfers != self.previous_transfers: |
320 | 193 | logger.debug("Update recent transfers with: %r", current_transfers) | ||
321 | 181 | for item_transfer in self._transfers_items: | 194 | for item_transfer in self._transfers_items: |
322 | 182 | self.child_delete(self._transfers_items[item_transfer]) | 195 | self.child_delete(self._transfers_items[item_transfer]) |
323 | 183 | for item in current_transfers: | 196 | for item in current_transfers: |
324 | @@ -204,6 +217,8 @@ | |||
325 | 204 | upload_item.property_set_int( | 217 | upload_item.property_set_int( |
326 | 205 | SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE, | 218 | SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE, |
327 | 206 | percentage) | 219 | percentage) |
328 | 220 | logger.debug("Current transfer %s progress update: %r", | ||
329 | 221 | item, percentage) | ||
330 | 207 | items_added += 1 | 222 | items_added += 1 |
331 | 208 | else: | 223 | else: |
332 | 209 | self.child_delete(self._uploading_items[item]) | 224 | self.child_delete(self._uploading_items[item]) |
333 | @@ -223,6 +238,7 @@ | |||
334 | 223 | uploading_file.property_set_int( | 238 | uploading_file.property_set_int( |
335 | 224 | SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE, | 239 | SyncMenu.PROGRESS_MENUITEM_PROP_PERCENT_DONE, |
336 | 225 | percentage) | 240 | percentage) |
337 | 241 | logger.debug("Current transfer %s created", item) | ||
338 | 226 | self.child_append(uploading_file) | 242 | self.child_append(uploading_file) |
339 | 227 | self._uploading_items[item] = uploading_file | 243 | self._uploading_items[item] = uploading_file |
340 | 228 | items_added += 1 | 244 | items_added += 1 |
341 | @@ -234,8 +250,7 @@ | |||
342 | 234 | def __init__(self, *args, **kwargs): | 250 | def __init__(self, *args, **kwargs): |
343 | 235 | """Initialize menu.""" | 251 | """Initialize menu.""" |
344 | 236 | 252 | ||
346 | 237 | def start_timer(self): | 253 | def update_transfers(self): |
347 | 238 | """Do nothing.""" | 254 | """Do nothing.""" |
348 | 239 | 255 | ||
349 | 240 | |||
350 | 241 | UbuntuOneSyncMenu = UbuntuOneSyncMenuLinux if use_syncmenu else DummySyncMenu | 256 | UbuntuOneSyncMenu = UbuntuOneSyncMenuLinux if use_syncmenu else DummySyncMenu |
351 | 242 | 257 | ||
352 | === modified file 'ubuntuone/status/aggregator.py' | |||
353 | --- ubuntuone/status/aggregator.py 2012-08-16 12:00:12 +0000 | |||
354 | +++ ubuntuone/status/aggregator.py 2012-09-26 20:23:20 +0000 | |||
355 | @@ -33,7 +33,7 @@ | |||
356 | 33 | import itertools | 33 | import itertools |
357 | 34 | import operator | 34 | import operator |
358 | 35 | import os | 35 | import os |
360 | 36 | from collections import deque | 36 | from collections import deque, Callable |
361 | 37 | 37 | ||
362 | 38 | import gettext | 38 | import gettext |
363 | 39 | 39 | ||
364 | @@ -41,7 +41,11 @@ | |||
365 | 41 | 41 | ||
366 | 42 | from ubuntuone.clientdefs import GETTEXT_PACKAGE | 42 | from ubuntuone.clientdefs import GETTEXT_PACKAGE |
367 | 43 | from ubuntuone.status.logger import logger | 43 | from ubuntuone.status.logger import logger |
369 | 44 | from ubuntuone.platform import session, notification | 44 | from ubuntuone.platform import ( |
370 | 45 | notification, | ||
371 | 46 | session, | ||
372 | 47 | sync_menu | ||
373 | 48 | ) | ||
374 | 45 | from ubuntuone.platform.messaging import Messaging | 49 | from ubuntuone.platform.messaging import Messaging |
375 | 46 | from ubuntuone.platform.launcher import UbuntuOneLauncher, DummyLauncher | 50 | from ubuntuone.platform.launcher import UbuntuOneLauncher, DummyLauncher |
376 | 47 | 51 | ||
377 | @@ -625,6 +629,7 @@ | |||
378 | 625 | self.progress = {} | 629 | self.progress = {} |
379 | 626 | self.to_do = {} | 630 | self.to_do = {} |
380 | 627 | self.recent_transfers = deque(maxlen=5) | 631 | self.recent_transfers = deque(maxlen=5) |
381 | 632 | self.progress_listeners = [] | ||
382 | 628 | 633 | ||
383 | 629 | def get_notification(self): | 634 | def get_notification(self): |
384 | 630 | """Create a new toggleable notification object.""" | 635 | """Create a new toggleable notification object.""" |
385 | @@ -655,6 +660,13 @@ | |||
386 | 655 | self.to_do = {} | 660 | self.to_do = {} |
387 | 656 | # pylint: enable=W0201 | 661 | # pylint: enable=W0201 |
388 | 657 | 662 | ||
389 | 663 | def register_progress_listener(self, listener): | ||
390 | 664 | """Register a callable object to be notified.""" | ||
391 | 665 | if isinstance(listener, Callable): | ||
392 | 666 | self.progress_listeners.append(listener) | ||
393 | 667 | else: | ||
394 | 668 | raise TypeError("Callable object expected.") | ||
395 | 669 | |||
396 | 658 | def get_discovery_message(self): | 670 | def get_discovery_message(self): |
397 | 659 | """Get the text for the discovery bubble.""" | 671 | """Get the text for the discovery bubble.""" |
398 | 660 | lines = [] | 672 | lines = [] |
399 | @@ -716,6 +728,8 @@ | |||
400 | 716 | progress = float( | 728 | progress = float( |
401 | 717 | sum(self.progress.values())) / sum(self.to_do.values()) | 729 | sum(self.progress.values())) / sum(self.to_do.values()) |
402 | 718 | self.progress_bar.set_progress(progress) | 730 | self.progress_bar.set_progress(progress) |
403 | 731 | for listener in self.progress_listeners: | ||
404 | 732 | listener() | ||
405 | 719 | 733 | ||
406 | 720 | def download_started(self, command): | 734 | def download_started(self, command): |
407 | 721 | """A download just started.""" | 735 | """A download just started.""" |
408 | @@ -801,13 +815,25 @@ | |||
409 | 801 | class StatusFrontend(object): | 815 | class StatusFrontend(object): |
410 | 802 | """Frontend for the status aggregator, used by the StatusListener.""" | 816 | """Frontend for the status aggregator, used by the StatusListener.""" |
411 | 803 | 817 | ||
413 | 804 | def __init__(self, clock=reactor): | 818 | def __init__(self, clock=reactor, service=None): |
414 | 805 | """Initialize this instance.""" | 819 | """Initialize this instance.""" |
415 | 806 | self.aggregator = StatusAggregator(clock=clock) | 820 | self.aggregator = StatusAggregator(clock=clock) |
416 | 807 | self.notification = self.aggregator.get_notification() | 821 | self.notification = self.aggregator.get_notification() |
417 | 808 | self.messaging = Messaging() | 822 | self.messaging = Messaging() |
418 | 809 | self.quota_timer = None | 823 | self.quota_timer = None |
419 | 810 | 824 | ||
420 | 825 | self.syncdaemon_service = service | ||
421 | 826 | self.sync_menu = None | ||
422 | 827 | self.start_sync_menu() | ||
423 | 828 | |||
424 | 829 | def start_sync_menu(self): | ||
425 | 830 | """Create the sync menu and register the progress listener.""" | ||
426 | 831 | if self.syncdaemon_service is not None: | ||
427 | 832 | self.sync_menu = sync_menu.UbuntuOneSyncMenu(self, | ||
428 | 833 | self.syncdaemon_service) | ||
429 | 834 | self.aggregator.register_progress_listener( | ||
430 | 835 | self.sync_menu.update_transfers) | ||
431 | 836 | |||
432 | 811 | def recent_transfers(self): | 837 | def recent_transfers(self): |
433 | 812 | """Return a tuple with the recent transfers paths.""" | 838 | """Return a tuple with the recent transfers paths.""" |
434 | 813 | return list(self.aggregator.recent_transfers) | 839 | return list(self.aggregator.recent_transfers) |
435 | 814 | 840 | ||
436 | === modified file 'ubuntuone/syncdaemon/main.py' | |||
437 | --- ubuntuone/syncdaemon/main.py 2012-09-19 17:23:02 +0000 | |||
438 | +++ ubuntuone/syncdaemon/main.py 2012-09-26 20:23:20 +0000 | |||
439 | @@ -48,10 +48,7 @@ | |||
440 | 48 | volume_manager, | 48 | volume_manager, |
441 | 49 | ) | 49 | ) |
442 | 50 | from ubuntuone import syncdaemon, clientdefs | 50 | from ubuntuone import syncdaemon, clientdefs |
447 | 51 | from ubuntuone.platform import ( | 51 | from ubuntuone.platform import event_logging |
444 | 52 | event_logging, | ||
445 | 53 | sync_menu, | ||
446 | 54 | ) | ||
448 | 55 | from ubuntuone.syncdaemon import status_listener | 52 | from ubuntuone.syncdaemon import status_listener |
449 | 56 | from ubuntuone.syncdaemon.interaction_interfaces import SyncdaemonService | 53 | from ubuntuone.syncdaemon.interaction_interfaces import SyncdaemonService |
450 | 57 | from ubuntuone.syncdaemon.states import StateManager, QueueManager | 54 | from ubuntuone.syncdaemon.states import StateManager, QueueManager |
451 | @@ -159,14 +156,6 @@ | |||
452 | 159 | self.mark = task.LoopingCall(self.log_mark) | 156 | self.mark = task.LoopingCall(self.log_mark) |
453 | 160 | self.mark.start(mark_interval) | 157 | self.mark.start(mark_interval) |
454 | 161 | 158 | ||
455 | 162 | self.sync_menu = None | ||
456 | 163 | self.start_sync_menu() | ||
457 | 164 | |||
458 | 165 | def start_sync_menu(self): | ||
459 | 166 | """Create the sync menu and run the loop.""" | ||
460 | 167 | self.sync_menu = sync_menu.UbuntuOneSyncMenu(self) | ||
461 | 168 | self.sync_menu.start_timer() | ||
462 | 169 | |||
463 | 170 | def start_event_logger(self): | 159 | def start_event_logger(self): |
464 | 171 | """Start the event logger if it's available for this platform.""" | 160 | """Start the event logger if it's available for this platform.""" |
465 | 172 | self.eventlog_listener = event_logging.get_listener(self.fs, self.vm) | 161 | self.eventlog_listener = event_logging.get_listener(self.fs, self.vm) |
466 | @@ -176,7 +165,8 @@ | |||
467 | 176 | 165 | ||
468 | 177 | def start_status_listener(self): | 166 | def start_status_listener(self): |
469 | 178 | """Start the status listener if it is configured to start.""" | 167 | """Start the status listener if it is configured to start.""" |
471 | 179 | self.status_listener = status_listener.get_listener(self.fs, self.vm) | 168 | self.status_listener = status_listener.get_listener(self.fs, self.vm, |
472 | 169 | self.external) | ||
473 | 180 | # subscribe to EQ, to be unsubscribed in shutdown | 170 | # subscribe to EQ, to be unsubscribed in shutdown |
474 | 181 | if self.status_listener: | 171 | if self.status_listener: |
475 | 182 | self.event_q.subscribe(self.status_listener) | 172 | self.event_q.subscribe(self.status_listener) |
476 | 183 | 173 | ||
477 | === modified file 'ubuntuone/syncdaemon/status_listener.py' | |||
478 | --- ubuntuone/syncdaemon/status_listener.py 2012-08-10 12:49:46 +0000 | |||
479 | +++ ubuntuone/syncdaemon/status_listener.py 2012-09-26 20:23:20 +0000 | |||
480 | @@ -48,10 +48,10 @@ | |||
481 | 48 | return True | 48 | return True |
482 | 49 | 49 | ||
483 | 50 | 50 | ||
485 | 51 | def get_listener(fsm, vm): | 51 | def get_listener(fsm, vm, syncdaemon_service=None): |
486 | 52 | """Return an instance of the status listener, or None if turned off.""" | 52 | """Return an instance of the status listener, or None if turned off.""" |
487 | 53 | if should_start_listener(): | 53 | if should_start_listener(): |
489 | 54 | status_frontend = StatusFrontend() | 54 | status_frontend = StatusFrontend(service=syncdaemon_service) |
490 | 55 | return StatusListener(fsm, vm, status_frontend) | 55 | return StatusListener(fsm, vm, status_frontend) |
491 | 56 | else: | 56 | else: |
492 | 57 | return None | 57 | return None |
This branch is wrong: it keeps using cpu while syncdaemon is idle.