Merge lp:~nataliabidart/ubuntuone-client/autoconnect into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 772
Merged at revision: 770
Proposed branch: lp:~nataliabidart/ubuntuone-client/autoconnect
Merge into: lp:ubuntuone-client
Diff against target: 398 lines (+194/-13)
10 files modified
bin/ubuntuone-preferences (+10/-4)
data/syncdaemon.conf (+5/-0)
tests/platform/linux/test_dbus.py (+43/-0)
tests/syncdaemon/test_config.py (+52/-2)
tests/syncdaemon/test_main.py (+36/-3)
tests/test_preferences.py (+5/-2)
ubuntuone/platform/linux/__init__.py (+15/-1)
ubuntuone/platform/linux/dbus_interface.py (+14/-0)
ubuntuone/syncdaemon/config.py (+9/-0)
ubuntuone/syncdaemon/main.py (+5/-1)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/autoconnect
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Chad Miller (community) Approve
Review via email: mp+43385@code.launchpad.net

Commit message

* Added new config option 'autoconnect' (LP: #688694).

Description of the change

To test, you should:

* quit syncdaemon (u1sdtool -q)

* edit ~/.config/ubuntuone/syncdaemon.conf and under the __main__ section add:
autoconnect = True

* ./autogen.sh && make

* start syncdaemon from this branch with:
PYTHONPATH=. ./bin/ubuntuone-syncdaemon

Monitor syncdaemon status either thru the logs or using u1sdtool and you'll see how it progresses further than READY, reaching QUEUE_MANAGER state.

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) wrote :

Works for me.

review: Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

looks good, tests pass.

review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntuone-preferences'
--- bin/ubuntuone-preferences 2010-11-30 17:53:14 +0000
+++ bin/ubuntuone-preferences 2010-12-10 22:10:15 +0000
@@ -123,6 +123,7 @@
123 except DBusException, e:123 except DBusException, e:
124 error_handler(e)124 error_handler(e)
125125
126
126def really_do_rest_request(url, method, conn):127def really_do_rest_request(url, method, conn):
127 """Second-order helper that does the REST request.128 """Second-order helper that does the REST request.
128129
@@ -136,6 +137,7 @@
136 conn.send(result)137 conn.send(result)
137 logger.debug("end really_do_rest_request (%s:%s)", method, url)138 logger.debug("end really_do_rest_request (%s:%s)", method, url)
138139
140
139def do_rest_request(proc, conn, callback):141def do_rest_request(proc, conn, callback):
140 """Helper that handles the REST request."""142 """Helper that handles the REST request."""
141 pid = os.getpid()143 pid = os.getpid()
@@ -149,6 +151,7 @@
149 callback(result)151 callback(result)
150 logger.debug("end do_rest_request (%d)", pid)152 logger.debug("end do_rest_request (%d)", pid)
151153
154
152def make_rest_request(url=None, method='GET', callback=None):155def make_rest_request(url=None, method='GET', callback=None):
153 """Helper that makes an oauth-wrapped REST request."""156 """Helper that makes an oauth-wrapped REST request."""
154 logger.debug("make_rest_request (%s:%s)", method, url)157 logger.debug("make_rest_request (%s:%s)", method, url)
@@ -159,6 +162,7 @@
159 Thread(target=do_rest_request, args=(p, conn1, callback)).start()162 Thread(target=do_rest_request, args=(p, conn1, callback)).start()
160 logger.debug("end make_rest_request (%s:%s)", method, url)163 logger.debug("end make_rest_request (%s:%s)", method, url)
161164
165
162class DevicesWidget(gtk.Table):166class DevicesWidget(gtk.Table):
163 """167 """
164 the Devices tab.168 the Devices tab.
@@ -471,9 +475,9 @@
471 DBUS_CREDENTIALS_PATH,475 DBUS_CREDENTIALS_PATH,
472 follow_name_owner_changes=True)476 follow_name_owner_changes=True)
473 iface = dbus.Interface(client, DBUS_CREDENTIALS_IFACE)477 iface = dbus.Interface(client, DBUS_CREDENTIALS_IFACE)
474 iface.clear_token(clientdefs.APP_NAME,478 iface.clear_credentials(clientdefs.APP_NAME, {},
475 reply_handler=local_removal_cb,479 reply_handler=local_removal_cb,
476 error_handler=self.error)480 error_handler=self.error)
477 except DBusException, e:481 except DBusException, e:
478 self.error(e)482 self.error(e)
479483
@@ -1054,8 +1058,10 @@
1054 self.present()1058 self.present()
1055 logger.info("Got credentials for %s", app_name)1059 logger.info("Got credentials for %s", app_name)
10561060
1057 def got_credentialserror(self, app_name, message, detailed_error):1061 def got_credentialserror(self, app_name, error_dict):
1058 """Got an error during authentication."""1062 """Got an error during authentication."""
1063 message = error_dict.get('error_msg', '')
1064 detailed_error = error_dict.get('detailed_error', '')
1059 if app_name == clientdefs.APP_NAME:1065 if app_name == clientdefs.APP_NAME:
1060 logger.error("Credentials error for %s: %s - %s" %1066 logger.error("Credentials error for %s: %s - %s" %
1061 (app_name, message, detailed_error))1067 (app_name, message, detailed_error))
10621068
=== modified file 'data/syncdaemon.conf'
--- data/syncdaemon.conf 2010-11-12 21:39:37 +0000
+++ data/syncdaemon.conf 2010-12-10 22:10:15 +0000
@@ -64,6 +64,11 @@
64udf_autosubscribe.help = Autosubsribe to new User Defined Folders, 'off' by default. 64udf_autosubscribe.help = Autosubsribe to new User Defined Folders, 'off' by default.
65 (accepted values: 1/0, on/off, true/false and yes/no)65 (accepted values: 1/0, on/off, true/false and yes/no)
6666
67autoconnect.default = True
68autoconnect.parser = bool
69autoconnect.help = Autoconnect the syncdaemon when is ready to start file synchronization against the server, 'on' by default.
70 (accepted values: 1/0, on/off, true/false and yes/no)
71
67ignore.parser = lines72ignore.parser = lines
68ignore.help = The list of (Python, not bash) regexes of the files that 73ignore.help = The list of (Python, not bash) regexes of the files that
69 SD should ignore.74 SD should ignore.
7075
=== modified file 'tests/platform/linux/test_dbus.py'
--- tests/platform/linux/test_dbus.py 2010-12-06 21:34:56 +0000
+++ tests/platform/linux/test_dbus.py 2010-12-10 22:10:15 +0000
@@ -2425,6 +2425,49 @@
2425 error_handler=self.error_handler)2425 error_handler=self.error_handler)
2426 return d2426 return d
24272427
2428 def test_autoconnect_enabled(self):
2429 """Test for Config.autoconnect_enabled."""
2430 client = self.get_client()
2431 d = defer.Deferred()
2432
2433 def reply_handler_disabled(result):
2434 """Handle the reply."""
2435 self.assertFalse(result)
2436 config.get_user_config().set_autoconnect(not result)
2437 d.callback(True)
2438
2439 def reply_handler_enabled(result):
2440 """Handle the reply."""
2441 self.assertTrue(result)
2442 config.get_user_config().set_autoconnect(not result)
2443 client.call_method('autoconnect_enabled',
2444 reply_handler=reply_handler_disabled,
2445 error_handler=self.error_handler)
2446
2447 client.call_method('autoconnect_enabled',
2448 reply_handler=reply_handler_enabled,
2449 error_handler=self.error_handler)
2450 return d
2451
2452 def test_set_autoconnect_enabled(self):
2453 """Test for Config.set_autoconnect_enabled."""
2454 client = self.get_client()
2455 d = defer.Deferred()
2456 orig = config.get_user_config().get_autoconnect()
2457 # restore autoconnect to original value
2458 self.addCleanup(lambda: config.get_user_config().set_autoconnect(orig))
2459
2460 def reply_handler(_):
2461 """Handle the reply."""
2462 self.assertEqual(config.get_user_config().get_autoconnect(),
2463 not orig)
2464 d.callback(True)
2465
2466 client.call_method('set_autoconnect_enabled', not orig,
2467 reply_handler=reply_handler,
2468 error_handler=self.error_handler)
2469 return d
2470
24282471
2429class DBusOAuthTestCase(BaseTwistedTestCase):2472class DBusOAuthTestCase(BaseTwistedTestCase):
2430 """Tests the interaction between dbus_interface and ubuntu-sso-client."""2473 """Tests the interaction between dbus_interface and ubuntu-sso-client."""
24312474
=== modified file 'tests/syncdaemon/test_config.py'
--- tests/syncdaemon/test_config.py 2010-11-30 17:53:14 +0000
+++ tests/syncdaemon/test_config.py 2010-12-10 22:10:15 +0000
@@ -235,7 +235,8 @@
235235
236 def test_load_udf_autosubscribe(self):236 def test_load_udf_autosubscribe(self):
237 """Test load/set/override of udf_autosubscribe config value."""237 """Test load/set/override of udf_autosubscribe config value."""
238 conf_file = os.path.join(self.test_root, 'test_udf_autosubscribe_config.conf')238 conf_file = os.path.join(self.test_root,
239 'test_udf_autosubscribe_config.conf')
239 # write some throttling values to the config file240 # write some throttling values to the config file
240 with open(conf_file, 'w') as fp:241 with open(conf_file, 'w') as fp:
241 fp.write('[__main__]\n')242 fp.write('[__main__]\n')
@@ -275,11 +276,60 @@
275 overridden_opts = [('__main__', 'udf_autosubscribe', False)]276 overridden_opts = [('__main__', 'udf_autosubscribe', False)]
276 conf.override_options(overridden_opts)277 conf.override_options(overridden_opts)
277 self.assertFalse(conf.get_udf_autosubscribe())278 self.assertFalse(conf.get_udf_autosubscribe())
278 self.assertFalse(conf.get_udf_autosubscribe() == conf_orig.get_udf_autosubscribe())279 self.assertNotEqual(conf.get_udf_autosubscribe(),
280 conf_orig.get_udf_autosubscribe())
279 conf.save()281 conf.save()
280 conf_1 = config._Config(conf_file)282 conf_1 = config._Config(conf_file)
281 self.assertEquals(True, conf_1.get_udf_autosubscribe())283 self.assertEquals(True, conf_1.get_udf_autosubscribe())
282284
285 def test_load_autoconnect(self):
286 """Test load/set/override of autoconnect config value."""
287 conf_file = os.path.join(self.test_root,
288 'test_autoconnect_config.conf')
289 # ensure that autoconnect is True
290 with open(conf_file, 'w') as fp:
291 fp.write('[__main__]\n')
292 fp.write('autoconnect = True\n')
293
294 # keep a original around
295 conf_orig = config._Config(conf_file)
296
297 # assert default is correct
298 self.assertTrue(conf_orig.get_autoconnect(),
299 'autoconnect is True by default.')
300
301 # load the config
302 conf = config._Config(conf_file)
303 self.assertTrue(conf.get_autoconnect())
304
305 # change it to False
306 conf.set_autoconnect(False)
307 self.assertFalse(conf.get_autoconnect())
308
309 # save, load and check
310 conf.save()
311 conf_1 = config._Config(conf_file)
312 self.assertFalse(conf_1.get_autoconnect())
313 # change it to True
314 conf.set_autoconnect(True)
315 self.assertTrue(conf.get_autoconnect())
316 # save, load and check
317 conf.save()
318 conf_1 = config._Config(conf_file)
319 self.assertTrue(conf_1.get_autoconnect())
320
321 # load the config, check the override of the value
322 conf = config._Config(conf_file)
323 self.assertTrue(conf.get_autoconnect())
324 overridden_opts = [('__main__', 'autoconnect', False)]
325 conf.override_options(overridden_opts)
326 self.assertFalse(conf.get_autoconnect())
327 self.assertNotEqual(conf.get_autoconnect(),
328 conf_orig.get_autoconnect())
329 conf.save()
330 conf_1 = config._Config(conf_file)
331 self.assertEquals(True, conf_1.get_autoconnect())
332
283333
284class ConfigglueParsersTests(BaseTwistedTestCase):334class ConfigglueParsersTests(BaseTwistedTestCase):
285 """Tests for our custom configglue parsers"""335 """Tests for our custom configglue parsers"""
286336
=== modified file 'tests/syncdaemon/test_main.py'
--- tests/syncdaemon/test_main.py 2010-11-30 17:53:14 +0000
+++ tests/syncdaemon/test_main.py 2010-12-10 22:10:15 +0000
@@ -23,9 +23,9 @@
2323
24from twisted.internet import defer, reactor24from twisted.internet import defer, reactor
2525
26from ubuntuone.syncdaemon.main import Main26from ubuntuone.syncdaemon import main as main_mod
27from contrib.testing.testcase import (27from contrib.testing.testcase import (
28 BaseTwistedTestCase,28 BaseTwistedTestCase, FAKED_CREDENTIALS,
29)29)
3030
3131
@@ -56,9 +56,10 @@
56 dns_srv=False, ssl=False,56 dns_srv=False, ssl=False,
57 mark_interval=60,57 mark_interval=60,
58 handshake_timeout=2,58 handshake_timeout=2,
59 oauth_credentials=FAKED_CREDENTIALS,
59 glib_loop=DBusGMainLoop(set_as_default=True))60 glib_loop=DBusGMainLoop(set_as_default=True))
60 params.update(kwargs)61 params.update(kwargs)
61 m = Main(**params)62 m = main_mod.Main(**params)
62 m.local_rescan = lambda *_: m.event_q.push('SYS_LOCAL_RESCAN_DONE')63 m.local_rescan = lambda *_: m.event_q.push('SYS_LOCAL_RESCAN_DONE')
63 return m64 return m
6465
@@ -172,3 +173,35 @@
172 self.assertTrue(os.path.exists(self.shares))173 self.assertTrue(os.path.exists(self.shares))
173 self.assertTrue(os.path.exists(self.root))174 self.assertTrue(os.path.exists(self.root))
174 main.shutdown()175 main.shutdown()
176
177 def test_connect_if_autoconnect_is_enabled(self):
178 """If autoconnect option is enabled, connect the syncdaemon."""
179 user_config = main_mod.config.get_user_config()
180 orig = user_config.get_autoconnect()
181 user_config.set_autoconnect(True)
182 self.addCleanup(lambda: user_config.set_autoconnect(orig))
183
184 self.connect_called = False
185 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',
186 lambda *a: setattr(self, 'connect_called', True))
187
188 main = self.build_main()
189 self.addCleanup(lambda: main.shutdown())
190
191 self.assertTrue(self.connect_called)
192
193 def test_dont_connect_if_autoconnect_is_disabled(self):
194 """If autoconnect option is disabled, do not connect the syncdaemon."""
195 user_config = main_mod.config.get_user_config()
196 orig = user_config.get_autoconnect()
197 user_config.set_autoconnect(False)
198 self.addCleanup(lambda: user_config.set_autoconnect(orig))
199
200 self.connect_called = False
201 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',
202 lambda *a: setattr(self, 'connect_called', True))
203
204 main = self.build_main()
205 self.addCleanup(lambda: main.shutdown())
206
207 self.assertFalse(self.connect_called)
175208
=== modified file 'tests/test_preferences.py'
--- tests/test_preferences.py 2010-11-30 17:53:14 +0000
+++ tests/test_preferences.py 2010-12-10 22:10:15 +0000
@@ -561,8 +561,11 @@
561561
562 def test_got_credentialserror(self):562 def test_got_credentialserror(self):
563 """Test CredentialsError signal."""563 """Test CredentialsError signal."""
564 self.login_handler.got_credentialserror(clientdefs.APP_NAME, "Error", "Detailed error")564 error_dict = {'error_msg': 'Test', 'detailed_error': 'My bad'}
565 self.assertTrue(self.memento.check_error(clientdefs.APP_NAME, "Error", "Detailed error"))565 self.login_handler.got_credentialserror(clientdefs.APP_NAME,
566 error_dict)
567 self.assertTrue(self.memento.check_error(clientdefs.APP_NAME,
568 *error_dict.values()))
566569
567 def test_got_authdenied(self):570 def test_got_authdenied(self):
568 """Test AuthorizationDenied signal."""571 """Test AuthorizationDenied signal."""
569572
=== modified file 'ubuntuone/platform/linux/__init__.py'
--- ubuntuone/platform/linux/__init__.py 2010-12-06 21:34:56 +0000
+++ ubuntuone/platform/linux/__init__.py 2010-12-10 22:10:15 +0000
@@ -38,12 +38,15 @@
38 open_file,38 open_file,
39 rename,39 rename,
40)40)
41from ubuntuone.platform.linux.vm_helper import create_shares_link, get_udf_path_name, get_udf_path, get_share_path, VMMetadataUpgraderMixIn41from ubuntuone.platform.linux.vm_helper import (create_shares_link,
42 get_udf_path_name, get_udf_path, get_share_path, VMMetadataUpgraderMixIn)
42from ubuntuone.platform.linux import tools43from ubuntuone.platform.linux import tools
43from filesystem_notifications import FilesystemMonitor44from filesystem_notifications import FilesystemMonitor
4445
4546
46class ExternalInterface(object):47class ExternalInterface(object):
48 """An ExternalInterface implemented with a DBus interface."""
49
47 def __init__(self, main, glib_loop=False, broadcast_events=False,50 def __init__(self, main, glib_loop=False, broadcast_events=False,
48 dbus_iface=None):51 dbus_iface=None):
49 # avoid circular dependencies52 # avoid circular dependencies
@@ -63,8 +66,19 @@
63 self.dbus_iface = dbus_iface66 self.dbus_iface = dbus_iface
64 self.bus = None67 self.bus = None
6568
69 def _get_credentials(self):
70 return self.dbus_iface.oauth_credentials
71
72 def _set_credentials(self, credentials):
73 self.dbus_iface.oauth_credentials = credentials
74
75 oauth_credentials = property(fget=_get_credentials, fset=_set_credentials)
76
66 def change_notification(self):77 def change_notification(self):
67 self.dbus_iface.status.emit_content_queue_changed()78 self.dbus_iface.status.emit_content_queue_changed()
6879
69 def shutdown(self, with_restart):80 def shutdown(self, with_restart):
70 self.dbus_iface.shutdown(with_restart)81 self.dbus_iface.shutdown(with_restart)
82
83 def connect(self):
84 self.dbus_iface.connect()
7185
=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
--- ubuntuone/platform/linux/dbus_interface.py 2010-12-09 13:38:46 +0000
+++ ubuntuone/platform/linux/dbus_interface.py 2010-12-10 22:10:15 +0000
@@ -1474,6 +1474,20 @@
1474 logger.debug('called files_sync_enabled')1474 logger.debug('called files_sync_enabled')
1475 return config.get_user_config().get_files_sync_enabled()1475 return config.get_user_config().get_files_sync_enabled()
14761476
1477 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
1478 in_signature='', out_signature='b')
1479 def autoconnect_enabled(self):
1480 """Return the autoconnect config value."""
1481 return config.get_user_config().get_autoconnect()
1482
1483 @dbus.service.method(DBUS_IFACE_CONFIG_NAME,
1484 in_signature='b', out_signature='')
1485 def set_autoconnect_enabled(self, enabled):
1486 """Enable syncdaemon autoconnect."""
1487 user_config = config.get_user_config()
1488 user_config.set_autoconnect(enabled)
1489 user_config.save()
1490
14771491
1478class Folders(DBusExposedObject):1492class Folders(DBusExposedObject):
1479 """A dbus interface to interact with User Defined Folders"""1493 """A dbus interface to interact with User Defined Folders"""
14801494
=== modified file 'ubuntuone/syncdaemon/config.py'
--- ubuntuone/syncdaemon/config.py 2010-08-11 14:05:23 +0000
+++ ubuntuone/syncdaemon/config.py 2010-12-10 22:10:15 +0000
@@ -343,6 +343,15 @@
343 def get_files_sync_enabled(self):343 def get_files_sync_enabled(self):
344 return self.get_parsed(MAIN, 'files_sync_enabled')344 return self.get_parsed(MAIN, 'files_sync_enabled')
345345
346 @requires_section(MAIN)
347 def set_autoconnect(self, enabled):
348 self.set(MAIN, 'autoconnect', str(enabled))
349
350 @requires_section(MAIN)
351 def get_autoconnect(self):
352 return self.get_parsed(MAIN, 'autoconnect')
353
354
346355
347def configglue(fileobj, *filenames, **kwargs):356def configglue(fileobj, *filenames, **kwargs):
348 """Populate an OptionParser with options and defaults taken from a357 """Populate an OptionParser with options and defaults taken from a
349358
=== modified file 'ubuntuone/syncdaemon/main.py'
--- ubuntuone/syncdaemon/main.py 2010-12-06 23:47:32 +0000
+++ ubuntuone/syncdaemon/main.py 2010-12-10 22:10:15 +0000
@@ -78,7 +78,7 @@
78 mark_interval=120, broadcast_events=False, handshake_timeout=30,78 mark_interval=120, broadcast_events=False, handshake_timeout=30,
79 shares_symlink_name='Shared With Me',79 shares_symlink_name='Shared With Me',
80 read_limit=None, write_limit=None, throttling_enabled=False,80 read_limit=None, write_limit=None, throttling_enabled=False,
81 ignore_files=None):81 ignore_files=None, oauth_credentials=None):
82 self.root_dir = root_dir82 self.root_dir = root_dir
83 self.shares_dir = shares_dir83 self.shares_dir = shares_dir
84 self.shares_dir_link = os.path.join(self.root_dir, shares_symlink_name)84 self.shares_dir_link = os.path.join(self.root_dir, shares_symlink_name)
@@ -122,6 +122,10 @@
122122
123 self.external = ubuntuone.platform.ExternalInterface(123 self.external = ubuntuone.platform.ExternalInterface(
124 self, glib_loop, broadcast_events)124 self, glib_loop, broadcast_events)
125 self.external.oauth_credentials = oauth_credentials
126 if user_config.get_autoconnect():
127 self.external.connect()
128
125 self.action_q.content_queue.set_change_notification_cb(129 self.action_q.content_queue.set_change_notification_cb(
126 self.external.change_notification)130 self.external.change_notification)
127 self.zg_listener = event_logging.ZeitgeistListener(self.fs, self.vm)131 self.zg_listener = event_logging.ZeitgeistListener(self.fs, self.vm)

Subscribers

People subscribed via source and target branches