Merge lp:~nataliabidart/ubuntuone-client/not-autoconnect-if-no-tokens into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 807
Merged at revision: 806
Proposed branch: lp:~nataliabidart/ubuntuone-client/not-autoconnect-if-no-tokens
Merge into: lp:ubuntuone-client
Diff against target: 469 lines (+99/-112)
6 files modified
contrib/testing/testcase.py (+1/-1)
tests/platform/linux/test_dbus.py (+66/-78)
tests/syncdaemon/test_main.py (+5/-4)
ubuntuone/platform/linux/__init__.py (+2/-2)
ubuntuone/platform/linux/dbus_interface.py (+22/-25)
ubuntuone/syncdaemon/main.py (+3/-2)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/not-autoconnect-if-no-tokens
Reviewer Review Type Date Requested Status
Lucio Torre (community) Approve
Roberto Alsina (community) Approve
dobey (community) Needs Information
Review via email: mp+46196@code.launchpad.net

Commit message

Syncdaemon should get credentials using find_credentials, not calling register which may raise a GUI our of nowhere (LP: #701588).

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

So does this stop autoconnecting when there are no tokens, or does it just change it so that if you don't have a token, you won't be able to register when it connects. This seems like the wrong fix to the bug to me.

review: Needs Information
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

This will make syncdaemon to continue autoconnecting if the token is already in the keyring.
If not, it will do nothing, since the point of entry to the service should be some other (usually) UI app.

Revision history for this message
dobey (dobey) wrote :

That's what I thought. It doesn't solve the bug, but works around it. I think the correct fix wold be to make ubuntuone-launch not start ubuntuone-syncdaemon if there is no token yet (it used to do that), and perhaps to make syncdaemon not try to connect automatically if there is no token, but if a connect() is explicitly requested, with no token, I think the register() call is still the right one to make. No?

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1 as discussed on IRC

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

The bug to track down why syncdaemon is started if the user doesn't have a U1 account is located at:

bug #702902

Revision history for this message
Lucio Torre (lucio.torre) wrote :

+1

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :
Download full text (183.0 KiB)

The attempt to merge lp:~nataliabidart/ubuntuone-client/not-autoconnect-if-no-tokens into lp:ubuntuone-client failed. Below is the output from the failed tests.

/usr/bin/gnome-autogen.sh
checking for autoconf >= 2.53...
(B testing autoconf2.50... not found.
  testing autoconf... found 2.67
checking for automake >= 1.10...
(B testing automake-1.11... found 1.11.1
checking for libtool >= 1.5...
(B testing libtoolize... found 2.2.6b
checking for intltool >= 0.30...
(B testing intltoolize... found 0.41.1
checking for pkg-config >= 0.14.0...
(B testing pkg-config... found 0.25
checking for gtk-doc >= 1.0...
(B testing gtkdocize... found 1.15
Checking for required M4 macros...
(BChecking for forbidden M4 macros...
(BProcessing ./configure.ac
(BRunning libtoolize...
(Blibtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running intltoolize...
(BRunning gtkdocize...
(BRunning aclocal-1.11...
(BRunning autoconf...
(BRunning autoheader...
(BRunning automake-1.11...
(BRunning ./configure --enable-gtk-doc --enable-debug --with-protocol=~/canonical/ubuntuone-storage-protocol/trunk/ ...
(Bchecking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864...

806. By Natalia Bidart

Merged trunk in.

807. By Natalia Bidart

Making tests pass.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'contrib/testing/testcase.py'
--- contrib/testing/testcase.py 2010-12-16 14:35:23 +0000
+++ contrib/testing/testcase.py 2011-01-14 20:00:42 +0000
@@ -96,7 +96,7 @@
96 def shutdown(self, with_restart=False):96 def shutdown(self, with_restart=False):
97 """...that only knows how to go away"""97 """...that only knows how to go away"""
9898
99 def _request_token(self):99 def _request_token(self, *args, **kwargs):
100 """Return a token which is a fixed set of credentials."""100 """Return a token which is a fixed set of credentials."""
101 return FAKED_CREDENTIALS101 return FAKED_CREDENTIALS
102102
103103
=== modified file 'tests/platform/linux/test_dbus.py'
--- tests/platform/linux/test_dbus.py 2011-01-07 17:24:11 +0000
+++ tests/platform/linux/test_dbus.py 2011-01-14 20:00:42 +0000
@@ -34,7 +34,6 @@
34 BaseTwistedTestCase, FakeMain, FAKED_CREDENTIALS,34 BaseTwistedTestCase, FakeMain, FAKED_CREDENTIALS,
35 MementoHandler)35 MementoHandler)
3636
37from ubuntuone.clientdefs import APP_NAME
38from ubuntuone.storageprotocol.sharersp import NotifyShareHolder37from ubuntuone.storageprotocol.sharersp import NotifyShareHolder
39from ubuntuone.syncdaemon import states, config38from ubuntuone.syncdaemon import states, config
40from ubuntuone.platform.linux.dbus_interface import (39from ubuntuone.platform.linux.dbus_interface import (
@@ -97,13 +96,14 @@
97 """96 """
98 self.next_login_cb = (callback, args)97 self.next_login_cb = (callback, args)
9998
99
100class FakeDBusInterface(object):100class FakeDBusInterface(object):
101 """A fake DBusInterface..."""101 """A fake DBusInterface..."""
102102
103 def shutdown(self, with_restart=False):103 def shutdown(self, with_restart=False):
104 """...that only knows how to go away"""104 """...that only knows how to go away"""
105105
106 def _request_token(self):106 def _request_token(self, *args, **kwargs):
107 """Return a token which is a fixed set of credentials."""107 """Return a token which is a fixed set of credentials."""
108 return FAKED_CREDENTIALS108 return FAKED_CREDENTIALS
109109
@@ -136,7 +136,7 @@
136 self.dbus_iface = DBusInterface(self.bus, self.main,136 self.dbus_iface = DBusInterface(self.bus, self.main,
137 system_bus=self.bus)137 system_bus=self.bus)
138 # token is a fixed set of credentials138 # token is a fixed set of credentials
139 self.dbus_iface._request_token = lambda: FAKED_CREDENTIALS139 self.dbus_iface._request_token = lambda *a, **kw: FAKED_CREDENTIALS
140140
141 self.main.external = ExternalInterface(self.main, False, False,141 self.main.external = ExternalInterface(self.main, False, False,
142 dbus_iface=self.dbus_iface)142 dbus_iface=self.dbus_iface)
@@ -317,6 +317,10 @@
317 """Fake register."""317 """Fake register."""
318 self._called['register'] = (args, kwargs)318 self._called['register'] = (args, kwargs)
319319
320 def find_credentials(self, *args, **kwargs):
321 """Fake find_credentials."""
322 self._called['find_credentials'] = (args, kwargs)
323
320324
321class FakedBusName(object):325class FakedBusName(object):
322 """Fake a dbus name."""326 """Fake a dbus name."""
@@ -2493,9 +2497,15 @@
24932497
24942498
2495class DBusOAuthTestCase(BaseTwistedTestCase):2499class DBusOAuthTestCase(BaseTwistedTestCase):
2496 """Tests the interaction between dbus_interface and ubuntu-sso-client."""2500 """Tests the interaction between dbus_interface and credentials.
2501
2502 Check conditions when autconnecting is False.
2503
2504 """
24972505
2498 timeout = 22506 timeout = 2
2507 method = 'register'
2508 autoconnecting = False
24992509
2500 def setUp(self):2510 def setUp(self):
2501 """Init."""2511 """Init."""
@@ -2539,8 +2549,8 @@
2539 self.assertEqual(self.dbus_iface._signal_handler, cb)2549 self.assertEqual(self.dbus_iface._signal_handler, cb)
2540 self.dbus_iface._deferred.callback(None)2550 self.dbus_iface._deferred.callback(None)
25412551
2542 self.patch(FakedSSOBackend, 'register', f)2552 self.patch(FakedSSOBackend, self.method, f)
2543 yield self.dbus_iface.connect()2553 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
25442554
2545 @defer.inlineCallbacks2555 @defer.inlineCallbacks
2546 def test_signals_are_removed_after_connection(self):2556 def test_signals_are_removed_after_connection(self):
@@ -2550,8 +2560,8 @@
2550 """Just succeed."""2560 """Just succeed."""
2551 self.dbus_iface._deferred.callback(None)2561 self.dbus_iface._deferred.callback(None)
25522562
2553 self.patch(FakedSSOBackend, 'register', f)2563 self.patch(FakedSSOBackend, self.method, f)
2554 yield self.dbus_iface.connect()2564 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2555 self.assertNotIn((DBUS_CREDENTIALS_IFACE, None), self.bus.callbacks)2565 self.assertNotIn((DBUS_CREDENTIALS_IFACE, None), self.bus.callbacks)
25562566
2557 @defer.inlineCallbacks2567 @defer.inlineCallbacks
@@ -2560,11 +2570,11 @@
25602570
2561 def f(*a, **kw):2571 def f(*a, **kw):
2562 """Receive credentials."""2572 """Receive credentials."""
2563 self.dbus_iface._signal_handler(APP_NAME, FAKED_CREDENTIALS,2573 self.dbus_iface._signal_handler(FAKED_CREDENTIALS,
2564 member='CredentialsFound')2574 member='CredentialsFound')
25652575
2566 self.patch(FakedSSOBackend, 'register', f)2576 self.patch(FakedSSOBackend, self.method, f)
2567 yield self.dbus_iface.connect()2577 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2568 self.assertEqual(self.events, [('SYS_USER_CONNECT',2578 self.assertEqual(self.events, [('SYS_USER_CONNECT',
2569 {'access_token': FAKED_CREDENTIALS})])2579 {'access_token': FAKED_CREDENTIALS})])
25702580
@@ -2574,12 +2584,12 @@
25742584
2575 def f(*a, **kw):2585 def f(*a, **kw):
2576 """Receive error signal."""2586 """Receive error signal."""
2577 self.dbus_iface._signal_handler(APP_NAME, 'Error description',2587 self.dbus_iface._signal_handler({'error_type': 'Error description',
2578 'Detailed error',2588 'error_detail': 'Detailed error'},
2579 member='CredentialsError')2589 member='CredentialsError')
25802590
2581 self.patch(FakedSSOBackend, 'register', f)2591 self.patch(FakedSSOBackend, self.method, f)
2582 d = self.dbus_iface.connect()2592 d = self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2583 d.addErrback(lambda failure: self.assertEqual(NoAccessToken,2593 d.addErrback(lambda failure: self.assertEqual(NoAccessToken,
2584 failure.type))2594 failure.type))
2585 yield d2595 yield d
@@ -2590,11 +2600,24 @@
25902600
2591 def f(*a, **kw):2601 def f(*a, **kw):
2592 """Receive error signal."""2602 """Receive error signal."""
2593 self.dbus_iface._signal_handler(APP_NAME,2603 self.dbus_iface._signal_handler(member='AuthorizationDenied')
2594 member='AuthorizationDenied')2604
25952605 self.patch(FakedSSOBackend, self.method, f)
2596 self.patch(FakedSSOBackend, 'register', f)2606 d = self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2597 d = self.dbus_iface.connect()2607 d.addErrback(lambda failure: self.assertEqual(NoAccessToken,
2608 failure.type))
2609 yield d
2610
2611 @defer.inlineCallbacks
2612 def test_connect_raises_NoAccessToken_if_no_creds(self):
2613 """If no credentials, NoAccessToken if no credentials."""
2614
2615 def f(*a, **kw):
2616 """Receive error signal."""
2617 self.dbus_iface._signal_handler(member='CredentialsNotFound')
2618
2619 self.patch(FakedSSOBackend, self.method, f)
2620 d = self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2598 d.addErrback(lambda failure: self.assertEqual(NoAccessToken,2621 d.addErrback(lambda failure: self.assertEqual(NoAccessToken,
2599 failure.type))2622 failure.type))
2600 yield d2623 yield d
@@ -2608,8 +2631,8 @@
2608 """Just fail."""2631 """Just fail."""
2609 raise expected2632 raise expected
26102633
2611 self.patch(FakedSSOBackend, 'register', f)2634 self.patch(FakedSSOBackend, self.method, f)
2612 d = self.dbus_iface.connect()2635 d = self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2613 d.addErrback(lambda failure: self.assertEqual(expected, failure.value))2636 d.addErrback(lambda failure: self.assertEqual(expected, failure.value))
2614 yield d2637 yield d
26152638
@@ -2622,14 +2645,15 @@
2622 """Just fail."""2645 """Just fail."""
2623 raise expected2646 raise expected
26242647
2625 self.patch(FakedSSOBackend, 'register', f)2648 self.patch(FakedSSOBackend, self.method, f)
2626 d = self.dbus_iface.connect()2649 d = self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2627 d.addErrback(lambda failure: self.assertEqual(expected, failure.value))2650 d.addErrback(lambda failure: self.assertEqual(expected, failure.value))
2628 yield d2651 yield d
2629 self.assertTrue(len(self.memento.records) > 0)2652 self.assertTrue(len(self.memento.records) > 0)
2630 msg = self.memento.records[0].message2653 record = self.memento.records[1]
2654 msg = record.message
2631 self.assertIn('connect failed while getting the token', msg)2655 self.assertIn('connect failed while getting the token', msg)
2632 self.assertIn(expected, self.memento.records[0].exc_info)2656 self.assertIn(expected, record.exc_info)
26332657
2634 def test_oauth_credentials_are_none_at_startup(self):2658 def test_oauth_credentials_are_none_at_startup(self):
2635 """If the oauth_credentials are not passed as param, they are None."""2659 """If the oauth_credentials are not passed as param, they are None."""
@@ -2644,7 +2668,7 @@
2644 'token_secret': 'faked_token_secret'}2668 'token_secret': 'faked_token_secret'}
2645 self.dbus_iface.oauth_credentials = (expected['token'],2669 self.dbus_iface.oauth_credentials = (expected['token'],
2646 expected['token_secret'])2670 expected['token_secret'])
2647 yield self.dbus_iface.connect()2671 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2648 self.assertEqual(self.events, [('SYS_USER_CONNECT',2672 self.assertEqual(self.events, [('SYS_USER_CONNECT',
2649 {'access_token': expected})])2673 {'access_token': expected})])
26502674
@@ -2659,7 +2683,7 @@
2659 expected['consumer_secret'],2683 expected['consumer_secret'],
2660 expected['token'],2684 expected['token'],
2661 expected['token_secret'])2685 expected['token_secret'])
2662 yield self.dbus_iface.connect()2686 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2663 self.assertEqual(self.events, [('SYS_USER_CONNECT',2687 self.assertEqual(self.events, [('SYS_USER_CONNECT',
2664 {'access_token': expected})])2688 {'access_token': expected})])
26652689
@@ -2669,67 +2693,31 @@
2669 self.dbus_iface.oauth_credentials = ('consumer_key',2693 self.dbus_iface.oauth_credentials = ('consumer_key',
2670 'consumer_secret',2694 'consumer_secret',
2671 'token_secret')2695 'token_secret')
2672 yield self.dbus_iface.connect()2696 yield self.dbus_iface.connect(autoconnecting=self.autoconnecting)
2673 self.assertEqual(self.events, [])2697 self.assertEqual(self.events, [])
2674 msgs = (str(self.dbus_iface.oauth_credentials), 'useless')2698 msgs = (str(self.dbus_iface.oauth_credentials), 'useless')
2675 self.assertTrue(self.memento.check_warning(*msgs))2699 self.assertTrue(self.memento.check_warning(*msgs))
26762700
2677 def test_only_log_if_app_name_is_not_correct_when_credentials_found(self):
2678 """If the app_name is not ours, just log an INFO message."""
2679
2680 def f(*a, **kw):
2681 """Receive wrong app_name."""
2682 self.dbus_iface._signal_handler(APP_NAME * 2,
2683 member='CredentialsFound')
2684
2685 self.patch(FakedSSOBackend, 'register', f)
2686 self.dbus_iface._request_token()
2687
2688 self.assertFalse(self.dbus_iface._deferred.called)
2689 self.assertTrue(self.memento.check_info('CredentialsFound',
2690 APP_NAME * 2))
2691
2692 def test_only_log_if_app_name_is_not_correct_when_credentials_error(self):
2693 """If the app_name is not ours, just log an INFO message."""
2694
2695 def f(*a, **kw):
2696 """Receive a wrong app_name."""
2697 self.dbus_iface._signal_handler(APP_NAME * 2,
2698 member='CredentialsError')
2699
2700 self.patch(FakedSSOBackend, 'register', f)
2701 self.dbus_iface._request_token()
2702
2703 self.assertFalse(self.dbus_iface._deferred.called)
2704 self.assertTrue(self.memento.check_info('CredentialsError',
2705 APP_NAME * 2))
2706
2707 def test_only_log_if_app_name_is_not_correct_when_authorization_denied(self):
2708 """If the app_name is not ours, just log an INFO message."""
2709
2710 def f(*a, **kw):
2711 """Receive a wrong app_name."""
2712 self.dbus_iface._signal_handler(APP_NAME * 2,
2713 member='AuthorizationDenied')
2714
2715 self.patch(FakedSSOBackend, 'register', f)
2716 self.dbus_iface._request_token()
2717
2718 self.assertFalse(self.dbus_iface._deferred.called)
2719 self.assertTrue(self.memento.check_info('AuthorizationDenied',
2720 APP_NAME * 2))
2721
2722 def test_signal_handler_remains_generic(self):2701 def test_signal_handler_remains_generic(self):
2723 """The signal handler function should be generic."""2702 """The signal handler function should be generic."""
2724 self.dbus_iface._signal_handler()2703 self.dbus_iface._signal_handler()
2725 # no failure2704 # no failure
2726 self.assertTrue(self.memento.check_debug('member: None',2705 self.assertTrue(self.memento.check_debug('member: None'))
2727 'app_name: None'))
27282706
2729 self.dbus_iface._signal_handler(no_member_kwarg='Test')2707 self.dbus_iface._signal_handler(no_member_kwarg='Test')
2730 # no failure2708 # no failure
2731 self.assertTrue(self.memento.check_debug('member: None',2709 self.assertTrue(self.memento.check_debug('member: None'))
2732 'app_name: None'))2710
2711
2712class DBusOAuthTestCaseRegister(DBusOAuthTestCase):
2713 """Tests the interaction between dbus_interface and credentials.
2714
2715 Check conditions when autconnecting is True.
2716
2717 """
2718
2719 method = 'find_credentials'
2720 autoconnecting = True
27332721
27342722
2735class FolderTests(DBusTwistedTestCase):2723class FolderTests(DBusTwistedTestCase):
27362724
=== modified file 'tests/syncdaemon/test_main.py'
--- tests/syncdaemon/test_main.py 2010-12-17 18:19:41 +0000
+++ tests/syncdaemon/test_main.py 2011-01-14 20:00:42 +0000
@@ -101,7 +101,7 @@
101 """Pass the test when we get this event."""101 """Pass the test when we get this event."""
102 reactor.callLater(0, d0.callback, None)102 reactor.callLater(0, d0.callback, None)
103103
104 main = self.build_main(handshake_timeout=.5)104 main = self.build_main(handshake_timeout=0)
105105
106 def fake_connect(*a):106 def fake_connect(*a):
107 """Only connect when States told so."""107 """Only connect when States told so."""
@@ -183,12 +183,13 @@
183183
184 self.connect_called = False184 self.connect_called = False
185 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',185 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',
186 lambda *a: setattr(self, 'connect_called', True))186 lambda *a, **kw: setattr(self, 'connect_called', (a, kw)))
187187
188 main = self.build_main()188 main = self.build_main()
189 self.addCleanup(lambda: main.shutdown())189 self.addCleanup(lambda: main.shutdown())
190190
191 self.assertTrue(self.connect_called)191 self.assertEqual(self.connect_called, ((main.external,),
192 {'autoconnecting': True}))
192193
193 def test_dont_connect_if_autoconnect_is_disabled(self):194 def test_dont_connect_if_autoconnect_is_disabled(self):
194 """If autoconnect option is disabled, do not connect the syncdaemon."""195 """If autoconnect option is disabled, do not connect the syncdaemon."""
@@ -199,7 +200,7 @@
199200
200 self.connect_called = False201 self.connect_called = False
201 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',202 self.patch(main_mod.ubuntuone.platform.ExternalInterface, 'connect',
202 lambda *a: setattr(self, 'connect_called', True))203 lambda *a, **kw: setattr(self, 'connect_called', True))
203204
204 main = self.build_main()205 main = self.build_main()
205 self.addCleanup(lambda: main.shutdown())206 self.addCleanup(lambda: main.shutdown())
206207
=== modified file 'ubuntuone/platform/linux/__init__.py'
--- ubuntuone/platform/linux/__init__.py 2010-12-20 12:28:01 +0000
+++ ubuntuone/platform/linux/__init__.py 2011-01-14 20:00:42 +0000
@@ -83,5 +83,5 @@
83 def shutdown(self, with_restart):83 def shutdown(self, with_restart):
84 self.dbus_iface.shutdown(with_restart)84 self.dbus_iface.shutdown(with_restart)
8585
86 def connect(self):86 def connect(self, *args, **kwargs):
87 self.dbus_iface.connect()87 self.dbus_iface.connect(*args, **kwargs)
8888
=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
--- ubuntuone/platform/linux/dbus_interface.py 2011-01-06 13:54:21 +0000
+++ ubuntuone/platform/linux/dbus_interface.py 2011-01-14 20:00:42 +0000
@@ -27,10 +27,8 @@
2727
28from twisted.internet import defer28from twisted.internet import defer
29from twisted.python.failure import Failure29from twisted.python.failure import Failure
30from ubuntu_sso import (DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,30from ubuntuone.credentials import (DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,
31 DBUS_CREDENTIALS_IFACE)31 DBUS_CREDENTIALS_IFACE)
32from ubuntu_sso.credentials import (HELP_TEXT_KEY, PING_URL_KEY, TC_URL_KEY,
33 WINDOW_ID_KEY)
34from ubuntuone.syncdaemon.interfaces import IMarker32from ubuntuone.syncdaemon.interfaces import IMarker
35from ubuntuone.syncdaemon import config33from ubuntuone.syncdaemon import config
3634
@@ -1847,12 +1845,16 @@
1847 self.event_queue.push(event)1845 self.event_queue.push(event)
18481846
1849 @defer.inlineCallbacks1847 @defer.inlineCallbacks
1850 def connect(self):1848 def connect(self, autoconnecting=False):
1851 """Push the SYS_USER_CONNECT event with the token.1849 """Push the SYS_USER_CONNECT event with the token.
18521850
1853 The token is requested via ubuntu-sso-client.1851 The token is requested via com.ubuntuone.credentials service. If
1852 'autoconnecting' is True, no UI window will be raised to promt the user
1853 for login/registration, only already existent credentials will be used.
18541854
1855 """1855 """
1856 logger.info('connect was requested. Are we autoconnecting? %r.',
1857 autoconnecting)
1856 if self.oauth_credentials is not None:1858 if self.oauth_credentials is not None:
1857 logger.debug('connect: oauth credentials were given by parameter.')1859 logger.debug('connect: oauth credentials were given by parameter.')
1858 ckey = csecret = key = secret = None1860 ckey = csecret = key = secret = None
@@ -1868,7 +1870,7 @@
1868 token = {'consumer_key': ckey, 'consumer_secret': csecret,1870 token = {'consumer_key': ckey, 'consumer_secret': csecret,
1869 'token': key, 'token_secret': secret}1871 'token': key, 'token_secret': secret}
1870 else:1872 else:
1871 token = yield self._request_token()1873 token = yield self._request_token(autoconnecting=autoconnecting)
18721874
1873 logger.info('connect: credential request was successful, '1875 logger.info('connect: credential request was successful, '
1874 'pushing SYS_USER_CONNECT.')1876 'pushing SYS_USER_CONNECT.')
@@ -1877,17 +1879,11 @@
1877 def _signal_handler(self, *args, **kwargs):1879 def _signal_handler(self, *args, **kwargs):
1878 """Generic signal handler."""1880 """Generic signal handler."""
1879 member = kwargs.get('member', None)1881 member = kwargs.get('member', None)
1880 app_name = args[0] if len(args) > 0 else None
1881 d = self._deferred1882 d = self._deferred
1882 logger.debug('Handling DBus signal for member: %r, app_name: %r.',1883 logger.debug('Handling DBus signal for member: %r.', member)
1883 member, app_name)1884
18841885 if member in ('CredentialsError', 'AuthorizationDenied',
1885 if app_name != APP_NAME:1886 'CredentialsNotFound'):
1886 logger.info('Received %s but app_name %s does not match %s, ' \
1887 'exiting.', member, app_name, APP_NAME)
1888 return
1889
1890 if member in ('CredentialsError', 'AuthorizationDenied'):
1891 logger.warning('%r: %r %r', member, args, kwargs)1887 logger.warning('%r: %r %r', member, args, kwargs)
1892 if not args:1888 if not args:
1893 d.errback(Failure(NoAccessToken(member)))1889 d.errback(Failure(NoAccessToken(member)))
@@ -1895,14 +1891,14 @@
1895 d.errback(Failure(NoAccessToken("%s: %s %s" %1891 d.errback(Failure(NoAccessToken("%s: %s %s" %
1896 (member, args, kwargs))))1892 (member, args, kwargs))))
1897 elif member == 'CredentialsFound' and not d.called:1893 elif member == 'CredentialsFound' and not d.called:
1898 credentials = args[1]1894 credentials = args[0]
1899 logger.info('%r: callbacking with credentials.', member)1895 logger.info('%r: callbacking with credentials.', member)
1900 d.callback(credentials)1896 d.callback(credentials)
1901 else:1897 else:
1902 logger.debug('_signal_handler: member %r not used or deferred '1898 logger.debug('_signal_handler: member %r not used or deferred '
1903 'already called? %r.', member, d.called)1899 'already called? %r.', member, d)
19041900
1905 def _request_token(self):1901 def _request_token(self, autoconnecting):
1906 """Request to SSO auth service to fetch the token."""1902 """Request to SSO auth service to fetch the token."""
1907 self._deferred = d = defer.Deferred()1903 self._deferred = d = defer.Deferred()
19081904
@@ -1921,12 +1917,13 @@
1921 client = self.bus.get_object(DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,1917 client = self.bus.get_object(DBUS_BUS_NAME, DBUS_CREDENTIALS_PATH,
1922 follow_name_owner_changes=True)1918 follow_name_owner_changes=True)
1923 iface = dbus.Interface(client, DBUS_CREDENTIALS_IFACE)1919 iface = dbus.Interface(client, DBUS_CREDENTIALS_IFACE)
1924 params = {HELP_TEXT_KEY: DESCRIPTION, TC_URL_KEY: TC_URL,1920 # ignore the reply, we get the result via signals
1925 PING_URL_KEY: PING_URL, WINDOW_ID_KEY: '0'}1921 if autoconnecting:
1926 iface.register(APP_NAME, params,1922 iface.find_credentials(reply_handler=lambda: None,
1927 # ignore the reply, we get the result via signals1923 error_handler=error_handler)
1928 reply_handler=lambda: None,1924 else:
1929 error_handler=error_handler)1925 iface.register(reply_handler=lambda: None,
1926 error_handler=error_handler)
1930 except DBusException, e:1927 except DBusException, e:
1931 error_handler(e)1928 error_handler(e)
1932 except:1929 except:
19331930
=== modified file 'ubuntuone/syncdaemon/main.py'
--- ubuntuone/syncdaemon/main.py 2011-01-07 18:51:45 +0000
+++ ubuntuone/syncdaemon/main.py 2011-01-14 20:00:42 +0000
@@ -74,7 +74,8 @@
74 def __init__(self, root_dir, shares_dir, data_dir, partials_dir,74 def __init__(self, root_dir, shares_dir, data_dir, partials_dir,
75 host='fs-1.one.ubuntu.com', port=443, dns_srv=None, ssl=True,75 host='fs-1.one.ubuntu.com', port=443, dns_srv=None, ssl=True,
76 disable_ssl_verify=False, glib_loop=False,76 disable_ssl_verify=False, glib_loop=False,
77 mark_interval=120, broadcast_events=False, handshake_timeout=30,77 mark_interval=120, broadcast_events=False,
78 handshake_timeout=30,
78 shares_symlink_name='Shared With Me',79 shares_symlink_name='Shared With Me',
79 read_limit=None, write_limit=None, throttling_enabled=False,80 read_limit=None, write_limit=None, throttling_enabled=False,
80 ignore_files=None, oauth_credentials=None):81 ignore_files=None, oauth_credentials=None):
@@ -125,7 +126,7 @@
125 self, glib_loop, broadcast_events)126 self, glib_loop, broadcast_events)
126 self.external.oauth_credentials = oauth_credentials127 self.external.oauth_credentials = oauth_credentials
127 if user_config.get_autoconnect():128 if user_config.get_autoconnect():
128 self.external.connect()129 self.external.connect(autoconnecting=True)
129130
130 self.action_q.content_queue.set_change_notification_cb(131 self.action_q.content_queue.set_change_notification_cb(
131 self.external.change_notification)132 self.external.change_notification)

Subscribers

People subscribed via source and target branches