Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Datumaro] Pretty output folder names #1149

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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