Commit a86473e1 authored by Lucas Carvalho's avatar Lucas Carvalho

Simplified the code, making one request instead of two... When the buildout...

Simplified the code, making one request instead of two... When the buildout upload the file, it must send the URL information as well to update the networkcached.map directly.
parent 03b903d4
...@@ -52,10 +52,13 @@ def check_sha256sum(path, sha256sum): ...@@ -52,10 +52,13 @@ def check_sha256sum(path, sha256sum):
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_log(sha256sum, url):
""" """Update the networkcached.log file.
If the url is not into the map file, it must be updated.
Adding the last sha256sum and URL which has been retrieved from networkcached server.
""" """
Update the networkcached.log file.
# Keep the log # Keep the log
map_path = os.path.join(os.environ.get('PWD'), '.networkcached.log') map_path = os.path.join(os.environ.get('PWD'), '.networkcached.log')
mode = 'r+' mode = 'r+'
...@@ -75,18 +78,6 @@ def _update_network_cached_map(network_cache, sha256sum, url, logger): ...@@ -75,18 +78,6 @@ def _update_network_cached_map(network_cache, sha256sum, url, logger):
finally: finally:
f.close() f.close()
# Update the map at networkcached server.
network_cached_url = os.path.join(network_cache, 'map/add')
try:
result = urllib.urlopen(network_cached_url, \
urllib.urlencode({'sha256sum': sha256sum, 'url': url}))
if int(result.code) != 200:
logger.info('Fail to update the network cache map: %s %s' % \
(sha256sum, url))
except IOError, e:
logger.info('An error occurred to update the map in networkcached.' \
' %s' % str(e))
def get_sha256sum_from_networkcached(network_cache, url, logger): def get_sha256sum_from_networkcached(network_cache, url, logger):
""" """
...@@ -150,11 +141,10 @@ def upload_network_cached(network_cache, external_url, path, logger): ...@@ -150,11 +141,10 @@ 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 \ 'url': base64.encodestring(external_url)}))
json.loads(result.read()).get('sha') == sha256sum: if result.code == 200:
_update_network_cached_map(network_cache, sha256sum, _update_network_cached_map(sha256sum, external_url)
external_url, logger)
except (IOError, EOFError), e: except (IOError, EOFError), e:
logger.info('Fail to upload cache on %s. %s' % \ logger.info('Fail to upload cache on %s. %s' % \
......
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