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

internetarchive.cli.argparser renamed to internetarchive.cli.cli_utils in v5+ of internetarchive #341

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 3 additions & 2 deletions tubeup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
import logging
import traceback

from tubeup.utils import key_value_to_dict
import internetarchive.cli

from tubeup.TubeUp import TubeUp
from tubeup import __version__

Expand Down Expand Up @@ -88,7 +89,7 @@ def main():
ch.setFormatter(formatter)
root.addHandler(ch)

metadata = key_value_to_dict(args['--metadata'])
metadata = internetarchive.cli.cli_utils.get_args_dict(args['--metadata'])

tu = TubeUp(verbose=not quiet_mode,
output_template=args['--output'])
Expand Down
18 changes: 0 additions & 18 deletions tubeup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@
EMPTY_ANNOTATION_FILE = ('<?xml version="1.0" encoding="UTF-8" ?>'
'<document><annotations></annotations></document>')

def key_value_to_dict(lst):
"""
Convert many key:value pair strings into a python dictionary
"""
if not isinstance(lst, list):
lst = [lst]

result = defaultdict(list)
for item in lst:
key, value = item.split(":", 1)
assert value, f"Expected a value! for {key}"
if result[key] and value not in result[key]:
result[key].append(value)
else:
result[key] = [value]

# Convert single-item lists back to strings for non-list values
return {k: v if len(v) > 1 else v[0] for k, v in result.items()}

def sanitize_identifier(identifier, replacement='-'):
return re.sub(r'[^\w-]', replacement, identifier)
Expand Down
Loading