~rye/ubuntuone-client/unique-check-is-unique

« back to all changes in this revision

Viewing changes to ubuntuone/u1sync/main.py

  • Committer: Tarmac
  • Author(s): natalia.bidart at canonical
  • Date: 2010-09-13 19:50:59 UTC
  • mfrom: (689.2.5 extend-oauth)
  • Revision ID: tarmac-20100913195059-bf861mvwpfddrwuc
OAuth consumer key and secret can be passed as parameter (LP: #637022).

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from twisted.internet import reactor
36
36
from Queue import Queue
37
37
 
38
 
from oauth.oauth import OAuthToken
 
38
from oauth.oauth import OAuthToken, OAuthConsumer
39
39
import ubuntuone.storageprotocol.dircontent_pb2 as dircontent_pb2
40
40
from ubuntuone.storageprotocol.dircontent_pb2 import DIRECTORY, SYMLINK
41
41
from ubuntuone.u1sync.genericmerge import (
292
292
    parser.add_option("--host", dest="host", metavar="HOST",
293
293
                      default='fs-1.one.ubuntu.com',
294
294
                      help="The server address")
295
 
    parser.add_option("--oauth", dest="oauth", metavar="KEY:SECRET",
296
 
                      help="Explicitly provide OAuth credentials")
 
295
 
 
296
    oauth_meta_var = "[CONSUMER_KEY:CONSUMER_SECRET:]KEY:SECRET"
 
297
    oauth_help = "Explicitly provide OAuth credentials. You can either " \
 
298
                 "provide the 4 values (consumer key and secret, plus the " \
 
299
                 "key and secret), or just the last two (key and secret)."
 
300
    parser.add_option("--oauth", dest="oauth", metavar=oauth_meta_var,
 
301
                      help=oauth_help)
297
302
    action_list = ", ".join(sorted(MERGE_ACTIONS.keys()))
298
303
    parser.add_option("--action", dest="action", metavar="ACTION",
299
304
                      default=None,
367
372
        options.action = DEFAULT_MERGE_ACTION
368
373
 
369
374
 
370
 
    passed_token = None
 
375
    token = None
 
376
    consumer = None
371
377
    if options.oauth is None:
372
378
        parser.error("--oauth is required")
373
379
    else:
374
 
        try:
375
 
            (key, secret) = options.oauth.split(':', 2)
376
 
        except ValueError:
377
 
            parser.error("--oauth requires a key and secret together in the "
378
 
                         " form KEY:SECRET")
379
 
        passed_token = OAuthToken(key, secret)
 
380
        values = options.oauth.split(':')
 
381
        if len(values) == 4:
 
382
            (consumer_key, consumer_secret, key, secret) = values
 
383
            consumer = OAuthConsumer(consumer_key, consumer_secret)
 
384
        elif len(values) == 2:
 
385
            (key, secret) = values
 
386
        else:
 
387
            parser.error("--oauth requires %s" % oauth_meta_var)
 
388
        token = OAuthToken(key, secret)
380
389
 
381
390
    if options.share is not None:
382
391
        try:
394
403
 
395
404
    def run_client():
396
405
        """Run the blocking client."""
397
 
        token = passed_token
398
 
 
399
406
        client.connect_ssl(options.host, int(options.port), options.no_ssl_verify)
400
407
 
401
408
        try:
402
409
            client.set_capabilities()
403
 
            client.oauth_from_token(token)
 
410
            client.oauth_from_token(token, consumer)
404
411
 
405
412
            if options.mode == "sync":
406
413
                do_sync(client=client, directory=directory,