diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ ## toplevel +### local svn repository + ``` $ python3 repo = 'pyang-repo-r343-eol-native-mixed-lf-crlf' @@ -63,11 +65,32 @@ t = LoadSvnRepository() t.run(svn_url=svn_url, - destination_path='/tmp', origin_url=origin_url, visit_date='2016-05-03T15:16:32+00:00', start_from_scratch=True) ``` +### repository dump + +``` +$ python3 +repo = '0-512-md' +archive_name = '%s-repo.svndump.gz' % repo +archive_path = '/home/storage/svn/dumps/%s' % archive_name +origin_url = 'http://%s.googlecode.com' % repo +svn_url = 'file://%s' % repo + +import logging +logging.basicConfig(level=logging.DEBUG) + +from swh.loader.svn.tasks import MountAndLoadSvnRepository + +t = MountAndLoadSvnRepository() +t.run(archive_path=archive_path, + origin_url=origin_url, + visit_date='2016-05-03T15:16:32+00:00', + start_from_scratch=True) +``` + ## Production like start worker instance @@ -116,4 +139,3 @@ ## Produce archive of svndumps list to load see. `python3 -m swh.loader.svn.producer svn-archive --help` - diff --git a/swh/loader/svn/loader.py b/swh/loader/svn/loader.py --- a/swh/loader/svn/loader.py +++ b/swh/loader/svn/loader.py @@ -544,12 +544,24 @@ """ def __init__(self, archive_path): super().__init__() - self.log.info('Archive to mount and load %s' % archive_path) + self.archive_path = archive_path + self.temp_dir = None + self.repo_path = None + + def prepare(self, *, svn_url, destination_path=None, + swh_revision=None, start_from_scratch=False, **kwargs): + self.log.info('Archive to mount and load %s' % self.archive_path) self.temp_dir, self.repo_path = init_svn_repo_from_archive_dump( - archive_path, + self.archive_path, prefix=TEMPORARY_DIR_PREFIX_PATTERN, suffix='-%s' % os.getpid(), root_dir=self.temp_directory) + if not svn_url: + svn_url = 'file://%s' % self.repo_path + super().prepare(svn_url=svn_url, destination_path=destination_path, + swh_revision=swh_revision, + start_from_scratch=start_from_scratch, + **kwargs) def cleanup(self): super().cleanup() diff --git a/swh/loader/svn/tasks.py b/swh/loader/svn/tasks.py --- a/swh/loader/svn/tasks.py +++ b/swh/loader/svn/tasks.py @@ -9,7 +9,7 @@ class LoadSvnRepository(Task): - """Import one svn repository to Software Heritage. + """Load an svn repository to Software Heritage. """ task_queue = 'swh_loader_svn' @@ -20,7 +20,7 @@ origin_url=None, visit_date=None, start_from_scratch=None): - """Import a svn repository with swh policy. + """Import a svn repository Args: args: ordered arguments (expected None) @@ -47,18 +47,22 @@ class MountAndLoadSvnRepository(Task): + """Mount an archive dump into an svn repository, then load the + repository to Software Heritage. + + """ task_queue = 'swh_loader_svn_mount_and_load' def run_task(self, *, archive_path, origin_url=None, visit_date=None, start_from_scratch=False): - """1. Mount an svn dump from archive as a local svn repository. - 2. Load it through the svn loader. - 3. Clean up mounted svn repository archive. + """1. Mount an svn dump from archive as a local svn repository + 2. Load it through the svn loader + 3. Clean up mounted svn repository archive """ loader = SvnLoaderFromDumpArchive(archive_path) loader.log = self.log - return loader.load(svn_url='file://%s' % loader.repo_path, + return loader.load(svn_url=None, origin_url=origin_url, visit_date=visit_date, archive_path=archive_path,