diff --git a/CHANGELOG.md b/CHANGELOG.md index 99de8a72724a..3c759297156d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.1.0] - Unreleased ### Added -- +- [Datumaro] Added model info and source info commands () ### Changed - 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/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))) 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