Commit 403c0999 authored by Lucas Carvalho's avatar Lucas Carvalho

Removed useless import and improved code style.

parent ca0599e3
......@@ -15,7 +15,6 @@
import os
import urllib
import re
import posixpath
import base64
import hashlib
......@@ -46,11 +45,13 @@ def _get_sha256_from_file(path):
' The path is not a file: %s ' % path
return _get_hash_from_file(path, hashlib.sha256())
def check_sha256sum(path, sha256sum):
"""Tell whether the SHA256sum checksum of the file at path matches
"""
return sha256sum == _get_hash_from_file(path, hashlib.sha256())
def _update_network_cached_map(network_cache, sha256sum, url, logger):
"""
If the url is not into the map file, it must be updated.
......@@ -134,6 +135,7 @@ def download_network_cached(network_cache, path, url, logger):
return True
def upload_network_cached(network_cache, external_url, path, logger):
"""Upload file to a network cache server"""
if network_cache in [None, '']:
......@@ -148,14 +150,15 @@ def upload_network_cached(network_cache, external_url, path, logger):
url = os.path.join(network_cache, sha256sum)
try:
result = urllib.urlopen(url, urllib.urlencode({
"data" : base64.encodestring(data)}))
"data": base64.encodestring(data)}))
if result.code == 200 and \
json.loads(result.read()).get('sha') == sha256sum:
_update_network_cached_map(network_cache, sha256sum,
external_url, logger)
except (IOError, EOFError), e:
logger.info('Fail to upload cache on %s. %s' % (external_url, str(e)))
logger.info('Fail to upload cache on %s. %s' % \
(external_url, str(e)))
finally:
f.close()
return True
......
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