From 396fd93996aafabdcfdeed70b0fe6c36142cdfaa Mon Sep 17 00:00:00 2001 From: Zhiltsov Max Date: Fri, 31 Jul 2020 15:47:53 +0300 Subject: [PATCH 1/3] Add model info and source info commands --- .../datumaro/cli/contexts/model/__init__.py | 25 ++++++++++++++++++ .../datumaro/cli/contexts/source/__init__.py | 26 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/datumaro/datumaro/cli/contexts/model/__init__.py b/datumaro/datumaro/cli/contexts/model/__init__.py index a10f5c0da254..0c4f201887f6 100644 --- a/datumaro/datumaro/cli/contexts/model/__init__.py +++ b/datumaro/datumaro/cli/contexts/model/__init__.py @@ -146,6 +146,30 @@ def run_command(args): return 0 +def build_info_parser(parser_ctor=argparse.ArgumentParser): + parser = parser_ctor() + + parser.add_argument('-n', '--name', + help="Model name") + parser.add_argument('-v', '--verbose', action='store_true', + help="Show details") + parser.add_argument('-p', '--project', dest='project_dir', default='.', + help="Directory of the project to operate on (default: current dir)") + parser.set_defaults(command=info_command) + + return parser + +def info_command(args): + project = load_project(args.project_dir) + + if args.name: + model = project.get_model(args.name) + print(model) + else: + for name, conf in project.config.models.items(): + print(name) + if args.verbose: + print(dict(conf)) def build_parser(parser_ctor=argparse.ArgumentParser): parser = parser_ctor() @@ -154,5 +178,6 @@ def build_parser(parser_ctor=argparse.ArgumentParser): add_subparser(subparsers, 'add', build_add_parser) add_subparser(subparsers, 'remove', build_remove_parser) add_subparser(subparsers, 'run', build_run_parser) + add_subparser(subparsers, 'info', build_info_parser) return parser diff --git a/datumaro/datumaro/cli/contexts/source/__init__.py b/datumaro/datumaro/cli/contexts/source/__init__.py index 94734265e7d1..ef9edafbd7af 100644 --- a/datumaro/datumaro/cli/contexts/source/__init__.py +++ b/datumaro/datumaro/cli/contexts/source/__init__.py @@ -225,6 +225,31 @@ def remove_command(args): return 0 +def build_info_parser(parser_ctor=argparse.ArgumentParser): + parser = parser_ctor() + + parser.add_argument('-n', '--name', + help="Source name") + parser.add_argument('-v', '--verbose', action='store_true', + help="Show details") + parser.add_argument('-p', '--project', dest='project_dir', default='.', + help="Directory of the project to operate on (default: current dir)") + parser.set_defaults(command=info_command) + + return parser + +def info_command(args): + project = load_project(args.project_dir) + + if args.name: + source = project.get_source(args.name) + print(source) + else: + for name, conf in project.config.sources.items(): + print(name) + if args.verbose: + print(dict(conf)) + def build_parser(parser_ctor=argparse.ArgumentParser): parser = parser_ctor(description=""" Manipulate data sources inside of a project.|n @@ -243,5 +268,6 @@ def build_parser(parser_ctor=argparse.ArgumentParser): subparsers = parser.add_subparsers() add_subparser(subparsers, 'add', build_add_parser) add_subparser(subparsers, 'remove', build_remove_parser) + add_subparser(subparsers, 'info', build_info_parser) return parser From eb55fdcd02ef2b3b2d6597eecb62e8e51633ce5a Mon Sep 17 00:00:00 2001 From: Zhiltsov Max Date: Fri, 31 Jul 2020 15:51:25 +0300 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e230af8bed80..430a54e6c3c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support creating multiple jobs for each task through python cli (https://github.com/opencv/cvat/pull/1950) - python cli over https () - Error message when plugins weren't able to initialize instead of infinite loading () +- [Datumaro] Added model info and source info commands () ### Changed - Smaller object details () From 6dc1853bb64c17b02e1b4a5495f3ed6efd3b37d2 Mon Sep 17 00:00:00 2001 From: Zhiltsov Max Date: Mon, 3 Aug 2020 18:15:21 +0300 Subject: [PATCH 3/3] adjust cli output --- .../datumaro/cli/contexts/project/__init__.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/datumaro/datumaro/cli/contexts/project/__init__.py b/datumaro/datumaro/cli/contexts/project/__init__.py index 65f81886e5c3..92d5a81f1f11 100644 --- a/datumaro/datumaro/cli/contexts/project/__init__.py +++ b/datumaro/datumaro/cli/contexts/project/__init__.py @@ -55,7 +55,7 @@ def create_command(args): if osp.isdir(project_env_dir) and os.listdir(project_env_dir): if not args.overwrite: raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % project_env_dir) + "(pass --overwrite to overwrite)" % project_env_dir) else: shutil.rmtree(project_env_dir, ignore_errors=True) @@ -63,7 +63,7 @@ def create_command(args): if osp.isdir(own_dataset_dir) and os.listdir(own_dataset_dir): if not args.overwrite: raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % own_dataset_dir) + "(pass --overwrite to overwrite)" % own_dataset_dir) else: # NOTE: remove the dir to avoid using data from previous project shutil.rmtree(own_dataset_dir) @@ -149,7 +149,7 @@ def import_command(args): if osp.isdir(project_env_dir) and os.listdir(project_env_dir): if not args.overwrite: raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % project_env_dir) + "(pass --overwrite to overwrite)" % project_env_dir) else: shutil.rmtree(project_env_dir, ignore_errors=True) @@ -157,7 +157,7 @@ def import_command(args): if osp.isdir(own_dataset_dir) and os.listdir(own_dataset_dir): if not args.overwrite: raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % own_dataset_dir) + "(pass --overwrite to overwrite)" % own_dataset_dir) else: # NOTE: remove the dir to avoid using data from previous project shutil.rmtree(own_dataset_dir) @@ -328,7 +328,7 @@ def export_command(args): if dst_dir: if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir): raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % dst_dir) + "(pass --overwrite to overwrite)" % dst_dir) else: dst_dir = generate_next_file_name('%s-%s' % \ (project.config.project_name, make_file_name(args.format))) @@ -424,7 +424,7 @@ def extract_command(args): if dst_dir: if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir): raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % dst_dir) + "(pass --overwrite to overwrite)" % dst_dir) else: dst_dir = generate_next_file_name('%s-filter' % \ project.config.project_name) @@ -453,10 +453,10 @@ def extract_command(args): return 0 def build_merge_parser(parser_ctor=argparse.ArgumentParser): - parser = parser_ctor(help="Merge projects", + parser = parser_ctor(help="Merge two projects", description=""" Updates items of the current project with items - from the other project.|n + from other project.|n |n Examples:|n - Update a project with items from other project:|n @@ -464,8 +464,8 @@ def build_merge_parser(parser_ctor=argparse.ArgumentParser): """, formatter_class=MultilineFormatter) - parser.add_argument('other_project_dir', - help="Directory of the project to get data updates from") + parser.add_argument('other_project', + help="Path to a project") parser.add_argument('-o', '--output-dir', dest='dst_dir', default=None, help="Output directory (default: current project's dir)") parser.add_argument('--overwrite', action='store_true', @@ -484,11 +484,12 @@ def merge_command(args): if dst_dir: if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir): raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % dst_dir) + "(pass --overwrite to overwrite)" % dst_dir) first_dataset = first_project.make_dataset() - first_dataset.update(second_project.make_dataset()) + second_dataset = second_project.make_dataset() + first_dataset.update(second_dataset) first_dataset.save(save_dir=dst_dir) if dst_dir is None: @@ -542,7 +543,7 @@ def diff_command(args): if dst_dir: if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir): raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % dst_dir) + "(pass --overwrite to overwrite)" % dst_dir) else: dst_dir = generate_next_file_name('%s-%s-diff' % ( first_project.config.project_name, @@ -602,7 +603,7 @@ def transform_command(args): if dst_dir: if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir): raise CliException("Directory '%s' already exists " - "(pass --overwrite to force creation)" % dst_dir) + "(pass --overwrite to overwrite)" % dst_dir) else: dst_dir = generate_next_file_name('%s-%s' % \ (project.config.project_name, make_file_name(args.transform)))