Merge lp:~alecu/ubuntuone-client/aggregator-fixes into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 860
Merged at revision: 867
Proposed branch: lp:~alecu/ubuntuone-client/aggregator-fixes
Merge into: lp:ubuntuone-client
Diff against target: 435 lines (+209/-32)
10 files modified
contrib/testing/testcase.py (+7/-0)
data/syncdaemon.conf (+7/-0)
tests/platform/linux/test_dbus.py (+55/-0)
tests/status/test_aggregator.py (+3/-1)
tests/syncdaemon/test_config.py (+48/-0)
tests/syncdaemon/test_status_listener.py (+30/-4)
ubuntuone/platform/linux/dbus_interface.py (+28/-3)
ubuntuone/status/aggregator.py (+3/-22)
ubuntuone/syncdaemon/config.py (+11/-1)
ubuntuone/syncdaemon/status_listener.py (+17/-1)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/aggregator-fixes
Reviewer Review Type Date Requested Status
Martin Albisetti (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+49806@code.launchpad.net

Commit message

Add a config/dbus option to disable notification bubbles (part I)

Description of the change

Add a config/dbus option to disable notification bubbles (part I)

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

great!

review: Approve
Revision history for this message
Martin Albisetti (beuno) :
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 2011-02-08 18:38:31 +0000
3+++ contrib/testing/testcase.py 2011-02-15 13:50:18 +0000
4@@ -170,6 +170,12 @@
5 node_is_with_queued_move = cleanup = get_public_files = disconnect
6
7
8+class FakeStatusListener(object):
9+ """A fake StatusListener."""
10+
11+ show_all_notifications = True
12+
13+
14 class FakeMain(main.Main):
15 """ A fake Main class to setup the tests """
16
17@@ -205,6 +211,7 @@
18 self.external = FakeExternalInterface()
19 self.lr = local_rescan.LocalRescan(self.vm, self.fs,
20 self.event_q, self.action_q)
21+ self.status_listener = FakeStatusListener()
22
23 def _connect_aq(self, _):
24 """Connect the fake action queue."""
25
26=== modified file 'data/syncdaemon.conf'
27--- data/syncdaemon.conf 2011-02-01 14:33:46 +0000
28+++ data/syncdaemon.conf 2011-02-15 13:50:18 +0000
29@@ -85,6 +85,13 @@
30 \A\..*\.tmp\Z
31
32
33+[notifications]
34+show_all_notifications.default = True
35+show_all_notifications.parser = bool
36+show_all_notifications.action = store_true
37+show_all_notifications.help = Show all bubble notifications
38+
39+
40 [bandwidth_throttling]
41 on.default = False
42 on.parser = bool
43
44=== modified file 'tests/platform/linux/test_dbus.py'
45--- tests/platform/linux/test_dbus.py 2011-02-10 11:28:49 +0000
46+++ tests/platform/linux/test_dbus.py 2011-02-15 13:50:18 +0000
47@@ -2570,6 +2570,61 @@
48 error_handler=self.error_handler)
49 return d
50
51+ def test_show_all_notifications_enabled(self):
52+ """Test for Config.show_all_notifications_enabled."""
53+ client = self.get_client()
54+ d = defer.Deferred()
55+
56+ def reply_handler_disabled(result):
57+ """Handle the reply."""
58+ self.assertTrue(result)
59+ config.get_user_config().set_show_all_notifications(not result)
60+ client.call_method('show_all_notifications_enabled',
61+ reply_handler=reply_handler_enabled,
62+ error_handler=self.error_handler)
63+
64+ def reply_handler_enabled(result):
65+ """Handle the reply."""
66+ self.assertFalse(result)
67+ d.callback(True)
68+
69+ client.call_method('show_all_notifications_enabled',
70+ reply_handler=reply_handler_disabled,
71+ error_handler=self.error_handler)
72+ return d
73+
74+ def test_enable_show_all_notifications(self):
75+ """Test for Config.enable_show_all_notifications."""
76+ client = self.get_client()
77+ d = defer.Deferred()
78+ self.main.status_listener.show_all_notifications = False
79+ def reply_handler(_):
80+ """Handle the reply."""
81+ user_config = config.get_user_config()
82+ self.assertTrue(user_config.get_show_all_notifications())
83+ self.assertTrue(self.main.status_listener.show_all_notifications)
84+ d.callback(True)
85+ client.call_method('enable_show_all_notifications',
86+ reply_handler=reply_handler,
87+ error_handler=self.error_handler)
88+ return d
89+
90+ def test_disable_show_all_notifications(self):
91+ """Test for Config.disable_show_all_notifications."""
92+ client = self.get_client()
93+ d = defer.Deferred()
94+ self.main.status_listener.show_all_notifications = True
95+ def reply_handler(_):
96+ """Handle the reply."""
97+ user_config = config.get_user_config()
98+ self.assertFalse(user_config.get_show_all_notifications())
99+ self.assertFalse(self.main.status_listener.show_all_notifications)
100+ d.callback(True)
101+ client.call_method('disable_show_all_notifications',
102+ reply_handler=reply_handler,
103+ error_handler=self.error_handler)
104+ return d
105+
106
107 class DBusOAuthTestCase(BaseTwistedTestCase):
108 """Tests the interaction between dbus_interface and credentials.
109
110=== modified file 'tests/status/test_aggregator.py'
111--- tests/status/test_aggregator.py 2011-02-10 17:47:02 +0000
112+++ tests/status/test_aggregator.py 2011-02-15 13:50:18 +0000
113@@ -22,6 +22,7 @@
114 from twisted.internet.task import Clock
115 from twisted.trial.unittest import TestCase
116
117+from contrib.testing.testcase import BaseTwistedTestCase
118 from ubuntuone.devtools.handlers import MementoHandler
119 from ubuntuone.status import aggregator
120 from ubuntuone.status.notification import AbstractNotification
121@@ -629,11 +630,12 @@
122 upload_finished = misc_command_unqueued
123
124
125-class StatusFrontendTestCase(TestCase):
126+class StatusFrontendTestCase(BaseTwistedTestCase):
127 """Test the status frontend."""
128
129 def setUp(self):
130 """Initialize this test instance."""
131+ BaseTwistedTestCase.setUp(self)
132 self.patch(aggregator, "StatusAggregator", FakeAggregator)
133 self.patch(aggregator, "Notification", FakeNotificationSingleton())
134 self.patch(aggregator, "Messaging", FakeMessaging)
135
136=== modified file 'tests/syncdaemon/test_config.py'
137--- tests/syncdaemon/test_config.py 2011-02-08 18:38:31 +0000
138+++ tests/syncdaemon/test_config.py 2011-02-15 13:50:18 +0000
139@@ -372,6 +372,54 @@
140 conf_1 = config._Config(conf_file)
141 self.assertEquals(True, conf_1.get_autoconnect())
142
143+ def test_load_show_all_notifications(self):
144+ """Test load/set/override of show_all_notifications config value."""
145+ conf_file = os.path.join(self.test_root,
146+ 'test_show_all_notifications_config.conf')
147+ # ensure that show_all_notifications is True
148+ with open(conf_file, 'w') as fp:
149+ fp.write('[notifications]\n')
150+ fp.write('show_all_notifications = True\n')
151+
152+ # keep a original around
153+ conf_orig = config._Config(conf_file)
154+
155+ # assert default is correct
156+ self.assertTrue(conf_orig.get_show_all_notifications(),
157+ 'show_all_notifications is True by default.')
158+
159+ # load the config
160+ conf = config._Config(conf_file)
161+ self.assertTrue(conf.get_show_all_notifications())
162+
163+ # change it to False
164+ conf.set_show_all_notifications(False)
165+ self.assertFalse(conf.get_show_all_notifications())
166+
167+ # save, load and check
168+ conf.save()
169+ conf_1 = config._Config(conf_file)
170+ self.assertFalse(conf_1.get_show_all_notifications())
171+ # change it to True
172+ conf.set_show_all_notifications(True)
173+ self.assertTrue(conf.get_show_all_notifications())
174+ # save, load and check
175+ conf.save()
176+ conf_1 = config._Config(conf_file)
177+ self.assertTrue(conf_1.get_show_all_notifications())
178+
179+ # load the config, check the override of the value
180+ conf = config._Config(conf_file)
181+ self.assertTrue(conf.get_show_all_notifications())
182+ overridden_opts = [('notifications', 'show_all_notifications', False)]
183+ conf.override_options(overridden_opts)
184+ self.assertFalse(conf.get_show_all_notifications())
185+ self.assertNotEqual(conf.get_show_all_notifications(),
186+ conf_orig.get_show_all_notifications())
187+ conf.save()
188+ conf_1 = config._Config(conf_file)
189+ self.assertEquals(True, conf_1.get_show_all_notifications())
190+
191
192 class ConfigglueParsersTests(BaseTwistedTestCase):
193 """Tests for our custom configglue parsers"""
194
195=== modified file 'tests/syncdaemon/test_status_listener.py'
196--- tests/syncdaemon/test_status_listener.py 2011-02-08 20:09:46 +0000
197+++ tests/syncdaemon/test_status_listener.py 2011-02-15 13:50:18 +0000
198@@ -20,19 +20,19 @@
199 import os
200
201 from twisted.internet import defer
202-from twisted.trial.unittest import TestCase
203
204-from contrib.testing.testcase import FakeMainTestCase
205-from ubuntuone.syncdaemon import status_listener
206+from contrib.testing.testcase import FakeMainTestCase, BaseTwistedTestCase
207+from ubuntuone.syncdaemon import config, status_listener
208 from ubuntuone.syncdaemon.volume_manager import Share, UDF
209
210
211-class GetListenerTestCase(TestCase):
212+class GetListenerTestCase(BaseTwistedTestCase):
213 """The status listener is created."""
214
215 def test_returns_listener(self):
216 """get_listener returns a listener if status reporting is enabled."""
217 self.patch(status_listener, "should_start_listener", lambda: True)
218+ self.patch(status_listener, "StatusFrontend", FakeStatusFrontend)
219 fsm = object()
220 vm = object()
221 listener = status_listener.get_listener(fsm, vm)
222@@ -108,6 +108,32 @@
223 return listen_for(self.main.event_q, *args, **kwargs)
224
225
226+class StatusListenerConfigTestCase(StatusListenerTestCase):
227+ """Test the config of the status listener."""
228+
229+ def test_show_all_notifications_calls_frontend(self):
230+ """Changes in the value of notifications are sent to the frontend."""
231+ self.listener.show_all_notifications = True
232+ call = ("set_show_all_notifications", (True,), {})
233+ self.assertIn(call, self.status_frontend.call_log)
234+
235+ def test_show_all_notifications_true(self):
236+ """The value of show_all_notifications is set to True."""
237+ user_conf = config.get_user_config()
238+ user_conf.set_show_all_notifications(True)
239+ listener = status_listener.StatusListener(None, None,
240+ self.status_frontend)
241+ self.assertTrue(listener.show_all_notifications)
242+
243+ def test_show_all_notifications_false(self):
244+ """The value of show_all_notifications is set to False."""
245+ user_conf = config.get_user_config()
246+ user_conf.set_show_all_notifications(False)
247+ listener = status_listener.StatusListener(None, None,
248+ self.status_frontend)
249+ self.assertFalse(listener.show_all_notifications)
250+
251+
252 class PublicFilesStatusTestCase(StatusListenerTestCase):
253 """Public files events are passed to the status object."""
254
255
256=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
257--- ubuntuone/platform/linux/dbus_interface.py 2011-02-10 11:28:49 +0000
258+++ ubuntuone/platform/linux/dbus_interface.py 2011-02-15 13:50:18 +0000
259@@ -1445,7 +1445,7 @@
260 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
261 in_signature='', out_signature='')
262 def disable_udf_autosubscribe(self):
263- """Enable UDF autosubscribe."""
264+ """Disable UDF autosubscribe."""
265 user_config = config.get_user_config()
266 user_config.set_udf_autosubscribe(False)
267 user_config.save()
268@@ -1459,7 +1459,7 @@
269 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
270 in_signature='', out_signature='')
271 def enable_share_autosubscribe(self):
272- """Enable UDF autosubscribe."""
273+ """Enable share autosubscribe."""
274 user_config = config.get_user_config()
275 user_config.set_share_autosubscribe(True)
276 user_config.save()
277@@ -1467,7 +1467,7 @@
278 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
279 in_signature='', out_signature='')
280 def disable_share_autosubscribe(self):
281- """Enable UDF autosubscribe."""
282+ """Disable share autosubscribe."""
283 user_config = config.get_user_config()
284 user_config.set_share_autosubscribe(False)
285 user_config.save()
286@@ -1502,6 +1502,31 @@
287 user_config.set_autoconnect(enabled)
288 user_config.save()
289
290+ @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
291+ in_signature='', out_signature='b')
292+ def show_all_notifications_enabled(self):
293+ """Return the show_all_notifications config value."""
294+
295+ return config.get_user_config().get_show_all_notifications()
296+
297+ @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
298+ in_signature='', out_signature='')
299+ def enable_show_all_notifications(self):
300+ """Enable showing all notifications."""
301+ user_config = config.get_user_config()
302+ user_config.set_show_all_notifications(True)
303+ user_config.save()
304+ self.dbus_iface.main.status_listener.show_all_notifications = True
305+
306+ @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
307+ in_signature='', out_signature='')
308+ def disable_show_all_notifications(self):
309+ """Disable showing all notifications."""
310+ user_config = config.get_user_config()
311+ user_config.set_show_all_notifications(False)
312+ user_config.save()
313+ self.dbus_iface.main.status_listener.show_all_notifications = False
314+
315
316 class Folders(DBusExposedObject):
317 """A dbus interface to interact with User Defined Folders"""
318
319=== modified file 'ubuntuone/status/aggregator.py'
320--- ubuntuone/status/aggregator.py 2011-02-10 17:47:02 +0000
321+++ ubuntuone/status/aggregator.py 2011-02-15 13:50:18 +0000
322@@ -550,28 +550,6 @@
323 self.progress_bar.completed()
324 self.reset()
325
326- def no_callback(self, status_events):
327- """Pushed a bunch of events by the buffer."""
328-
329- lines = []
330-
331- if self.show_progress:
332- lines.append(self.get_progress_message())
333-
334- for weight, statuses in group_statuses(status_events):
335- statuses = list(statuses)
336- count = len(statuses)
337- first_status = statuses[0]
338- if count == 1:
339- lines.append(first_status.one())
340- else:
341- lines.append(first_status.many(count))
342-
343- text = "\n".join(lines)
344- self.notification.send_notification(UBUNTUONE_TITLE, text)
345- logger.debug("notification shown: %s", text)
346- self.show_progress = False
347-
348 def misc_command_queued(self, command):
349 """A miscellaneous command was queued."""
350 self.total_counter += 1
351@@ -700,3 +678,6 @@
352 logger.debug("server connection made")
353 self.notification.send_notification(
354 UBUNTUONE_TITLE, ConnectionMadeStatus().one())
355+
356+ def set_show_all_notifications(self, value):
357+ """Set the flag to show all notifications."""
358
359=== modified file 'ubuntuone/syncdaemon/config.py'
360--- ubuntuone/syncdaemon/config.py 2011-02-07 19:19:50 +0000
361+++ ubuntuone/syncdaemon/config.py 2011-02-15 13:50:18 +0000
362@@ -62,6 +62,7 @@
363
364 # sections
365 THROTTLING = 'bandwidth_throttling'
366+NOTIFICATIONS = 'notifications'
367 MAIN = '__main__'
368
369 # global logger
370@@ -271,7 +272,7 @@
371 def save(self):
372 """Save the config object to disk"""
373 # cleanup empty sections
374- for section in [MAIN, THROTTLING]:
375+ for section in [MAIN, THROTTLING, NOTIFICATIONS]:
376 if self.has_section(section) and not self.options(section):
377 self.remove_section(section)
378 with open(self.config_file+'.new', 'w') as fp:
379@@ -364,6 +365,15 @@
380 def get_autoconnect(self):
381 return self.get_parsed(MAIN, 'autoconnect')
382
383+ @requires_section(NOTIFICATIONS)
384+ def set_show_all_notifications(self, enabled):
385+ self.set(NOTIFICATIONS, 'show_all_notifications', str(enabled))
386+
387+ @requires_section(NOTIFICATIONS)
388+ def get_show_all_notifications(self):
389+ """The value of the show_all_notifications setting."""
390+ return self.get_parsed(NOTIFICATIONS, 'show_all_notifications')
391+
392
393
394 def configglue(fileobj, *filenames, **kwargs):
395
396=== modified file 'ubuntuone/syncdaemon/status_listener.py'
397--- ubuntuone/syncdaemon/status_listener.py 2011-02-08 20:09:46 +0000
398+++ ubuntuone/syncdaemon/status_listener.py 2011-02-15 13:50:18 +0000
399@@ -18,7 +18,7 @@
400 """Listener for event queue that updates the UI to show syncdaemon status."""
401
402 from ubuntuone.status.aggregator import StatusFrontend
403-from ubuntuone.syncdaemon import action_queue
404+from ubuntuone.syncdaemon import action_queue, config
405
406 def should_start_listener():
407 """Check if the status listener should be started."""
408@@ -37,11 +37,27 @@
409 class StatusListener(object):
410 """SD listener for EQ events that turns them into status updates."""
411
412+ _show_all_notifications = True
413+
414 def __init__(self, fsm, vm, status_frontend):
415 """Initialize this instance with the FSM and VM."""
416 self.fsm = fsm
417 self.vm = vm
418 self.status_frontend = status_frontend
419+ user_conf = config.get_user_config()
420+ self.show_all_notifications = user_conf.get_show_all_notifications()
421+
422+ def get_show_all_notifications(self):
423+ """Get the value of show_all_notifications."""
424+ return self._show_all_notifications
425+
426+ def set_show_all_notifications(self, value):
427+ """Set the value of show_all_notifications."""
428+ self._show_all_notifications = value
429+ self.status_frontend.set_show_all_notifications(value)
430+
431+ show_all_notifications = property(get_show_all_notifications,
432+ set_show_all_notifications)
433
434 def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
435 public_url):

Subscribers

People subscribed via source and target branches