Browse Source

Allow overriding the archive ID

tags/v1.0
JustAnotherArchivist 4 years ago
parent
commit
7e8958b063
2 changed files with 8 additions and 5 deletions
  1. +2
    -1
      codearchiver/core.py
  2. +6
    -4
      codearchiver/modules/git.py

+ 2
- 1
codearchiver/core.py View File

@@ -124,9 +124,10 @@ class Module:
'''Whether or not this module is for handling `inputUrl`.''' '''Whether or not this module is for handling `inputUrl`.'''
return False return False


def __init__(self, inputUrl):
def __init__(self, inputUrl, id_ = None):
self._inputUrl = inputUrl self._inputUrl = inputUrl
self._url = inputUrl.url self._url = inputUrl.url
self._id = id_
self._httpClient = HttpClient() self._httpClient = HttpClient()


@abc.abstractmethod @abc.abstractmethod


+ 6
- 4
codearchiver/modules/git.py View File

@@ -14,8 +14,8 @@ class Git(codearchiver.core.Module):
def matches(inputUrl): def matches(inputUrl):
return inputUrl.url.endswith('.git') 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 self._extraBranches = extraBranches


def process(self): def process(self):
@@ -24,7 +24,9 @@ class Git(codearchiver.core.Module):
logger.fatal(f'{directory!r} already exists') logger.fatal(f'{directory!r} already exists')
return return
startTime = datetime.datetime.utcnow() 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): if os.path.exists(bundle):
logger.fatal(f'{bundle!r} already exists') logger.fatal(f'{bundle!r} already exists')
return return
@@ -49,7 +51,7 @@ class Git(codearchiver.core.Module):
logger.info(f'Removing clone') logger.info(f'Removing clone')
shutil.rmtree(directory) 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): def __repr__(self):
return f'{type(self).__module__}.{type(self).__name__}({self._inputUrl!r}, extraBranches = {self._extraBranches!r})' return f'{type(self).__module__}.{type(self).__name__}({self._inputUrl!r}, extraBranches = {self._extraBranches!r})'

Loading…
Cancel
Save