Merge lp:~nataliabidart/ubuntuone-client/extend-sdtool into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Tim Cole
Approved revision: 1009
Merged at revision: 1003
Proposed branch: lp:~nataliabidart/ubuntuone-client/extend-sdtool
Merge into: lp:ubuntuone-client
Diff against target: 778 lines (+285/-79)
15 files modified
contrib/testing/testcase.py (+2/-2)
tests/platform/linux/__init__.py (+16/-0)
tests/platform/linux/eventlog/test_zg_listener.py (+1/-0)
tests/platform/linux/eventlog/test_zglog.py (+1/-0)
tests/platform/linux/test_config.py (+17/-0)
tests/platform/linux/test_credentials.py (+11/-9)
tests/platform/linux/test_dbus.py (+42/-11)
tests/platform/linux/test_os_helper.py (+1/-0)
tests/platform/linux/test_session.py (+7/-4)
tests/platform/linux/test_tools.py (+79/-8)
ubuntuone/platform/linux/dbus_interface.py (+31/-3)
ubuntuone/platform/linux/tools.py (+55/-38)
ubuntuone/syncdaemon/event_queue.py (+5/-0)
ubuntuone/syncdaemon/main.py (+16/-4)
ubuntuone/syncdaemon/states.py (+1/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/extend-sdtool
Reviewer Review Type Date Requested Status
Tim Cole (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+64749@code.launchpad.net

Commit message

- Implemented methods to extend SyncDaemonTool and then provide settings management for autoconnect and share/udf autosubscribe (LP: #797411).

To post a comment you must log in.
1006. By Natalia Bidart

Restore the cleanup of shares_dir.

1007. By Natalia Bidart

Removed print statements.

1008. By Natalia Bidart

Reverting test_zglog.py changes.

1009. By Natalia Bidart

Adding deprecation warnings to DBus deprecated methods/signals.

Revision history for this message
Eric Casteleijn (thisfred) wrote :

I like the the settings refactoring! Code looks good, tests pass.

review: Approve
Revision history for this message
Tim Cole (tcole) wrote :

Looks great!

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-06-15 14:46:04 +0000
3+++ contrib/testing/testcase.py 2011-06-15 21:34:36 +0000
4@@ -310,7 +310,7 @@
5 os.makedirs(path)
6
7 def setUp(self):
8- TwistedTestCase.setUp(self)
9+ super(BaseTwistedTestCase, self).setUp()
10 # use the config from the branch
11 self.old_get_config_files = config.get_config_files
12 config.get_config_files = lambda: [os.path.join(os.environ['ROOTDIR'],
13@@ -336,7 +336,7 @@
14 root_dir = getattr(self, '__root', None)
15 if root_dir:
16 self.rmtree(self.__root)
17- return TwistedTestCase.tearDown(self)
18+ return super(BaseTwistedTestCase, self).tearDown()
19
20
21 class FakeMainTestCase(BaseTwistedTestCase):
22
23=== modified file 'tests/platform/linux/__init__.py'
24--- tests/platform/linux/__init__.py 2011-02-08 12:04:21 +0000
25+++ tests/platform/linux/__init__.py 2011-06-15 21:34:36 +0000
26@@ -1,6 +1,21 @@
27+# Copyright 2011 Canonical Ltd.
28+#
29+# This program is free software: you can redistribute it and/or modify it
30+# under the terms of the GNU General Public License version 3, as published
31+# by the Free Software Foundation.
32+#
33+# This program is distributed in the hope that it will be useful, but
34+# WITHOUT ANY WARRANTY; without even the implied warranties of
35+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
36+# PURPOSE. See the GNU General Public License for more details.
37+#
38+# You should have received a copy of the GNU General Public License along
39+# with this program. If not, see <http://www.gnu.org/licenses/>.
40+
41 """Linux test code."""
42
43
44+
45 def _setup_service_busname(testcase):
46 # monkeypatch __del__ to avoid issues with gc
47 import dbus
48@@ -10,6 +25,7 @@
49
50 setup_main_test = _setup_service_busname
51
52+
53 def get_main_params(testcase, params):
54 """Return the parameters used to create the main object for tests."""
55 from dbus.mainloop.glib import DBusGMainLoop
56
57=== modified file 'tests/platform/linux/eventlog/test_zg_listener.py'
58--- tests/platform/linux/eventlog/test_zg_listener.py 2011-04-20 21:47:24 +0000
59+++ tests/platform/linux/eventlog/test_zg_listener.py 2011-06-15 21:34:36 +0000
60@@ -1133,6 +1133,7 @@
61 self.assertEqual(local_folder.mimetype, DIRECTORY_MIMETYPE)
62 self.assertEqual(local_folder.storage, STORAGE_LOCAL)
63
64+
65 class ZeitgeistPublicFilesTestCase(ZeitgeistListenerTestCase):
66 """Public files events are logged into Zeitgeist."""
67
68
69=== modified file 'tests/platform/linux/eventlog/test_zglog.py'
70--- tests/platform/linux/eventlog/test_zglog.py 2010-12-02 14:53:38 +0000
71+++ tests/platform/linux/eventlog/test_zglog.py 2011-06-15 21:34:36 +0000
72@@ -73,6 +73,7 @@
73 d.addCallback(verify)
74 return d
75
76+
77 def wait_zeitgeist_started(seconds=10):
78 """Wait a few seconds until zg is started, or fail if it can't."""
79 client = None
80
81=== modified file 'tests/platform/linux/test_config.py'
82--- tests/platform/linux/test_config.py 2010-12-01 21:13:52 +0000
83+++ tests/platform/linux/test_config.py 2011-06-15 21:34:36 +0000
84@@ -1,8 +1,25 @@
85+# -*- coding: utf-8 -*-
86+
87+# Copyright 2010-2011 Canonical Ltd.
88+#
89+# This program is free software: you can redistribute it and/or modify it
90+# under the terms of the GNU General Public License version 3, as published
91+# by the Free Software Foundation.
92+#
93+# This program is distributed in the hope that it will be useful, but
94+# WITHOUT ANY WARRANTY; without even the implied warranties of
95+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
96+# PURPOSE. See the GNU General Public License for more details.
97+#
98+# You should have received a copy of the GNU General Public License along
99+# with this program. If not, see <http://www.gnu.org/licenses/>.
100+
101 from ConfigParser import ConfigParser
102
103 from tests.platform.linux.test_dbus import DBusTwistedTestCase
104 from ubuntuone.syncdaemon import config
105
106+
107 class TestDBusConfig(DBusTwistedTestCase):
108
109 def test_get_throttling_limits(self):
110
111=== modified file 'tests/platform/linux/test_credentials.py'
112--- tests/platform/linux/test_credentials.py 2011-05-31 18:13:24 +0000
113+++ tests/platform/linux/test_credentials.py 2011-06-15 21:34:36 +0000
114@@ -21,7 +21,7 @@
115 from functools import wraps
116
117 from twisted.internet.defer import Deferred, inlineCallbacks
118-from ubuntuone.devtools.testcase import DBusTestCase as TestCase
119+from ubuntuone.devtools.testcase import DBusTestCase
120 from ubuntuone.devtools.handlers import MementoHandler
121
122 from ubuntuone.credentials import logging, logger
123@@ -172,15 +172,16 @@
124 self.register(app_name, args)
125
126
127-class BaseTestCase(TestCase):
128+class BaseTestCase(DBusTestCase):
129 """Base test case."""
130
131 timeout = 8
132 app_name = APP_NAME
133 error_dict = None
134
135+ @inlineCallbacks
136 def setUp(self):
137- super(BaseTestCase, self).setUp()
138+ yield super(BaseTestCase, self).setUp()
139 FakedSSOService.app_name = self.app_name
140 FakedSSOService.error_dict = self.error_dict
141
142@@ -188,7 +189,6 @@
143 self.memento.setLevel(logging.DEBUG)
144 logger.addHandler(self.memento)
145
146- self.bus = dbus.SessionBus()
147 self.sso_server = self.register_server(ubuntu_sso.DBUS_BUS_NAME,
148 ubuntu_sso.DBUS_CREDENTIALS_PATH,
149 FakedSSOService) # faked SSO server
150@@ -201,6 +201,7 @@
151 'Service %s should not be running.' % bus_name)
152 mock = service_class(object_path=object_path, conn=self.bus)
153 self.addCleanup(mock.remove_from_connection)
154+ self.addCleanup(lambda: self.bus.release_name(bus_name))
155
156 return mock
157
158@@ -222,8 +223,9 @@
159 signals = ('CredentialsFound', 'CredentialsNotFound', 'CredentialsCleared',
160 'CredentialsStored', 'CredentialsError', 'AuthorizationDenied')
161
162+ @inlineCallbacks
163 def setUp(self):
164- super(CredentialsManagementTestCase, self).setUp()
165+ yield super(CredentialsManagementTestCase, self).setUp()
166 self.creds_server = self.register_server(DBUS_BUS_NAME,
167 DBUS_CREDENTIALS_PATH,
168 CredentialsManagement) # real service
169@@ -596,8 +598,9 @@
170 class RefCountingTestCase(BaseTestCase):
171 """Tests for the CredentialsManagement ref counting."""
172
173+ @inlineCallbacks
174 def setUp(self):
175- super(RefCountingTestCase, self).setUp()
176+ yield super(RefCountingTestCase, self).setUp()
177 self._called = False
178 self.client = CredentialsManagement()
179
180@@ -848,13 +851,13 @@
181 class CredentialsTestCase(BaseTestCase):
182 """Test suite for the Credentials class."""
183
184+ @inlineCallbacks
185 def setUp(self):
186- super(CredentialsTestCase, self).setUp()
187+ yield super(CredentialsTestCase, self).setUp()
188 FakedSSOService.error_dict = None
189 self.creds_server = self.register_server(DBUS_BUS_NAME,
190 DBUS_CREDENTIALS_PATH,
191 CredentialsManagement) # real service
192-
193 self.client = CredentialsManagementTool()
194
195 @inlineCallbacks
196@@ -982,4 +985,3 @@
197 self.assertEqual(e[0], FakedSSOService.error_dict)
198 else:
199 self.fail('Must not succeed!')
200-
201
202=== modified file 'tests/platform/linux/test_dbus.py'
203--- tests/platform/linux/test_dbus.py 2011-06-15 13:54:26 +0000
204+++ tests/platform/linux/test_dbus.py 2011-06-15 21:34:36 +0000
205@@ -23,7 +23,6 @@
206 import logging
207
208 import dbus
209-from dbus.mainloop.glib import DBusGMainLoop
210 from dbus import exceptions
211 from mocker import MockerTestCase
212 from twisted.internet import defer, reactor
213@@ -105,12 +104,7 @@
214 self.fs_manager = self.main.fs
215 self.event_q = self.main.event_q
216 self.action_q = self.main.action_q
217- self.loop = DBusGMainLoop(set_as_default=True)
218- self.bus = dbus.bus.BusConnection(mainloop=self.loop)
219 self.nm = FakeNetworkManager(self.bus)
220- # monkeypatch busName.__del__ to avoid errors on gc
221- # we take care of releasing the name in shutdown
222- dbus.service.BusName.__del__ = lambda _: None
223 self.dbus_iface = DBusInterface(self.bus, self.main,
224 system_bus=self.bus)
225 # expose the inner object so that other tests can access them
226@@ -128,10 +122,8 @@
227 self.main.external = ExternalInterface(self.main, False, False,
228 dbus_iface=self.dbus_iface)
229 self.busName = self.dbus_iface.busName
230- self.bus.set_exit_on_disconnect(False)
231 self.dbus_iface.connect()
232 self.event_q.push('SYS_INIT_DONE')
233- self.signal_receivers = set()
234
235 self.handler = MementoHandler()
236 self._logger = logging.getLogger("ubuntuone.SyncDaemon")
237@@ -149,8 +141,6 @@
238 self.main.shutdown()
239 self.nm.shutdown()
240 self.dbus_iface.bus.flush()
241- self.bus.flush()
242- self.bus.close()
243 self.rmtree(self.shares_dir)
244 self.rmtree(self.root_dir)
245 self.rmtree(self.data_dir)
246@@ -2550,8 +2540,48 @@
247 error_handler=self.error_handler)
248 return d
249
250+ def test_enable_autoconnect(self):
251+ """Test for Config.enable_autoconnect."""
252+ client = self.get_client()
253+ d = defer.Deferred()
254+ orig = config.get_user_config().get_autoconnect()
255+ # restore autoconnect to original value
256+ self.addCleanup(lambda: config.get_user_config().set_autoconnect(orig))
257+
258+ def reply_handler(_):
259+ """Handle the reply."""
260+ self.assertTrue(config.get_user_config().get_autoconnect())
261+ d.callback(True)
262+
263+ client.call_method('enable_autoconnect',
264+ reply_handler=reply_handler,
265+ error_handler=self.error_handler)
266+ return d
267+
268+ def test_disable_autoconnect(self):
269+ """Test for Config.disable_autoconnect."""
270+ client = self.get_client()
271+ d = defer.Deferred()
272+ orig = config.get_user_config().get_autoconnect()
273+ # restore autoconnect to original value
274+ self.addCleanup(lambda: config.get_user_config().set_autoconnect(orig))
275+
276+ def reply_handler(_):
277+ """Handle the reply."""
278+ self.assertFalse(config.get_user_config().get_autoconnect())
279+ d.callback(True)
280+
281+ client.call_method('disable_autoconnect',
282+ reply_handler=reply_handler,
283+ error_handler=self.error_handler)
284+ return d
285+
286 def test_set_autoconnect_enabled(self):
287- """Test for Config.set_autoconnect_enabled."""
288+ """Test for Config.set_autoconnect_enabled.
289+
290+ DEPRECATED.
291+
292+ """
293 client = self.get_client()
294 d = defer.Deferred()
295 orig = config.get_user_config().get_autoconnect()
296@@ -2657,6 +2687,7 @@
297 self.events.append((name, kw))
298 self.memento = MementoHandler()
299 logger.addHandler(self.memento)
300+ self.addCleanup(lambda: logger.removeHandler(self.memento))
301
302 def tearDown(self, *args):
303 """Shutdown."""
304
305=== modified file 'tests/platform/linux/test_os_helper.py'
306--- tests/platform/linux/test_os_helper.py 2011-04-01 19:48:38 +0000
307+++ tests/platform/linux/test_os_helper.py 2011-06-15 21:34:36 +0000
308@@ -45,6 +45,7 @@
309 stat_path,
310 )
311
312+
313 class FakeGIOFile(object):
314 """Fake File for gio."""
315
316
317=== modified file 'tests/platform/linux/test_session.py'
318--- tests/platform/linux/test_session.py 2011-02-22 23:15:12 +0000
319+++ tests/platform/linux/test_session.py 2011-06-15 21:34:36 +0000
320@@ -31,6 +31,7 @@
321 session.INHIBIT_SUSPENDING_COMPUTER |
322 session.INHIBIT_SESSION_IDLE)
323
324+
325 class FakeGnomeSessionManagerInhibitor(dbus.service.Object):
326 """A fake Gnome Session Manager (but only the inhibitor bits)."""
327
328@@ -66,9 +67,10 @@
329
330 timeout = 5
331
332+ @inlineCallbacks
333 def setUp(self):
334 """Initialize this test case."""
335- DBusTestCase.setUp(self)
336+ yield super(SessionDBusClientTestCase, self).setUp()
337 DBusGMainLoop(set_as_default=True)
338
339 def test_fake_inhibitor(self):
340@@ -92,15 +94,16 @@
341 def register_fakeserver(self, bus_name, object_path, object_class,
342 **kwargs):
343 """The fake service is registered on the DBus."""
344- session_bus = dbus.SessionBus()
345 flags = (dbus.bus.NAME_FLAG_REPLACE_EXISTING |
346 dbus.bus.NAME_FLAG_DO_NOT_QUEUE |
347 dbus.bus.NAME_FLAG_ALLOW_REPLACEMENT)
348- name = session_bus.request_name(bus_name, flags=flags)
349+ name = self.bus.request_name(bus_name, flags=flags)
350 self.assertNotEqual(name, dbus.bus.REQUEST_NAME_REPLY_EXISTS)
351- fake = object_class(object_path=object_path, conn=session_bus,
352+ fake = object_class(object_path=object_path, conn=self.bus,
353 **kwargs)
354 self.addCleanup(fake.remove_from_connection)
355+ self.addCleanup(lambda: self.bus.release_name(bus_name))
356+
357 return fake
358
359 @inlineCallbacks
360
361=== modified file 'tests/platform/linux/test_tools.py'
362--- tests/platform/linux/test_tools.py 2011-06-15 13:54:26 +0000
363+++ tests/platform/linux/test_tools.py 2011-06-15 21:34:36 +0000
364@@ -45,19 +45,15 @@
365 yield super(TestToolsBase, self).setUp()
366 self.tool = tools.SyncDaemonTool(self.bus)
367 self.home_dir = self.mktemp('ubuntuonehacker')
368- self._old_home = os.environ['HOME']
369+ old_home = os.environ['HOME']
370 os.environ['HOME'] = self.home_dir
371+ self.addCleanup(lambda: os.environ.__setitem__('HOME', old_home))
372+ self.addCleanup(lambda: self.rmtree(self.home_dir))
373 self.handler = MementoHandler()
374 self.tool.log.addHandler(self.handler)
375 yield self.main.wait_for_nirvana()
376
377 @defer.inlineCallbacks
378- def tearDown(self):
379- os.environ['HOME'] = self._old_home
380- self.rmtree(self.home_dir)
381- yield super(TestToolsBase, self).tearDown()
382-
383- @defer.inlineCallbacks
384 def create_file(self, path):
385 """ creates a test file in fsm """
386 share_path = os.path.join(self.shares_dir, 'share_tools')
387@@ -69,7 +65,7 @@
388
389
390 class TestToolsBasic(TestToolsBase):
391- """ Baic test of SyncDaemonTool """
392+ """Basic test of SyncDaemonTool."""
393
394 def _create_share(self, accepted=True, subscribed=True):
395 """Return a newly created Share."""
396@@ -586,6 +582,31 @@
397 self.assertEqual(False, config.get_files_sync_enabled())
398
399 @defer.inlineCallbacks
400+ def test_is_autoconnect_enabled(self):
401+ """Test for is_autoconnect_enabled."""
402+ yield self.tool.enable_autoconnect(False)
403+ enabled = yield self.tool.is_autoconnect_enabled()
404+ self.assertFalse(enabled)
405+
406+ yield self.tool.enable_autoconnect(True)
407+ enabled = yield self.tool.is_autoconnect_enabled()
408+ self.assertTrue(enabled)
409+
410+ @defer.inlineCallbacks
411+ def test_enable_autoconnect(self):
412+ """Test for enable_autoconnect."""
413+ yield self.tool.enable_autoconnect(True)
414+ enabled = yield self.tool.is_autoconnect_enabled()
415+ self.assertTrue(enabled)
416+
417+ @defer.inlineCallbacks
418+ def test_disable_autoconnect(self):
419+ """Test for disable_autoconnect."""
420+ yield self.tool.enable_autoconnect(False)
421+ enabled = yield self.tool.is_autoconnect_enabled()
422+ self.assertFalse(enabled)
423+
424+ @defer.inlineCallbacks
425 def test_is_show_all_notifications_enabled(self):
426 """Test for is_show_all_notifications_enabled."""
427 yield self.tool.enable_show_all_notifications(False)
428@@ -611,6 +632,56 @@
429 self.assertFalse(enabled)
430
431 @defer.inlineCallbacks
432+ def test_is_share_autosubscribe_enabled(self):
433+ """Test for is_share_autosubscribe_enabled."""
434+ yield self.tool.enable_share_autosubscribe(False)
435+ enabled = yield self.tool.is_share_autosubscribe_enabled()
436+ self.assertFalse(enabled)
437+
438+ yield self.tool.enable_share_autosubscribe(True)
439+ enabled = yield self.tool.is_share_autosubscribe_enabled()
440+ self.assertTrue(enabled)
441+
442+ @defer.inlineCallbacks
443+ def test_enable_share_autosubscribe(self):
444+ """Test for enable_share_autosubscribe."""
445+ yield self.tool.enable_share_autosubscribe(True)
446+ enabled = yield self.tool.is_share_autosubscribe_enabled()
447+ self.assertTrue(enabled)
448+
449+ @defer.inlineCallbacks
450+ def test_disable_share_autosubscribe(self):
451+ """Test for disable_share_autosubscribe."""
452+ yield self.tool.enable_share_autosubscribe(False)
453+ enabled = yield self.tool.is_share_autosubscribe_enabled()
454+ self.assertFalse(enabled)
455+
456+ @defer.inlineCallbacks
457+ def test_is_udf_autosubscribe_enabled(self):
458+ """Test for is_udf_autosubscribe_enabled."""
459+ yield self.tool.enable_udf_autosubscribe(False)
460+ enabled = yield self.tool.is_udf_autosubscribe_enabled()
461+ self.assertFalse(enabled)
462+
463+ yield self.tool.enable_udf_autosubscribe(True)
464+ enabled = yield self.tool.is_udf_autosubscribe_enabled()
465+ self.assertTrue(enabled)
466+
467+ @defer.inlineCallbacks
468+ def test_enable_udf_autosubscribe(self):
469+ """Test for enable_udf_autosubscribe."""
470+ yield self.tool.enable_udf_autosubscribe(True)
471+ enabled = yield self.tool.is_udf_autosubscribe_enabled()
472+ self.assertTrue(enabled)
473+
474+ @defer.inlineCallbacks
475+ def test_disable_udf_autosubscribe(self):
476+ """Test for disable_udf_autosubscribe."""
477+ yield self.tool.enable_udf_autosubscribe(False)
478+ enabled = yield self.tool.is_udf_autosubscribe_enabled()
479+ self.assertFalse(enabled)
480+
481+ @defer.inlineCallbacks
482 def test_refresh_volumes(self):
483 """Test for refresh_volumes method."""
484 d = defer.Deferred()
485
486=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
487--- ubuntuone/platform/linux/dbus_interface.py 2011-06-09 10:08:57 +0000
488+++ ubuntuone/platform/linux/dbus_interface.py 2011-06-15 21:34:36 +0000
489@@ -17,8 +17,10 @@
490 # with this program. If not, see <http://www.gnu.org/licenses/>.
491 """DBUS interface module."""
492
493+import logging
494+import warnings
495+
496 import dbus.service
497-import logging
498
499 from dbus import DBusException
500 from xml.etree import ElementTree
501@@ -192,9 +194,11 @@
502 def waiting_metadata(self):
503 """Return a list of the operations in the meta-queue.
504
505- As we don't have meta-queue anymore, this is faked. This method
506+ As we don't have meta-queue anymore, this is faked. This method
507 is deprecated, and will go away in a near future.
508+
509 """
510+ warnings.warn('Use "waiting" method instead.', DeprecationWarning)
511 logger.debug('called waiting_metadata')
512 commands = self.syncdaemon_status.waiting_metadata()
513 for op, data in commands:
514@@ -207,7 +211,9 @@
515
516 As we don't have content-queue anymore, this is faked. This method
517 is deprecated, and will go away in a near future.
518+
519 """
520+ warnings.warn('Use "waiting" method instead.', DeprecationWarning)
521 logger.debug('called waiting_content')
522 commands = self.syncdaemon_status.waiting_content()
523 for data in commands:
524@@ -265,14 +271,20 @@
525 """Fire a signal to notify that the content queue has changed.
526
527 This signal is deprecated, and will go away in a near future.
528+
529 """
530+ msg = 'Connect to RequestQueueAdded/RequestQueueRemoved instead.'
531+ warnings.warn(msg, DeprecationWarning)
532
533 @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
534 def MetaQueueChanged(self):
535 """Fire a signal to notify that the meta queue has changed.
536
537 This signal is deprecated, and will go away in a near future.
538+
539 """
540+ msg = 'Connect to RequestQueueAdded/RequestQueueRemoved instead.'
541+ warnings.warn(msg, DeprecationWarning)
542
543 @dbus.service.signal(DBUS_IFACE_STATUS_NAME, signature='ssa{ss}')
544 def RequestQueueAdded(self, op_name, op_id, data):
545@@ -906,10 +918,26 @@
546 """Return the autoconnect config value."""
547 return self.syncdaemon_config.autoconnect_enabled()
548
549+ @dbus.service.method(DBUS_IFACE_CONFIG_NAME)
550+ def enable_autoconnect(self):
551+ """Enable syncdaemon autoconnect."""
552+ self.syncdaemon_config.set_autoconnect_enabled(True)
553+
554+ @dbus.service.method(DBUS_IFACE_CONFIG_NAME)
555+ def disable_autoconnect(self):
556+ """Disable syncdaemon autoconnect."""
557+ self.syncdaemon_config.set_autoconnect_enabled(False)
558+
559 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
560 in_signature='b', out_signature='')
561 def set_autoconnect_enabled(self, enabled):
562- """Enable syncdaemon autoconnect."""
563+ """Enable syncdaemon autoconnect.
564+
565+ This method is deprecated.
566+
567+ """
568+ msg = 'Use enable_autoconnect/disable_autoconnect instead.'
569+ warnings.warn(msg, DeprecationWarning)
570 self.syncdaemon_config.set_autoconnect_enabled(enabled)
571
572 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
573
574=== modified file 'ubuntuone/platform/linux/tools.py'
575--- ubuntuone/platform/linux/tools.py 2011-06-15 18:09:09 +0000
576+++ ubuntuone/platform/linux/tools.py 2011-06-15 21:34:36 +0000
577@@ -714,30 +714,40 @@
578 error_handler=d.errback)
579 return d
580
581+
582+ def _is_setting_enabled(self, setting_name):
583+ """Return whether 'setting_name' is enabled."""
584+ d = defer.Deferred()
585+ config_client = DBusClient(self.bus, '/config',
586+ DBUS_IFACE_CONFIG_NAME)
587+ config_client.call_method('%s_enabled' % setting_name,
588+ reply_handler=d.callback,
589+ error_handler=d.errback)
590+ return d
591+
592+ def _enable_setting(self, setting_name, enabled, dbus_method=None):
593+ """Enable/disable 'setting_name'."""
594+ d = defer.Deferred()
595+ config_client = DBusClient(self.bus, '/config',
596+ DBUS_IFACE_CONFIG_NAME)
597+ if dbus_method is not None:
598+ meth = dbus_method
599+ elif enabled:
600+ meth = 'enable_%s'
601+ else:
602+ meth = 'disable_%s'
603+ config_client.call_method(meth % setting_name,
604+ reply_handler=d.callback,
605+ error_handler=d.errback)
606+ return d
607+
608 def is_throttling_enabled(self):
609 """Check if throttling is enabled."""
610- d = defer.Deferred()
611- config_client = DBusClient(self.bus, '/config',
612- DBUS_IFACE_CONFIG_NAME)
613- config_client.call_method('bandwidth_throttling_enabled',
614- reply_handler=d.callback,
615- error_handler=d.errback)
616- return d
617-
618+ return self._is_setting_enabled('bandwidth_throttling')
619
620 def enable_throttling(self, enabled):
621 """Enable/disable throttling."""
622- d = defer.Deferred()
623- config_client = DBusClient(self.bus, '/config',
624- DBUS_IFACE_CONFIG_NAME)
625- if enabled:
626- meth = 'enable_bandwidth_throttling'
627- else:
628- meth = 'disable_bandwidth_throttling'
629- config_client.call_method(meth,
630- reply_handler=d.callback,
631- error_handler=d.errback)
632- return d
633+ return self._enable_setting('bandwidth_throttling', enabled)
634
635 def is_files_sync_enabled(self):
636 """Check if files sync is enabled."""
637@@ -770,30 +780,37 @@
638 config.save()
639 self.start()
640
641+ def is_autoconnect_enabled(self):
642+ """Check if autoconnect is enabled."""
643+ return self._is_setting_enabled('autoconnect')
644+
645+ def enable_autoconnect(self, enabled):
646+ """Enable/disable autoconnect."""
647+ return self._enable_setting('autoconnect', enabled)
648+
649 def is_show_all_notifications_enabled(self):
650 """Check if show_all_notifications is enabled."""
651- d = defer.Deferred()
652- config_client = DBusClient(self.bus, '/config',
653- DBUS_IFACE_CONFIG_NAME)
654- config_client.call_method('show_all_notifications_enabled',
655- reply_handler=d.callback,
656- error_handler=d.errback)
657- return d
658-
659+ return self._is_setting_enabled('show_all_notifications')
660
661 def enable_show_all_notifications(self, enabled):
662 """Enable/disable show_all_notifications."""
663- d = defer.Deferred()
664- config_client = DBusClient(self.bus, '/config',
665- DBUS_IFACE_CONFIG_NAME)
666- if enabled:
667- meth = 'enable_show_all_notifications'
668- else:
669- meth = 'disable_show_all_notifications'
670- config_client.call_method(meth,
671- reply_handler=d.callback,
672- error_handler=d.errback)
673- return d
674+ return self._enable_setting('show_all_notifications', enabled)
675+
676+ def is_share_autosubscribe_enabled(self):
677+ """Check if share_autosubscribe is enabled."""
678+ return self._is_setting_enabled('share_autosubscribe')
679+
680+ def enable_share_autosubscribe(self, enabled):
681+ """Enable/disable share_autosubscribe."""
682+ return self._enable_setting('share_autosubscribe', enabled)
683+
684+ def is_udf_autosubscribe_enabled(self):
685+ """Check if udf_autosubscribe is enabled."""
686+ return self._is_setting_enabled('udf_autosubscribe')
687+
688+ def enable_udf_autosubscribe(self, enabled):
689+ """Enable/disable udf_autosubscribe."""
690+ return self._enable_setting('udf_autosubscribe', enabled)
691
692 def refresh_volumes(self):
693 """Call refresh_volumes method via DBus.
694
695=== modified file 'ubuntuone/syncdaemon/event_queue.py'
696--- ubuntuone/syncdaemon/event_queue.py 2011-04-01 20:10:14 +0000
697+++ ubuntuone/syncdaemon/event_queue.py 2011-06-15 21:34:36 +0000
698@@ -205,6 +205,11 @@
699 def shutdown(self):
700 """Make the monitor shutdown."""
701 self.monitor.shutdown()
702+ # clean up all registered listeners
703+ if len(self.listener_map.items()) > 0:
704+ for k, v in self.listener_map.items():
705+ v.clear()
706+ del self.listener_map[k]
707
708 def rm_watch(self, dirpath):
709 """Remove watch from a dir."""
710
711=== modified file 'ubuntuone/syncdaemon/main.py'
712--- ubuntuone/syncdaemon/main.py 2011-04-06 17:31:12 +0000
713+++ ubuntuone/syncdaemon/main.py 2011-06-15 21:34:36 +0000
714@@ -46,6 +46,7 @@
715
716 class WaitingHelpingHandler(object):
717 """An auxiliary class that helps wait for events."""
718+
719 def __init__(self, event_queue, waiting_events, waiting_kwargs,
720 result=None):
721 self.deferred = defer.Deferred()
722@@ -104,7 +105,7 @@
723 self.event_q = event_queue.EventQueue(self.fs, ignore_files)
724 self.fs.register_eq(self.event_q)
725
726- # subscribe VM to EQ
727+ # subscribe VM to EQ, to be unsubscribed in shutdown
728 self.event_q.subscribe(self.vm)
729 self.vm.init_root()
730
731@@ -143,12 +144,14 @@
732 def start_event_logger(self):
733 """Start the event logger if it's available for this platform."""
734 self.eventlog_listener = event_logging.get_listener(self.fs, self.vm)
735+ # subscribe to EQ, to be unsubscribed in shutdown
736 if self.eventlog_listener:
737 self.event_q.subscribe(self.eventlog_listener)
738
739 def start_status_listener(self):
740 """Start the status listener if it is configured to start."""
741 self.status_listener = status_listener.get_listener(self.fs, self.vm)
742+ # subscribe to EQ, to be unsubscribed in shutdown
743 if self.status_listener:
744 self.event_q.subscribe(self.status_listener)
745
746@@ -203,11 +206,20 @@
747 """Shutdown the daemon; optionally restart it."""
748 self.event_q.push('SYS_USER_DISCONNECT')
749 self.event_q.push('SYS_QUIT')
750+
751+ self.event_q.unsubscribe(self.vm)
752+ if getattr(self, 'eventlog_listener', None) is not None:
753+ self.event_q.unsubscribe(self.eventlog_listener)
754+ if getattr(self, 'status_listener', None) is not None:
755+ self.event_q.unsubscribe(self.status_listener)
756+
757+ # shutdown these before event_q so the listeners are unsubscribed
758+ self.state_manager.shutdown()
759+ self.hash_q.shutdown()
760+ self.external.shutdown(with_restart)
761+
762 self.event_q.shutdown()
763- self.hash_q.shutdown()
764 self.db.shutdown()
765- self.state_manager.shutdown()
766- self.external.shutdown(with_restart)
767 self.mark.stop()
768
769 def restart(self):
770
771=== modified file 'ubuntuone/syncdaemon/states.py'
772--- ubuntuone/syncdaemon/states.py 2011-03-07 15:39:09 +0000
773+++ ubuntuone/syncdaemon/states.py 2011-06-15 21:34:36 +0000
774@@ -491,3 +491,4 @@
775 def shutdown(self):
776 """Finish all pending work."""
777 self.connection.shutdown()
778+ self.eq.unsubscribe(self)

Subscribers

People subscribed via source and target branches