From f0e4cf9ca7ebcfb03e55177e3a83205e2f9dce6b Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 16 Apr 2015 20:09:39 +0200 Subject: [PATCH] Use only one worker if debug mode is activated --- CHANGELOG.rst | 1 + tests/cli/test_main.py | 27 +++++++++++++++++++++++++++ vdirsyncer/cli/__init__.py | 13 ++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f9eb2dd..748fc4e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,7 @@ Version 0.5.0 - Command line should be a lot faster when no work is done, e.g. for help output. - Fix compatibility with iCloud again. +- Use only one worker if debug mode is activated. Version 0.4.4 ============= diff --git a/tests/cli/test_main.py b/tests/cli/test_main.py index 9e6ec5b..e85dee1 100644 --- a/tests/cli/test_main.py +++ b/tests/cli/test_main.py @@ -38,6 +38,33 @@ def test_simple_run(tmpdir, runner): assert tmpdir.join('path_b/haha.txt').read() == 'UID:haha' +def test_debug_connections(tmpdir, runner): + runner.write_with_general(dedent(''' + [pair my_pair] + a = my_a + b = my_b + + [storage my_a] + type = filesystem + path = {0}/path_a/ + fileext = .txt + + [storage my_b] + type = filesystem + path = {0}/path_b/ + fileext = .txt + ''').format(str(tmpdir))) + + tmpdir.mkdir('path_a') + tmpdir.mkdir('path_b') + + result = runner.invoke(['-vdebug', 'sync', '--max-workers=3']) + assert 'using 3 maximal workers' in result.output.lower() + + result = runner.invoke(['-vdebug', 'sync']) + assert 'using 1 maximal workers' in result.output.lower() + + def test_empty_storage(tmpdir, runner): runner.write_with_general(dedent(''' [pair my_pair] diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 9047012..65e09ee 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -48,14 +48,25 @@ def app(ctx, verbosity): if ctx.obj is None: ctx.obj = {} + ctx.obj['verbosity'] = verbosity + if 'config' not in ctx.obj: ctx.obj['config'] = load_config() main = app +def max_workers_callback(ctx, param, value): + if value == 0 and ctx.obj['verbosity'] == log.logging.DEBUG: + return 1 + return value + + max_workers_option = click.option( '--max-workers', default=0, type=click.IntRange(min=0, max=None), - help=('Use at most this many connections, 0 means unlimited.') + callback=max_workers_callback, + help=('Use at most this many connections. With debug messages enabled, ' + 'the default is 1, otherwise an unlimited amount of connections is ' + 'used.') )