Merge lp:~nataliabidart/ubuntuone-client/fix-u1sync into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: dobey
Approved revision: 689
Merged at revision: 688
Proposed branch: lp:~nataliabidart/ubuntuone-client/fix-u1sync
Merge into: lp:ubuntuone-client
Diff against target: 239 lines (+18/-104)
2 files modified
ubuntuone/u1sync/client.py (+11/-82)
ubuntuone/u1sync/main.py (+7/-22)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/fix-u1sync
Reviewer Review Type Date Requested Status
Lucio Torre (community) Approve
Facundo Batista (community) Approve
Review via email: mp+35023@code.launchpad.net

Commit message

* Made u1sync client work from the command line. No more "authorize" option, only --oauth (LP: #634337).

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

Thanks!

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

Please leave this as needs review for now. There are some issues with launchpad, and setting this to Approve will denote the wrong revision number for merging.

I've reported https://bugs.edge.launchpad.net/launchpad/+bug/634451 and bugged the LP hackers to get it fixed. Hopefully it will be fixed very shortly and we can go back about our normal lives.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/u1sync/client.py'
2--- ubuntuone/u1sync/client.py 2010-06-23 15:31:32 +0000
3+++ ubuntuone/u1sync/client.py 2010-09-10 02:20:59 +0000
4@@ -28,8 +28,6 @@
5 from Queue import Queue
6 from threading import Lock
7 import zlib
8-import urlparse
9-import ConfigParser
10 from cStringIO import StringIO
11
12 from twisted.internet import reactor, defer
13@@ -37,12 +35,11 @@
14 from ubuntuone.logger import LOGFOLDER
15 from ubuntuone.storageprotocol.content_hash import crc32
16 from ubuntuone.storageprotocol.context import get_ssl_context
17-from ubuntu_sso.config import get_config as get_oauth_config
18-from ubuntu_sso.auth import AuthorisationClient
19 from ubuntuone.u1sync.genericmerge import MergeNode
20 from ubuntuone.u1sync.utils import should_sync
21
22 CONSUMER_KEY = "ubuntuone"
23+CONSUMER_SECRET = "hammertime"
24
25 from oauth.oauth import OAuthConsumer
26 from ubuntuone.storageprotocol.client import (
27@@ -177,9 +174,12 @@
28 """U1 storage client facade."""
29 required_caps = frozenset(["no-content", "fix462230"])
30
31- def __init__(self, realm, reactor=reactor):
32- """Create the instance."""
33-
34+ def __init__(self, realm=None, reactor=reactor):
35+ """Create the instance.
36+
37+ 'realm' is no longer used, but is left as param for API compatibility.
38+
39+ """
40 self.reactor = reactor
41 self.factory = SyncClientFactory(self)
42
43@@ -189,37 +189,8 @@
44 self._status_waiting = []
45 self._active_waiters = set()
46
47- self.realm = realm
48-
49- oauth_config = get_oauth_config()
50- if oauth_config.has_section(realm):
51- config_section = realm
52- elif self.realm.startswith("http://localhost") and \
53- oauth_config.has_section("http://localhost"):
54- config_section = "http://localhost"
55- else:
56- config_section = "default"
57-
58- @log_timing
59- def get_oauth_option(option):
60- """Retrieves an option from oauth config."""
61- try:
62- return oauth_config.get(config_section, option)
63- except ConfigParser.NoOptionError:
64- return oauth_config.get("default", option)
65-
66- @log_timing
67- def get_oauth_url(option):
68- """Retrieves an absolutized URL from the OAuth config."""
69- suffix = get_oauth_option(option)
70- return urlparse.urljoin(realm, suffix)
71-
72 self.consumer_key = CONSUMER_KEY
73- self.consumer_secret = get_oauth_option("consumer_secret")
74-
75- self.request_token_url = get_oauth_url("request_token_url")
76- self.user_authorisation_url = get_oauth_url("user_authorisation_url")
77- self.access_token_url = get_oauth_url("access_token_url")
78+ self.consumer_secret = CONSUMER_SECRET
79
80 def force_shutdown(self):
81 """Forces the client to shut itself down."""
82@@ -256,49 +227,6 @@
83 self._active_waiters.remove(waiter)
84
85 @log_timing
86- def obtain_oauth_token(self, create_token):
87- """Obtains an oauth token, optionally creating one if requried."""
88- token_result = self._get_waiter()
89-
90- @log_timing
91- def have_token(token):
92- """When a token is available."""
93- token_result.wake(token)
94-
95- @log_timing
96- def no_token():
97- """When no token is available."""
98- token_result.wake(None)
99-
100- oauth_client = AuthorisationClient(realm=self.realm,
101- request_token_url=
102- self.request_token_url,
103- user_authorisation_url=
104- self.user_authorisation_url,
105- access_token_url=
106- self.access_token_url,
107- consumer_key=self.consumer_key,
108- consumer_secret=
109- self.consumer_secret,
110- callback_parent=have_token,
111- callback_denied=no_token,
112- do_login=create_token)
113-
114-
115- @log_timing
116- def _obtain_token():
117- """Obtains or creates a token."""
118- if create_token:
119- oauth_client.clear_token()
120- oauth_client.ensure_access_token()
121-
122- self.reactor.callFromThread(_obtain_token)
123- token = self._wait(token_result)
124- if token is None:
125- raise AuthenticationError("Unable to obtain OAuth token.")
126- return token
127-
128- @log_timing
129 def _change_status(self, status, reason=None):
130 """Changes the client status. Usually called from the reactor
131 thread.
132@@ -412,10 +340,11 @@
133 self._await_status_not("connecting", "connected", "authenticated")
134
135 @log_timing
136- def oauth_from_token(self, token):
137+ def oauth_from_token(self, token, consumer=None):
138 """Perform OAuth authorisation using an existing token."""
139
140- consumer = OAuthConsumer(self.consumer_key, self.consumer_secret)
141+ if consumer is None:
142+ consumer = OAuthConsumer(self.consumer_key, self.consumer_secret)
143
144 def _auth_successful(value):
145 """Callback for successful auth. Changes status to
146
147=== modified file 'ubuntuone/u1sync/main.py'
148--- ubuntuone/u1sync/main.py 2010-08-16 22:14:19 +0000
149+++ ubuntuone/u1sync/main.py 2010-09-10 02:20:59 +0000
150@@ -282,7 +282,6 @@
151 def do_main(argv):
152 """The main user-facing portion of the script."""
153 usage = "Usage: %prog [options] [DIRECTORY]\n" \
154- " %prog --authorize [options]\n" \
155 " %prog --list-shares [options]\n" \
156 " %prog --init [--share=SHARE_UUID] [options] DIRECTORY\n" \
157 " %prog --diff [--share=SHARE_UUID] [options] DIRECTORY"
158@@ -294,9 +293,7 @@
159 default='fs-1.one.ubuntu.com',
160 help="The server address")
161 parser.add_option("--oauth", dest="oauth", metavar="KEY:SECRET",
162- default=None,
163- help="Explicitly provide OAuth credentials "
164- "(default is to query keyring)")
165+ help="Explicitly provide OAuth credentials")
166 action_list = ", ".join(sorted(MERGE_ACTIONS.keys()))
167 parser.add_option("--action", dest="action", metavar="ACTION",
168 default=None,
169@@ -307,9 +304,6 @@
170 "making changes")
171 parser.add_option("--quiet", action="store_true", dest="quiet",
172 default=False, help="Produces less output")
173- parser.add_option("--authorize", action="store_const", dest="mode",
174- const="authorize",
175- help="Authorize this machine")
176 parser.add_option("--list-shares", action="store_const", dest="mode",
177 const="list-shares", default="sync",
178 help="List available shares")
179@@ -351,17 +345,14 @@
180 else:
181 directory = args[0]
182 if options.mode == "init" or options.mode == "list-shares" or \
183- options.mode == "diff" or options.mode == "authorize":
184+ options.mode == "diff":
185 if options.action is not None:
186 parser.error("--%s does not take the --action parameter" % \
187 options.mode)
188 if options.dry_run:
189 parser.error("--%s does not take the --dry-run parameter" % \
190 options.mode)
191- if options.mode == "authorize":
192- if options.oauth is not None:
193- parser.error("--authorize does not take the --oauth parameter")
194- if options.mode == "list-shares" or options.mode == "authorize":
195+ if options.mode == "list-shares":
196 if len(args) != 0:
197 parser.error("--list-shares does not take a directory")
198 if options.mode != "init" and options.mode != "diff":
199@@ -376,8 +367,9 @@
200 options.action = DEFAULT_MERGE_ACTION
201
202
203+ passed_token = None
204 if options.oauth is None:
205- passed_token = None
206+ parser.error("--oauth is required")
207 else:
208 try:
209 (key, secret) = options.oauth.split(':', 2)
210@@ -395,18 +387,14 @@
211 else:
212 share_spec = None
213
214- client = Client(realm=options.realm, reactor=reactor)
215+ client = Client(reactor=reactor)
216
217 signal.signal(signal.SIGINT, lambda s, f: client.force_shutdown())
218 signal.signal(signal.SIGTERM, lambda s, f: client.force_shutdown())
219
220 def run_client():
221 """Run the blocking client."""
222- if passed_token is None:
223- should_create_token = (options.mode == "authorize")
224- token = client.obtain_oauth_token(create_token=should_create_token)
225- else:
226- token = passed_token
227+ token = passed_token
228
229 client.connect_ssl(options.host, int(options.port), options.no_ssl_verify)
230
231@@ -429,9 +417,6 @@
232 directory=directory,
233 quiet=options.quiet, subtree_path=options.subtree,
234 ignore_symlinks=False)
235- elif options.mode == "authorize":
236- if not options.quiet:
237- print "Authorized."
238 finally:
239 client.disconnect()
240

Subscribers

People subscribed via source and target branches