diff --git a/setup.py b/setup.py index db89a38..75bd013 100644 --- a/setup.py +++ b/setup.py @@ -1,28 +1,31 @@ from setuptools import setup, find_packages def parse_requirements(): requirements = [] for reqf in ('requirements.txt', 'requirements-swh.txt'): with open(reqf) as f: for line in f.readlines(): line = line.strip() if not line or line.startswith('#'): continue requirements.append(line) return requirements setup( name='swh.loader.mercurial', description='Software Heritage Mercurial Loader', author='Software Heritage developers', author_email='swh-devel@inria.fr', url='https://forge.softwareheritage.org/diffusion/DLDHG/', packages=find_packages(), # packages's modules scripts=[], # scripts to package install_requires=parse_requirements(), setup_requires=['vcversioner'], vcversioner={}, include_package_data=True, + entry_points={ + 'console_scripts': ['swh-loader-hg=swh.loader.mercurial.cli:main'], + }, ) diff --git a/swh/loader/mercurial/cli.py b/swh/loader/mercurial/cli.py new file mode 100644 index 0000000..ae4e3f7 --- /dev/null +++ b/swh/loader/mercurial/cli.py @@ -0,0 +1,48 @@ +# Copyright (C) 2018 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import datetime +import click +import logging + +LOGLEVELS = [logging._levelToName[lvl] + for lvl in sorted(logging._levelToName.keys())] + + +@click.command() +@click.argument('origin-url') +@click.option('--hg-directory', '-d', + help=('Path to the hg (local) directory to load from. ' + 'If unset, the hg repo will be cloned from the ' + 'given (origin) url.')) +@click.option('--hg-archive', '-a', + help=('Path to the hg archive file to load from.')) +@click.option('--visit-date', '-D', help='Visit date (defaults to now).') +@click.option('--log-level', '-l', + type=click.Choice(LOGLEVELS, case_sensitive=False), + help='Log level.') +def main(origin_url, hg_directory=None, + hg_archive=None, visit_date=None, log_level=None): + + logging.basicConfig( + level=(log_level or 'DEBUG').upper(), + format='%(asctime)s %(process)d %(message)s') + + if not visit_date: + visit_date = datetime.datetime.now(tz=datetime.timezone.utc) + kwargs = {'visit_date': visit_date, + 'origin_url': origin_url} + if hg_archive: + from .loader import HgArchiveBundle20Loader as HgLoader + kwargs['archive_path'] = hg_archive + else: + from .loader import HgBundle20Loader as HgLoader + kwargs['directory'] = hg_directory + + return HgLoader().load(**kwargs) + + +if __name__ == '__main__': + main()