diff --git a/swh/scheduler/cli.py b/swh/scheduler/cli.py --- a/swh/scheduler/cli.py +++ b/swh/scheduler/cli.py @@ -17,6 +17,7 @@ from . import compute_nb_tasks_from from .backend_es import SWHElasticSearchClient from . import get_scheduler, DEFAULT_CONFIG +from .cli_utils import parse_options locale.setlocale(locale.LC_ALL, '') @@ -300,8 +301,7 @@ now = arrow.utcnow() - args = [x for x in options if '=' not in x] - kw = dict(x.split('=', 1) for x in options if '=' in x) + (args, kw) = parse_options(options) task = {'type': type, 'policy': policy, 'priority': priority, diff --git a/swh/scheduler/cli_utils.py b/swh/scheduler/cli_utils.py new file mode 100644 --- /dev/null +++ b/swh/scheduler/cli_utils.py @@ -0,0 +1,21 @@ +# Copyright (C) 2019 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + + +def parse_options(options): + """Parses options from a CLI and turns it into Python args and kwargs. + + >>> parse_options([]) + ([], {}) + >>> parse_options(['foo', 'bar']) + (['foo', 'bar'], {}) + >>> parse_options(['foo=bar']) + ([], {'foo': 'bar'}) + >>> parse_options(['foo', 'bar=baz']) + (['foo'], {'bar': 'baz'}) + """ + args = [x for x in options if '=' not in x] + kw = dict(x.split('=', 1) for x in options if '=' in x) + return (args, kw)