diff --git a/resources/test/loader-tar.ini b/resources/test/loader-tar.ini new file mode 100644 index 0000000..d307ef3 --- /dev/null +++ b/resources/test/loader-tar.ini @@ -0,0 +1,30 @@ +[main] + +tar_path = /home/tony/work/inria/repo/linux.tgz +dir_path = /tmp/linux/ + +# synthetic origin +origin_url = file:///dev/null +branch = master +authority_id = 1 +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 77b5601..8364134 100644 --- a/swh/loader/dir/tasks.py +++ b/swh/loader/dir/tasks.py @@ -1,28 +1,68 @@ # 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 + from swh.core.scheduling import Task +from swh.core import config + +from swh.loader.dir.loader import DirLoader -from .loader import DirLoader class LoadDirRepository(Task): """Import a directory to Software Heritage""" 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], ) + self.loader = DirLoader(self.config) + self.loader.log = self.log - def run(self, repo_path, origin_url, authority_id, validity): + def run(self, dir_path): """Import a directory""" - loader = DirLoader(self.config) - loader.log = self.log + self.loader.process(dir_path) + + +class LoadTarRepository(Task): + """Import a tarball to Software Heritage""" + + CONFIG_BASE_FILENAME = 'loader-tar.ini' + ADDITIONAL_CONFIG = { + 'dir_path': ('str', '/tmp/swh.loader.tar/'), + 'tar_path': ('str', '/some/path/to/tarball.tar') + + } + + def __init__(self): + self.config = DirLoader.parse_config_file( + base_filename=self.CONFIG_BASE_FILENAME, + additional_configs=[self.ADDITIONAL_CONFIG], + ) + config.prepare_folders(self.config, 'dir_path') + self.loader = DirLoader(self.config) + self.loader.log = self.log + + def untar(self, tar_path, dir_path): + """Decompress an archive tar_path to dir_path. + + """ + subprocess.check_output(['tar', 'xvf', tar_path, + '--preserve-permissions', + '-C', dir_path], + universal_newlines=True) + + def run(self, dir_path): + """Import a tarball. - loader.process(repo_path) + """ + tar_path = self.config['tar_path'] + self.untar(tar_path, dir_path) + self.loader.process(dir_path)