diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2020-05-27 10:46:52 +0200 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2020-05-27 13:47:23 +0200 |
commit | ae4f1c8b5a5490fd5d15f07ac9959f410447bd52 (patch) | |
tree | 5cc80ff59cee0f56684f09a74e9b18e361bab42e /utils/trackertestutils | |
parent | 45cdd0483d0b2b9f642d78796b8d3f5f5c8bbc69 (diff) | |
download | tracker-ae4f1c8b5a5490fd5d15f07ac9959f410447bd52.tar.gz |
trackertestutils: Improvement to option parsing
Use argparse mutually-exclusive option groups instead of checking
these manually.
Diffstat (limited to 'utils/trackertestutils')
-rw-r--r-- | utils/trackertestutils/__main__.py | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/utils/trackertestutils/__main__.py b/utils/trackertestutils/__main__.py index 0723adcf3..ba64eb4d7 100644 --- a/utils/trackertestutils/__main__.py +++ b/utils/trackertestutils/__main__.py @@ -208,19 +208,21 @@ def argument_parser(): help="run Tracker from the given install prefix. You " "can run the system version of Tracker by " "specifying --prefix=/usr") - parser.add_argument('-s', '--store', metavar='DIR', action=expand_path, - default=default_store_location, dest='store_location', - help=f"directory to store the index (default={default_store_location})") parser.add_argument('--use-session-dirs', action='store_true', help=f"update the real Tracker index (use with care!)") - parser.add_argument('--store-tmpdir', action='store_true', - help="create index in a temporary directory and " - "delete it on exit (useful for automated testing)") - parser.add_argument('--index-recursive-directories', nargs='+', - help="override the default locations Tracker should index") - parser.add_argument('--index-recursive-tmpdir', action='store_true', - help="create a temporary directory and configure Tracker " - "to only index that location (useful for automated testing)") + store_group = parser.add_mutually_exclusive_group() + store_group.add_argument('-s', '--store', metavar='DIR', action=expand_path, + default=default_store_location, dest='store_location', + help=f"directory to store the index (default={default_store_location})") + store_group.add_argument('--store-tmpdir', action='store_true', + help="create index in a temporary directory and " + "delete it on exit (useful for automated testing)") + index_group = parser.add_mutually_exclusive_group() + index_group.add_argument('--index-recursive-directories', nargs='+', + help="override the default locations Tracker should index") + index_group.add_argument('--index-recursive-tmpdir', action='store_true', + help="create a temporary directory and configure Tracker " + "to only index that location (useful for automated testing)") parser.add_argument('--wait-for-miner', type=str, action='append', help="wait for one or more daemons to start, and " "return to idle for at least 1 second, before " @@ -391,8 +393,6 @@ def main(): "--index-recursive-tmpdir") use_session_dirs = True else: - if args.store_location != default_store_location and args.store_tmpdir: - raise RuntimeError("The --store-tmpdir flag is enabled, but --store= was also passed.") if args.store_tmpdir: store_location = store_tmpdir = tempfile.mkdtemp(prefix='tracker-sandbox-store') else: @@ -401,9 +401,6 @@ def main(): index_recursive_directories = None index_recursive_tmpdir = None - if args.index_recursive_directories and args.index_recursive_tmpdir: - raise RuntimeError("The --index-recursive-tmpdir flag is enabled, but " - "--index-recursive-directories= was also passed.") if args.index_recursive_tmpdir: # This tmpdir goes in cwd because paths under /tmp are ignored for indexing index_recursive_tmpdir = tempfile.mkdtemp(prefix='tracker-indexed-tmpdir', dir=os.getcwd()) |