| |
@@ -94,7 +94,7 @@
|
| |
return super(StreamLookasideCache, self).remote_file_exists(
|
| |
_name, filename, hashstr)
|
| |
|
| |
- def upload(self, name, filename, hashstr, offline=False):
|
| |
+ def upload(self, name, filename, hashstr, offline=False, **kwargs):
|
| |
"""
|
| |
Uploads a file to lookaside cache.
|
| |
|
| |
@@ -169,13 +169,32 @@
|
| |
|
| |
|
| |
class SIGLookasideCache(CGILookasideCache):
|
| |
- def __init__(self, hashtype, download_url, upload_url, name, branch):
|
| |
+ def __init__(self, hashtype, download_url, upload_url, name, branch, structure='hash'):
|
| |
super(SIGLookasideCache, self).__init__(
|
| |
hashtype, download_url, upload_url, client_cert="/home/bstinson/.centos.cert")
|
| |
+
|
| |
+ self.name = name
|
| |
self.branch = branch
|
| |
-
|
| |
- self.download_path = (
|
| |
- '%(name)s/%(branch)s/%(hash)s')
|
| |
+ self.structure = structure
|
| |
+
|
| |
+ @property
|
| |
+ def download_path(self):
|
| |
+ if self.structure == 'hash':
|
| |
+ return '%(name)s/%(filename)s/%(hashtype)s/%(hash)s'
|
| |
+ return '%(name)s/%(branch)s/%(hash)s'
|
| |
+
|
| |
+ def get_download_url(self, name, filename, hash, hashtype=None, **kwargs):
|
| |
+ if self.structure == 'hash':
|
| |
+ path_dict = {
|
| |
+ 'name': name,
|
| |
+ 'filename': filename,
|
| |
+ 'hash': hash,
|
| |
+ 'hashtype': hashtype
|
| |
+ }
|
| |
+ path = self.download_path % path_dict
|
| |
+ return os.path.join(self.download_url, path)
|
| |
+
|
| |
+ return super(SIGLookasideCache, self).get_download_url(name, filename, hash, hashtype, **kwargs)
|
| |
|
| |
def remote_file_exists(self, name, filename, hash):
|
| |
"""Verify whether a file exists on the lookaside cache
|
| |
@@ -201,8 +220,9 @@
|
| |
|
| |
post_data = [('name', _name),
|
| |
('%ssum' % self.hashtype, hash),
|
| |
- ('branch', self.branch),
|
| |
('filename', filename)]
|
| |
+ if self.structure == 'branch':
|
| |
+ post_data.append(('branch', self.branch))
|
| |
|
| |
with io.BytesIO() as buf:
|
| |
c = pycurl.Curl()
|
| |
@@ -279,8 +299,9 @@
|
| |
self.log.info("Uploading: %s", filepath)
|
| |
post_data = [('name', name),
|
| |
('%ssum' % self.hashtype, hash),
|
| |
- ('branch', self.branch),
|
| |
('file', (pycurl.FORM_FILE, filepath))]
|
| |
+ if self.structure == 'branch':
|
| |
+ post_data.append(('branch', self.branch))
|
| |
|
| |
with io.BytesIO() as buf:
|
| |
c = pycurl.Curl()
|
| |
Is there any way for us to add a command line switch to override/force the lookaside structure? Not necessarily something we need to address now, but would be a good enhancement I think