diff --git a/datumaro/datumaro/cli/contexts/project/__init__.py b/datumaro/datumaro/cli/contexts/project/__init__.py index 3d3100ca9019..15bc3a0c05e4 100644 --- a/datumaro/datumaro/cli/contexts/project/__init__.py +++ b/datumaro/datumaro/cli/contexts/project/__init__.py @@ -16,7 +16,8 @@ from datumaro.components.extractor import AnnotationType from datumaro.components.cli_plugin import CliPlugin from .diff import DiffVisualizer -from ...util import add_subparser, CliException, MultilineFormatter +from ...util import add_subparser, CliException, MultilineFormatter, \ + make_file_name from ...util.project import make_project_path, load_project, \ generate_next_dir_name @@ -286,8 +287,8 @@ def export_command(args): raise CliException("Directory '%s' already exists " "(pass --overwrite to force creation)" % dst_dir) else: - dst_dir = generate_next_dir_name('%s-export-%s' % \ - (project.config.project_name, args.format)) + dst_dir = generate_next_dir_name('%s-%s' % \ + (project.config.project_name, make_file_name(args.format))) dst_dir = osp.abspath(dst_dir) try: @@ -554,8 +555,8 @@ def transform_command(args): raise CliException("Directory '%s' already exists " "(pass --overwrite to force creation)" % dst_dir) else: - dst_dir = generate_next_dir_name('%s-transform' % \ - project.config.project_name) + dst_dir = generate_next_dir_name('%s-%s' % \ + (project.config.project_name, make_file_name(args.transform))) dst_dir = osp.abspath(dst_dir) extra_args = {} @@ -648,7 +649,7 @@ def print_extractor_info(extractor, indent=''): print_extractor_info(subset, indent=" ") print("Models:") - for model_name, model in env.config.models.items(): + for model_name, model in config.models.items(): print(" model '%s':" % model_name) print(" type:", model.launcher) diff --git a/datumaro/datumaro/cli/util/__init__.py b/datumaro/datumaro/cli/util/__init__.py index 493199836433..2d04a6936b71 100644 --- a/datumaro/datumaro/cli/util/__init__.py +++ b/datumaro/datumaro/cli/util/__init__.py @@ -36,3 +36,17 @@ def _fill_text(self, text, width, indent): initial_indent=indent, subsequent_indent=indent) + '\n' multiline_text += formatted_paragraph return multiline_text + +def make_file_name(s): + # adapted from + # https://docs.djangoproject.com/en/2.1/_modules/django/utils/text/#slugify + """ + Normalizes string, converts to lowercase, removes non-alpha characters, + and converts spaces to hyphens. + """ + import unicodedata, re + s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore') + s = s.decode() + s = re.sub(r'[^\w\s-]', '', s).strip().lower() + s = re.sub(r'[-\s]+', '-', s) + return s \ No newline at end of file