395
399
share_spec = None
397
reactor_thread = Thread(target=
398
lambda: reactor.run(installSignalHandlers=False))
399
reactor_thread.setDaemon(True)
400
reactor_thread.start()
402
401
client = Client(realm=options.realm, reactor=reactor)
405
should_create_token = (options.mode == "authorize")
406
token = client.obtain_oauth_token(create_token=should_create_token)
408
client.connect_ssl(options.host, int(options.port), options.no_ssl_verify)
411
client.set_capabilities()
412
client.oauth_from_token(token)
414
if options.mode == "sync":
415
do_sync(client=client, directory=directory, action=options.action,
416
dry_run=options.dry_run, quiet=options.quiet)
417
elif options.mode == "init":
418
do_init(client=client, share_spec=share_spec, directory=directory,
419
quiet=options.quiet, subtree_path=options.subtree)
420
elif options.mode == "list-shares":
421
do_list_shares(client=client)
422
elif options.mode == "diff":
423
do_diff(client=client, share_spec=share_spec, directory=directory,
424
quiet=options.quiet, subtree_path=options.subtree,
425
ignore_symlinks=False)
426
elif options.mode == "authorize":
427
if not options.quiet:
403
signal.signal(signal.SIGINT, lambda s, f: client.force_shutdown())
404
signal.signal(signal.SIGTERM, lambda s, f: client.force_shutdown())
407
"""Run the blocking client."""
408
if passed_token is None:
409
should_create_token = (options.mode == "authorize")
410
token = client.obtain_oauth_token(create_token=should_create_token)
414
client.connect_ssl(options.host, int(options.port), options.no_ssl_verify)
417
client.set_capabilities()
418
client.oauth_from_token(token)
420
if options.mode == "sync":
421
do_sync(client=client, directory=directory,
422
action=options.action,
423
dry_run=options.dry_run, quiet=options.quiet)
424
elif options.mode == "init":
425
do_init(client=client, share_spec=share_spec,
427
quiet=options.quiet, subtree_path=options.subtree)
428
elif options.mode == "list-shares":
429
do_list_shares(client=client)
430
elif options.mode == "diff":
431
do_diff(client=client, share_spec=share_spec,
433
quiet=options.quiet, subtree_path=options.subtree,
434
ignore_symlinks=False)
435
elif options.mode == "authorize":
436
if not options.quiet:
431
439
client.disconnect()
441
def capture_exception(queue, func):
442
"""Capture the exception from calling func."""
446
queue.put(sys.exc_info())
433
450
reactor.callWhenRunning(reactor.stop)
434
reactor_thread.join(1.0)
453
reactor.callInThread(capture_exception, queue, run_client)
454
reactor.run(installSignalHandlers=False)
455
exc_info = queue.get(True, 0.1)
457
raise exc_info[0], exc_info[1], exc_info[2]
437
460
"""Top-level main function."""