Commit f18c3b61 authored by Yingjie Xu's avatar Yingjie Xu

Uses binary cache.

parent 4b01f2ce
......@@ -20,6 +20,14 @@ import re
import shutil
import urlparse
import traceback
import ctypes
from ctypes import util
SYS, _, KERNEL, _, ARCH = os.uname()
LIBC = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
LIBC_VERSION_FUN = LIBC.gnu_get_libc_version
LIBC_VERSION_FUN.restype = ctypes.c_char_p
LIBC_VERSION = "libc-%s" % LIBC_VERSION_FUN()
try:
try:
......@@ -76,7 +84,7 @@ def get_directory_key(url):
@fallback_call
def download_network_cached(dir_url, cache_url, path, url, logger,
signature_certificate_list, md5sum=None):
signature_certificate_list, md5sum=None, binary_mode=False):
"""Downloads from a network cache provider
If something fail (providor be offline, or hash_string fail), we ignore
......@@ -92,8 +100,12 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
if md5sum is None:
md5sum = _get_md5_from_url(url)
if binary_mode:
directory_key = "binary-%s-%s-%s" % \
(os.path.basename(path), SYS, ARCH)
else:
directory_key = get_directory_key(url)
directory_key = get_directory_key(url)
url = os.path.basename(url)
if len(signature_certificate_list) == 0:
......@@ -108,7 +120,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
logger.info('Downloading %s from network cache.' % url)
try:
file_descriptor = nc.select(directory_key)
file_descriptor = nc.select(directory_key, binary_mode=binary_mode)
f = open(path, 'w+b')
try:
......@@ -131,7 +143,7 @@ def download_network_cached(dir_url, cache_url, path, url, logger,
@fallback_call
def upload_network_cached(dir_url, cache_url, external_url, path, logger,
signature_private_key_file, shacache_cert_file, shacache_key_file,
shadir_cert_file, shadir_key_file):
shadir_cert_file, shadir_key_file, binary_mode=False):
"""Upload file to a network cache server"""
if not LIBNETWORKCACHE_ENABLED:
return False
......@@ -141,11 +153,19 @@ def upload_network_cached(dir_url, cache_url, external_url, path, logger,
logger.info('Uploading %s into network cache.' % external_url)
file_name = get_filename_from_url(external_url)
directory_key = get_directory_key(external_url)
kw = dict(file_name=file_name,
urlmd5=hashlib.md5(external_url).hexdigest())
if binary_mode:
file_name = get_filename_from_url(path)
directory_key = "binary-%s-%s-%s" % \
(file_name, SYS, ARCH)
kw = dict(file_name=file_name,
kernel=KERNEL,
libc_version=LIBC_VERSION,
urlmd5=hashlib.md5(external_url).hexdigest())
else:
file_name = get_filename_from_url(external_url)
directory_key = get_directory_key(external_url)
kw = dict(file_name=file_name,
urlmd5=hashlib.md5(external_url).hexdigest())
f = open(path, 'r')
# convert '' into None in order to call nc nicely
......
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