Remove usages of click.pass_context

And fix some bugs in doubleclick's obj proxy
This commit is contained in:
Markus Unterwaditzer 2015-05-25 14:14:03 +02:00
parent 3aa27f6d37
commit c2a50d76a4
2 changed files with 10 additions and 14 deletions

View file

@ -7,7 +7,7 @@ from .tasks import discover_collections, repair_collection, sync_pair
from .utils import CliError, WorkerQueue, cli_logger, handle_cli_error, \ from .utils import CliError, WorkerQueue, cli_logger, handle_cli_error, \
load_config, parse_pairs_args load_config, parse_pairs_args
from .. import __version__, log from .. import __version__, log
from ..doubleclick import click from ..doubleclick import click, ctx
def catch_errors(f): def catch_errors(f):
@ -36,9 +36,8 @@ def validate_verbosity(ctx, param, value):
callback=validate_verbosity, callback=validate_verbosity,
help='Either CRITICAL, ERROR, WARNING, INFO or DEBUG') help='Either CRITICAL, ERROR, WARNING, INFO or DEBUG')
@click.version_option(version=__version__) @click.version_option(version=__version__)
@click.pass_context
@catch_errors @catch_errors
def app(ctx, verbosity): def app(verbosity):
''' '''
vdirsyncer -- synchronize calendars and contacts vdirsyncer -- synchronize calendars and contacts
''' '''
@ -77,12 +76,11 @@ max_workers_option = click.option(
help=('Do/Don\'t abort synchronization when all items are about ' help=('Do/Don\'t abort synchronization when all items are about '
'to be deleted from both sides.')) 'to be deleted from both sides.'))
@max_workers_option @max_workers_option
@click.pass_context
@catch_errors @catch_errors
def sync(ctx, pairs, force_delete, max_workers): def sync(pairs, force_delete, max_workers):
''' '''
Synchronize the given collections or pairs. If no arguments are given, Synchronize the given pairs. If no arguments are given, all will be
all will be synchronized. synchronized.
`vdirsyncer sync` will sync everything configured. `vdirsyncer sync` will sync everything configured.
@ -111,9 +109,8 @@ def sync(ctx, pairs, force_delete, max_workers):
@app.command() @app.command()
@click.argument('pairs', nargs=-1) @click.argument('pairs', nargs=-1)
@max_workers_option @max_workers_option
@click.pass_context
@catch_errors @catch_errors
def discover(ctx, pairs, max_workers): def discover(pairs, max_workers):
''' '''
Refresh collection cache for the given pairs. Refresh collection cache for the given pairs.
''' '''
@ -143,9 +140,8 @@ def discover(ctx, pairs, max_workers):
@app.command() @app.command()
@click.argument('collection') @click.argument('collection')
@click.pass_context
@catch_errors @catch_errors
def repair(ctx, collection): def repair(collection):
''' '''
Repair a given collection. Repair a given collection.

View file

@ -65,7 +65,7 @@ class _Stack(object):
class _StackProxy(object): class _StackProxy(object):
def __init__(self, stack): def __init__(self, stack):
self._doubleclick_stack = stack object.__setattr__(self, '_doubleclick_stack', stack)
def __bool__(self): def __bool__(self):
try: try:
@ -77,8 +77,8 @@ class _StackProxy(object):
__nonzero__ = __bool__ __nonzero__ = __bool__
def __getattr__(self, name): __getattr__ = lambda s, n: getattr(s._doubleclick_stack.top, n)
return getattr(self._doubleclick_stack.top, name) __setattr__ = lambda s, n, v: setattr(s._doubleclick_stack.top, n, v)
_ctx_stack = _Stack() _ctx_stack = _Stack()