diff --git a/resources/loader/tar.ini b/resources/loader/tar.ini index 6a2d9bf..c0aaf45 100644 --- a/resources/loader/tar.ini +++ b/resources/loader/tar.ini @@ -1,38 +1,39 @@ [main] # NOT FOR PRODUCTION tar_path = /home/tony/work/inria/repo/linux.tgz dir_path = /tmp/linux/ # synthetic origin origin_url = file:///dev/null +origin_type = tar # occurrence occurrence_branch = master2 occurrence_authority = 1 occurrence_validity = 2015-01-01 00:00:00+00 # occurrence 2 occurrence2_branch = dev occurrence2_authority = 2 occurrence2_validity = 2015-01-01 00:00:00+00 # synthetic revision revision_author_name = swh author revision_author_email = swh@inria.fr revision_author_date = 1444054085 revision_author_offset = +0200 revision_committer_name = swh committer revision_committer_email = swh@inria.fr revision_committer_date = 1444054085 revision_committer_offset = +0200 revision_type = tar revision_message = synthetic revision message # synthetic release release_name = v0.0.1 release_date = 1444054085 release_offset = +0200 release_author_name = swh author release_author_email = swh@inria.fr release_comment = synthetic release diff --git a/swh/loader/dir/tasks.py b/swh/loader/dir/tasks.py index 6ae8488..7c0e29b 100644 --- a/swh/loader/dir/tasks.py +++ b/swh/loader/dir/tasks.py @@ -1,93 +1,90 @@ # Copyright (C) 2015 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 subprocess import shutil import tempfile from swh.core.scheduling import Task from swh.loader.dir.loader import DirLoader class LoadDirRepository(Task): """Import a directory to Software Heritage """ task_queue = 'swh_loader_dir' CONFIG_BASE_FILENAME = 'loader/dir.ini' ADDITIONAL_CONFIG = {} def __init__(self): self.config = DirLoader.parse_config_file( base_filename=self.CONFIG_BASE_FILENAME, additional_configs=[self.ADDITIONAL_CONFIG], ) def run(self, dir_path, origin, revision, release, occurrences): """Import a directory. Args: cf. swh.loader.dir.loader.run docstring """ loader = DirLoader(self.config) loader.log = self.log loader.process(dir_path, origin, revision, release, occurrences) def untar(tar_path, dir_path): """Decompress an archive tar_path to dir_path. At the end of this call, dir_path contains the tarball's uncompressed content. Args: tar_path: the path to access the tarball dir_path: The path where to extract the tarball's content. """ untar_cmd = ['tar', 'xavf', tar_path, '--preserve-permissions', '-C', dir_path] subprocess.check_call(untar_cmd, stderr=subprocess.STDOUT) class LoadTarRepository(LoadDirRepository): """Import a tarball to Software Heritage """ task_queue = 'swh_loader_tar' CONFIG_BASE_FILENAME = 'loader/tar.ini' ADDITIONAL_CONFIG = { 'extraction_dir': ('str', '/tmp/swh.loader.tar/'), } - def run(self, tar_path, origin_url, revision, release, occurrences): + def run(self, tar_path, origin, revision, release, occurrences): """Import a tarball tar_path. Args: - tar_path: path access to the tarball - - origin_url: url where we fetched the tarball - - revision, release, occurrences: see LoadDirRepository.run + - origin, revision, release, occurrences: see LoadDirRepository.run """ extraction_dir = self.config['extraction_dir'] dir_path = tempfile.mkdtemp(prefix='swh.loader.tar', dir=extraction_dir) # unarchive in dir_path untar(tar_path, dir_path) - origin = { - 'url': origin_url, - 'type': 'tar' - } + if 'type' not in origin: # let the type flow if present + origin['type'] = 'tar' try: super().run(dir_path, origin, revision, release, occurrences) finally: # always clean up shutil.rmtree(dir_path)