Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/from_disk.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 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 | ||||
from collections import defaultdict | from collections import defaultdict | ||||
import datetime | |||||
import os | import os | ||||
import shutil | import shutil | ||||
from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
from dulwich.errors import ObjectFormatException | from dulwich.errors import ObjectFormatException | ||||
try: | try: | ||||
from dulwich.errors import EmptyFileException | from dulwich.errors import EmptyFileException | ||||
▲ Show 20 Lines • Show All 368 Lines • ▼ Show 20 Lines | def cleanup(self): | ||||
"""Cleanup the temporary location (if it exists). | """Cleanup the temporary location (if it exists). | ||||
""" | """ | ||||
if self.temp_dir and os.path.exists(self.temp_dir): | if self.temp_dir and os.path.exists(self.temp_dir): | ||||
shutil.rmtree(self.temp_dir) | shutil.rmtree(self.temp_dir) | ||||
self.log.info( | self.log.info( | ||||
"Project %s - Done injecting %s" % (self.origin_url, self.repo_path) | "Project %s - Done injecting %s" % (self.origin_url, self.repo_path) | ||||
) | ) | ||||
if __name__ == "__main__": | |||||
import logging | |||||
import click | |||||
logging.basicConfig( | |||||
level=logging.DEBUG, format="%(asctime)s %(process)d %(message)s" | |||||
) | |||||
@click.command() | |||||
@click.option("--origin-url", help="origin url") | |||||
@click.option("--git-directory", help="Path to git repository to load") | |||||
@click.option("--visit-date", default=None, help="Visit date") | |||||
def main(origin_url, git_directory, visit_date): | |||||
if not visit_date: | |||||
visit_date = datetime.datetime.now(tz=datetime.timezone.utc) | |||||
return GitLoaderFromDisk().load(origin_url, git_directory, visit_date) | |||||
main() |