Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/cli.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
from itertools import chain | from itertools import chain | ||||
import logging | import logging | ||||
Show All 19 Lines | @click.option( | ||||
), | ), | ||||
) | ) | ||||
@click.option("--hg-archive", "-a", help=("Path to the hg archive file to load from.")) | @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("--visit-date", "-D", help="Visit date (defaults to now).") | ||||
@click.option("--log-level", "-l", type=click.Choice(LOGLEVELS), help="Log level.") | @click.option("--log-level", "-l", type=click.Choice(LOGLEVELS), help="Log level.") | ||||
def main( | def main( | ||||
origin_url, hg_directory=None, hg_archive=None, visit_date=None, log_level=None | origin_url, hg_directory=None, hg_archive=None, visit_date=None, log_level=None | ||||
): | ): | ||||
from swh.storage import get_storage | |||||
logging.basicConfig( | logging.basicConfig( | ||||
level=(log_level or "DEBUG").upper(), | level=(log_level or "DEBUG").upper(), | ||||
format="%(asctime)s %(process)d %(message)s", | format="%(asctime)s %(process)d %(message)s", | ||||
) | ) | ||||
if not visit_date: | if not visit_date: | ||||
visit_date = datetime.datetime.now(tz=datetime.timezone.utc) | visit_date = datetime.datetime.now(tz=datetime.timezone.utc) | ||||
kwargs = {"visit_date": visit_date, "origin_url": origin_url} | kwargs = {"visit_date": visit_date, "origin_url": origin_url} | ||||
if hg_archive: | if hg_archive: | ||||
from .loader import HgArchiveBundle20Loader as HgLoader | from .loader import HgArchiveBundle20Loader as HgLoader | ||||
kwargs["archive_path"] = hg_archive | kwargs["archive_path"] = hg_archive | ||||
else: | else: | ||||
from .loader import HgBundle20Loader as HgLoader | from .loader import HgBundle20Loader as HgLoader | ||||
kwargs["directory"] = hg_directory | kwargs["directory"] = hg_directory | ||||
return HgLoader().load(**kwargs) | storage = get_storage(cls="memory") | ||||
return HgLoader(storage, **kwargs).load() | |||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
main() | main() |