Commit 76b9961e authored by Yingjie Xu's avatar Yingjie Xu

Fix json tags.

parent ebefd105
...@@ -88,7 +88,8 @@ class Software(object): ...@@ -88,7 +88,8 @@ class Software(object):
if download_network_cached( if download_network_cached(
self.download_binary_cache_url, self.download_binary_cache_url,
self.download_binary_dir_url, self.download_binary_dir_url,
self.url, self.software_url_hash, self.url, self.software_root,
self.software_url_hash,
tarpath, self.logger, tarpath, self.logger,
self.signature_certificate_list): self.signature_certificate_list):
tar = tarfile.open(tarpath) tar = tarfile.open(tarpath)
......
...@@ -22,6 +22,7 @@ import urlparse ...@@ -22,6 +22,7 @@ import urlparse
import traceback import traceback
import utils import utils
import json import json
import platform
try: try:
try: try:
...@@ -54,8 +55,8 @@ def fallback_call(function): ...@@ -54,8 +55,8 @@ def fallback_call(function):
@fallback_call @fallback_call
def download_network_cached(cache_url, dir_url, software_url, key, path, def download_network_cached(cache_url, dir_url, software_url, software_root,
logger, signature_certificate_list): key, path, logger, signature_certificate_list):
"""Downloads from a network cache provider """Downloads from a network cache provider
return True if download succeeded. return True if download succeeded.
...@@ -77,27 +78,37 @@ def download_network_cached(cache_url, dir_url, software_url, key, path, ...@@ -77,27 +78,37 @@ def download_network_cached(cache_url, dir_url, software_url, key, path,
logger.info('Downloading %s binary from network cache.' % software_url) logger.info('Downloading %s binary from network cache.' % software_url)
try: try:
file_descriptor = None
json_entry_list = nc.select_generic(key) json_entry_list = nc.select_generic(key)
for entry in json_entry_list: for entry in json_entry_list:
json_information, _ = entry json_information, _ = entry
try: try:
tags = json.loads(json_information) tags = json.loads(json_information)
if tags.get('machine') != platform.machine():
continue
if tags.get('os') != str(platform.linux_distribution()):
continue
if tags.get('software_url') != software_url:
continue
if tags.get('software_root') != software_root:
continue
sha512 = tags.get('sha512') sha512 = tags.get('sha512')
file_descriptor = nc.download(sha512) file_descriptor = nc.download(sha512)
break break
except Exception: except Exception:
continue continue
f = open(path, 'w+b') if file_descriptor is not None:
try: f = open(path, 'w+b')
shutil.copyfileobj(file_descriptor, f) try:
finally: shutil.copyfileobj(file_descriptor, f)
f.close() finally:
file_descriptor.close() f.close()
file_descriptor.close()
return True
except (IOError, DirectoryNotFound), e: except (IOError, DirectoryNotFound), e:
logger.info('Failed to download from network cache %s: %s' % \ logger.info('Failed to download from network cache %s: %s' % \
(software_url, str(e))) (software_url, str(e)))
return False return False
return True
@fallback_call @fallback_call
...@@ -114,17 +125,14 @@ def upload_network_cached(software_root, software_url, cached_key, ...@@ -114,17 +125,14 @@ def upload_network_cached(software_root, software_url, cached_key,
logger.info('Uploading %s binary into network cache.' % software_url) logger.info('Uploading %s binary into network cache.' % software_url)
# YXU: "file" and "urlmd5" should be removed when server side is ready
kw = dict( kw = dict(
file=software_url, file="file",
urlmd5=cached_key, urlmd5="urlmd5",
software_url=software_url, software_url=software_url,
gcc_version="gcc-version",
libc_version="libc-version",
libcxx_version="libcxx-version",
kernel_version="kernel-version",
software_root=software_root, software_root=software_root,
arch="arch", machine=platform.machine(),
python_version="python-version" os=str(platform.linux_distrubution())
) )
f = open(path, 'r') f = open(path, 'r')
......
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