Skip to content
Snippets Groups Projects
Commit 1858bd97 authored by yvesn's avatar yvesn
Browse files

SSDM-6427: obis - added support for git annex backend WORM

parent 692d5891
No related branches found
No related tags found
No related merge requests found
...@@ -167,14 +167,30 @@ class ChecksumGeneratorMd5(object): ...@@ -167,14 +167,30 @@ class ChecksumGeneratorMd5(object):
return hash_md5.hexdigest() return hash_md5.hexdigest()
class ChecksumGeneratorWORM(object):
def get_checksum(self, file):
return {
'checksum': self.worm(file),
'checksumType': 'WORM',
'fileLength': os.path.getsize(file),
'path': file
}
def worm(self, file):
modification_time = int(os.path.getmtime(file))
size = os.path.getsize(file)
return "WORM-s{}-m{}--{}".format(size, modification_time, file)
class ChecksumGeneratorGitAnnex(object): class ChecksumGeneratorGitAnnex(object):
def __init__(self): def __init__(self):
backend = self._get_annex_backend() self.backend = self._get_annex_backend()
self.checksum_generator_replacement = ChecksumGeneratorCrc32() if backend is None else None self.checksum_generator_replacement = ChecksumGeneratorCrc32() if self.backend is None else None
# define which generator to use for files which are not handled by annex # define which generator to use for files which are not handled by annex
if backend == 'MD5': if self.backend == 'MD5':
self.checksum_generator_supplement = ChecksumGeneratorMd5() self.checksum_generator_supplement = ChecksumGeneratorMd5()
elif self.backend == 'WORM':
self.checksum_generator_supplement = ChecksumGeneratorWORM()
else: else:
self.checksum_generator_supplement = ChecksumGeneratorCrc32() self.checksum_generator_supplement = ChecksumGeneratorCrc32()
...@@ -191,12 +207,20 @@ class ChecksumGeneratorGitAnnex(object): ...@@ -191,12 +207,20 @@ class ChecksumGeneratorGitAnnex(object):
if annex_info['present'] != True: if annex_info['present'] != True:
return self.checksum_generator_supplement.get_checksum(file) return self.checksum_generator_supplement.get_checksum(file)
return { return {
'checksum': annex_info['key'].split('--')[1], 'checksum': self._get_checksum_from_annex_info(annex_info),
'checksumType': annex_info['key'].split('-')[0], 'checksumType': annex_info['key'].split('-')[0],
'fileLength': os.path.getsize(file), 'fileLength': os.path.getsize(file),
'path': file 'path': file
} }
def _get_checksum_from_annex_info(self, annex_info):
if self.backend == 'MD5':
return annex_info['key'].split('--')[1]
elif self.backend == 'WORM':
return annex_info['key'][5:]
else:
raise ValueError("Git annex backend not supported: " + self.backend)
def _get_annex_backend(self): def _get_annex_backend(self):
with open('.gitattributes') as gitattributes: with open('.gitattributes') as gitattributes:
for line in gitattributes.readlines(): for line in gitattributes.readlines():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment