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

Removed useless import and improved code style.

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