Skip to content

Commit

Permalink
Remove data_helpers in favor of using CommonPy
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Mar 24, 2022
1 parent d849e00 commit 2d74b05
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 73 deletions.
10 changes: 5 additions & 5 deletions eprints2bags/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import bagit
from collections import defaultdict
from commonpy.data_utils import flattened, parsed_datetime, pluralized
import getpass
from humanize import intcomma
import keyring
Expand All @@ -51,7 +52,6 @@
import eprints2bags
from eprints2bags import print_version
from .constants import ON_WINDOWS, KEYRING_PREFIX
from .data_helpers import flatten, expand_range, parse_datetime, plural
from .eprints import *
from .exit_codes import ExitCode
from .files import create_archive, verify_archive, archive_extension
Expand Down Expand Up @@ -387,7 +387,7 @@ def main(api_url = 'A', bag_action = 'B', processes = 'C', diff_with = 'D',
lastmod = None
else:
try:
lastmod = parse_datetime(lastmod)
lastmod = parsed_datetime(lastmod)
lastmod_str = lastmod.strftime(_LASTMOD_PRINT_FORMAT)
if __debug__: log(f'parsed lastmod as {lastmod_str}')
except Exception as ex:
Expand Down Expand Up @@ -458,7 +458,7 @@ def main(api_url = 'A', bag_action = 'B', processes = 'C', diff_with = 'D',
inform(f'Fetching full records list from {api_url}')
wanted = eprints_records_list(raw_list)

inform(f'Will process {intcomma(len(wanted))} EPrints {plural("record", wanted)}.')
inform(f'Will process {pluralized("EPrints record", wanted, True)}.')
if lastmod:
inform(f'Will only keep records modified after {lastmod_str}.')
if status:
Expand Down Expand Up @@ -508,7 +508,7 @@ def main(api_url = 'A', bag_action = 'B', processes = 'C', diff_with = 'D',

inform('─'*os.get_terminal_size(0)[0])
count = len(wanted) - len(missing) - len(skipped)
inform(f'Wrote {intcomma(count)} EPrints {plural("record", count)} to {output_dir}')
inform(f'Wrote {pluralized("EPrints record", count, True)} to {output_dir}')
if len(skipped) > 0:
inform('The following records were skipped: '+ ', '.join(skipped) + '.')
if len(missing) > 0:
Expand Down Expand Up @@ -561,7 +561,7 @@ def parsed_id_list(id_list):
if ',' not in id_list and '-' not in id_list:
alert_fatal('Unable to understand list of record identifiers')
exit(int(ExitCode.bad_arg))
return flatten(expand_range(x) for x in id_list.split(','))
return flattened(expand_range(x) for x in id_list.split(','))


def credentials(api_url, user, pswd, use_keyring, reset = False):
Expand Down
66 changes: 0 additions & 66 deletions eprints2bags/data_helpers.py

This file was deleted.

4 changes: 2 additions & 2 deletions eprints2bags/eprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import codecs
from collections import defaultdict
from commonpy.data_utils import parsed_datetime
from lxml import etree
import os
from os import path
import shutil
from sidetrack import log

import eprints2bags
from .data_helpers import parse_datetime
from .exceptions import *
from .network import net
from .ui import inform, warn, alert, alert_fatal
Expand Down Expand Up @@ -121,7 +121,7 @@ def eprints_xml(number, base_url, user, password, missing_ok):

def eprints_lastmod(xml):
lastmod_elem = xml.find('.//{' + _EPRINTS_XMLNS + '}lastmod')
return parse_datetime(lastmod_elem.text)
return parsed_datetime(lastmod_elem.text)


def eprints_status(xml):
Expand Down

0 comments on commit 2d74b05

Please sign in to comment.