From 7e8958b0633651f08714fc277ee53a1f820d1adf Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 22 Jun 2020 13:44:28 +0000 Subject: [PATCH] Allow overriding the archive ID --- codearchiver/core.py | 3 ++- codearchiver/modules/git.py | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/codearchiver/core.py b/codearchiver/core.py index ac40c5e..982c0d6 100644 --- a/codearchiver/core.py +++ b/codearchiver/core.py @@ -124,9 +124,10 @@ class Module: '''Whether or not this module is for handling `inputUrl`.''' return False - def __init__(self, inputUrl): + def __init__(self, inputUrl, id_ = None): self._inputUrl = inputUrl self._url = inputUrl.url + self._id = id_ self._httpClient = HttpClient() @abc.abstractmethod diff --git a/codearchiver/modules/git.py b/codearchiver/modules/git.py index 2d0ed52..4b27b75 100644 --- a/codearchiver/modules/git.py +++ b/codearchiver/modules/git.py @@ -14,8 +14,8 @@ class Git(codearchiver.core.Module): def matches(inputUrl): return inputUrl.url.endswith('.git') - def __init__(self, inputUrl, extraBranches = {}): - super().__init__(inputUrl) + def __init__(self, *args, extraBranches = {}, **kwargs): + super().__init__(*args, **kwargs) self._extraBranches = extraBranches def process(self): @@ -24,7 +24,9 @@ class Git(codearchiver.core.Module): logger.fatal(f'{directory!r} already exists') return startTime = datetime.datetime.utcnow() - bundle = f'{self._url.replace("/", "_")}.{startTime:%Y%m%dT%H%M%SZ}.bundle' + if self._id is None: + self._id = f'git_{self._url.replace("/", "_")}_{startTime:%Y%m%dT%H%M%SZ}' + bundle = f'{self._id}.bundle' if os.path.exists(bundle): logger.fatal(f'{bundle!r} already exists') return @@ -49,7 +51,7 @@ class Git(codearchiver.core.Module): logger.info(f'Removing clone') shutil.rmtree(directory) - return codearchiver.core.Result(id = f'git-{bundle[:-7]}', files = [bundle]) + return codearchiver.core.Result(id = self._id, files = [bundle]) def __repr__(self): return f'{type(self).__module__}.{type(self).__name__}({self._inputUrl!r}, extraBranches = {self._extraBranches!r})'