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

Simplify library existence detection.

parent 5d5ebff6
...@@ -20,6 +20,13 @@ import re ...@@ -20,6 +20,13 @@ import re
import urllib import urllib
import urlparse import urlparse
try:
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
DirectoryNotFound
except ImportError:
LIBNETWORKCACHE_ENABLED = False
else:
LIBNETWORKCACHE_ENABLED = True
_md5_re = re.compile(r'md5=([a-f0-9]+)') _md5_re = re.compile(r'md5=([a-f0-9]+)')
...@@ -52,13 +59,9 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None): ...@@ -52,13 +59,9 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None):
return True if download succeeded. return True if download succeeded.
""" """
try: if not LIBNETWORKCACHE_ENABLED:
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
DirectoryNotFound
except:
return False return False
if sha_cache in (None, '',): if sha_cache in (None, '',):
# Not able to use network cache # Not able to use network cache
return False return False
...@@ -94,10 +97,7 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None): ...@@ -94,10 +97,7 @@ def download_network_cached(sha_dir, sha_cache, path, url, logger, md5sum=None):
def upload_network_cached(sha_cache, sha_dir, external_url, path, logger): def upload_network_cached(sha_cache, sha_dir, external_url, path, logger):
"""Upload file to a network cache server""" """Upload file to a network cache server"""
try: if not LIBNETWORKCACHE_ENABLED:
from slapos.libnetworkcache import NetworkcacheClient, UploadError, \
DirectoryNotFound
except:
return False return False
if sha_cache in [None, ''] or sha_dir in [None, '']: if sha_cache in [None, ''] or sha_dir in [None, '']:
......
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