Commit e388ee36 authored by Łukasz Nowak's avatar Łukasz Nowak

Follow slapos.libnetworkcache interface changes.

Use signature_certificate_list if strings instead of signature_certificate_file.
Additionaly simplify backward compatbility: just do not play with it.
parent 6be3228b
...@@ -77,8 +77,8 @@ class Download(object): ...@@ -77,8 +77,8 @@ class Download(object):
self.upload_dir_url = options.get('__networkcache__upload-dir-url') self.upload_dir_url = options.get('__networkcache__upload-dir-url')
self.upload_cache_url = options.get( self.upload_cache_url = options.get(
'__networkcache__upload-cache-url') '__networkcache__upload-cache-url')
self.signature_certificate_file = options.get( self.signature_certificate_list = options.get(
'__networkcache__signature-certificate-file') '__networkcache__signature-certificate-list')
self.signature_private_key_file = options.get( self.signature_private_key_file = options.get(
'__networkcache__signature-private-key-file') '__networkcache__signature-private-key-file')
...@@ -188,8 +188,7 @@ class Download(object): ...@@ -188,8 +188,7 @@ class Download(object):
try: try:
if not download_network_cached(self.download_dir_url, if not download_network_cached(self.download_dir_url,
self.download_cache_url, tmp_path, url, self.logger, self.download_cache_url, tmp_path, url, self.logger,
self.signature_certificate_file, self.signature_certificate_list, md5sum):
self.signature_private_key_file, md5sum):
# Download from original url # Download from original url
tmp_path, headers = urllib.urlretrieve(url, tmp_path) tmp_path, headers = urllib.urlretrieve(url, tmp_path)
if not check_md5sum(tmp_path, md5sum): if not check_md5sum(tmp_path, md5sum):
...@@ -199,7 +198,6 @@ class Download(object): ...@@ -199,7 +198,6 @@ class Download(object):
if self.upload_cache_url and self.upload_dir_url: if self.upload_cache_url and self.upload_dir_url:
upload_network_cached(self.upload_dir_url, upload_network_cached(self.upload_dir_url,
self.upload_cache_url, url, tmp_path, self.logger, self.upload_cache_url, url, tmp_path, self.logger,
self.signature_certificate_file,
self.signature_private_key_file) self.signature_private_key_file)
finally: finally:
os.close(handle) os.close(handle)
......
...@@ -345,7 +345,7 @@ class Installer: ...@@ -345,7 +345,7 @@ class Installer:
download_cache_url=None, download_cache_url=None,
upload_dir_url=None, upload_dir_url=None,
upload_cache_url=None, upload_cache_url=None,
signature_certificate_file=None, signature_certificate_list=None,
signature_private_key_file=None signature_private_key_file=None
): ):
self._dest = dest self._dest = dest
...@@ -419,7 +419,7 @@ class Installer: ...@@ -419,7 +419,7 @@ class Installer:
self._download_cache_url = download_cache_url self._download_cache_url = download_cache_url
self._upload_dir_url = upload_dir_url self._upload_dir_url = upload_dir_url
self._upload_cache_url = upload_cache_url self._upload_cache_url = upload_cache_url
self._signature_certificate_file = signature_certificate_file self._signature_certificate_list = signature_certificate_list
self._signature_private_key_file = signature_private_key_file self._signature_private_key_file = signature_private_key_file
_allowed_eggs_from_site_packages_regex = None _allowed_eggs_from_site_packages_regex = None
...@@ -725,12 +725,12 @@ class Installer: ...@@ -725,12 +725,12 @@ class Installer:
new_location = os.path.join(tmp, filename) new_location = os.path.join(tmp, filename)
if not download_network_cached(self._download_dir_url, if not download_network_cached(self._download_dir_url,
self._download_cache_url, new_location, dist.location, logger, self._download_cache_url, new_location, dist.location, logger,
self._signature_certificate_file, self._signature_private_key_file): self._signature_certificate_list):
new_location = self._index.download(dist.location, tmp) new_location = self._index.download(dist.location, tmp)
if self._upload_cache_url and self._upload_dir_url: if self._upload_cache_url and self._upload_dir_url:
upload_network_cached(self._upload_dir_url, upload_network_cached(self._upload_dir_url,
self._upload_cache_url, dist.location, new_location, logger, self._upload_cache_url, dist.location, new_location, logger,
self._signature_certificate_file, self._signature_private_key_file) self._signature_private_key_file)
if (download_cache if (download_cache
and (realpath(new_location) == realpath(dist.location)) and (realpath(new_location) == realpath(dist.location))
...@@ -1111,7 +1111,7 @@ def install(specs, dest, ...@@ -1111,7 +1111,7 @@ def install(specs, dest,
include_site_packages=None, allowed_eggs_from_site_packages=None, include_site_packages=None, allowed_eggs_from_site_packages=None,
prefer_final=None, download_dir_url=None, download_cache_url=None, prefer_final=None, download_dir_url=None, download_cache_url=None,
upload_dir_url=None, upload_cache_url=None, upload_dir_url=None, upload_cache_url=None,
signature_certificate_file=None, signature_private_key_file=None): signature_certificate_list=None, signature_private_key_file=None):
installer = Installer( installer = Installer(
dest, links, index, executable, always_unzip, path, newest, dest, links, index, executable, always_unzip, path, newest,
versions, use_dependency_links, allow_hosts=allow_hosts, versions, use_dependency_links, allow_hosts=allow_hosts,
...@@ -1120,7 +1120,7 @@ def install(specs, dest, ...@@ -1120,7 +1120,7 @@ def install(specs, dest,
prefer_final=prefer_final, download_dir_url=download_dir_url, prefer_final=prefer_final, download_dir_url=download_dir_url,
download_cache_url=download_cache_url, upload_dir_url=upload_dir_url, download_cache_url=download_cache_url, upload_dir_url=upload_dir_url,
upload_cache_url=upload_cache_url, upload_cache_url=upload_cache_url,
signature_certificate_file=signature_certificate_file, signature_certificate_list=signature_certificate_list,
signature_private_key_file=signature_private_key_file) signature_private_key_file=signature_private_key_file)
return installer.install(specs, working_set) return installer.install(specs, working_set)
......
...@@ -52,7 +52,7 @@ def get_directory_key(url): ...@@ -52,7 +52,7 @@ def get_directory_key(url):
def download_network_cached(dir_url, cache_url, path, url, logger, def download_network_cached(dir_url, cache_url, path, url, logger,
signature_certificate_file, signature_private_key_file, md5sum=None): signature_certificate_list, md5sum=None):
"""Downloads from a network cache provider """Downloads from a network cache provider
If something fail (providor be offline, or hash_string fail), we ignore If something fail (providor be offline, or hash_string fail), we ignore
...@@ -69,15 +69,18 @@ def download_network_cached(dir_url, cache_url, path, url, logger, ...@@ -69,15 +69,18 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
md5sum = _get_md5_from_url(url) md5sum = _get_md5_from_url(url)
signature_certificate_file_list = signature_certificate_file.split('\n')
directory_key = get_directory_key(url) directory_key = get_directory_key(url)
url = os.path.basename(url) url = os.path.basename(url)
try:
nc = NetworkcacheClient(cache_url, dir_url,
signature_certificate_list=signature_certificate_list)
except TypeError:
logger.warning('Incompatible version of networkcache, not using it.')
return False
logger.info('Downloading %s from network cache.' % url) logger.info('Downloading %s from network cache.' % url)
try: try:
nc = getNetworkcacheClient(shacache=cache_url, shadir=dir_url,
signature_private_key_file=signature_private_key_file,
signature_certificate_file_list=signature_certificate_file_list)
file_descriptor = nc.select(directory_key) file_descriptor = nc.select(directory_key)
f = open(path, 'w+b') f = open(path, 'w+b')
...@@ -99,7 +102,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger, ...@@ -99,7 +102,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
def upload_network_cached(dir_url, cache_url, external_url, path, logger, def upload_network_cached(dir_url, cache_url, external_url, path, logger,
signature_certificate_file, signature_private_key_file): signature_private_key_file):
"""Upload file to a network cache server""" """Upload file to a network cache server"""
if not LIBNETWORKCACHE_ENABLED: if not LIBNETWORKCACHE_ENABLED:
return False return False
...@@ -114,13 +117,16 @@ def upload_network_cached(dir_url, cache_url, external_url, path, logger, ...@@ -114,13 +117,16 @@ def upload_network_cached(dir_url, cache_url, external_url, path, logger,
directory_key = get_directory_key(external_url) directory_key = get_directory_key(external_url)
kw = dict(file_name=file_name, kw = dict(file_name=file_name,
urlmd5=hashlib.md5(external_url).hexdigest()) urlmd5=hashlib.md5(external_url).hexdigest())
signature_certificate_file_list = signature_certificate_file.split('\n')
f = open(path, 'r') f = open(path, 'r')
try: try:
nc = getNetworkcacheClient(shacache=cache_url, shadir=dir_url, nc = NetworkcacheClient(cache_url, dir_url,
signature_certificate_file_list=signature_certificate_file_list, signature_private_key_file=signature_private_key_file)
signature_private_key_file=signature_private_key_file) except TypeError:
logger.warning('Incompatible version of networkcache, not using it.')
return False
try:
return nc.upload(f, directory_key, **kw) return nc.upload(f, directory_key, **kw)
except (IOError, UploadError), e: except (IOError, UploadError), e:
logger.info('Fail to upload file. %s' % \ logger.info('Fail to upload file. %s' % \
...@@ -150,18 +156,4 @@ def get_filename_from_url(url): ...@@ -150,18 +156,4 @@ def get_filename_from_url(url):
return name return name
def getNetworkcacheClient(shacache, shadir, signature_private_key_file,
signature_certificate_file_list):
"""
Provides backward compatibility to instantiate NetworkcacheClient.
"""
try:
nc = NetworkcacheClient(shacache, shadir, signature_private_key_file,
signature_certificate_file_list)
except TypeError:
nc = NetworkcacheClient(shacache, shadir)
return nc
from download import check_md5sum from download import check_md5sum
...@@ -94,7 +94,7 @@ class Eggs(object): ...@@ -94,7 +94,7 @@ class Eggs(object):
('__networkcache__upload-cache-url', 'upload_cache_url'), ('__networkcache__upload-cache-url', 'upload_cache_url'),
('__networkcache__upload-dir-url', 'upload_dir_url'), ('__networkcache__upload-dir-url', 'upload_dir_url'),
('__networkcache__signature-private-key-file', 'signature_private_key_file'), ('__networkcache__signature-private-key-file', 'signature_private_key_file'),
('__networkcache__signature-certificate-file', 'signature_certificate_file')): ('__networkcache__signature-certificate-list', 'signature_certificate_list')):
if option_key in b_options: if option_key in b_options:
kw[kw_key] = b_options[option_key] kw[kw_key] = b_options[option_key]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment