Skip to content

Commit

Permalink
[Datumaro] Pretty output folder names (#1149)
Browse files Browse the repository at this point in the history
* Generate output dir name from operation parameters

* Fix failing command
  • Loading branch information
zhiltsov-max committed Feb 19, 2020
1 parent a2da181 commit 6c2d93e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 7 additions & 6 deletions datumaro/datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions datumaro/datumaro/cli/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6c2d93e

Please sign in to comment.