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):
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.
def _update_network_cached_log(sha256sum, url):
"""Update the networkcached.log file.
Adding the last sha256sum and URL which has been retrieved from networkcached server.
"""
Update the networkcached.log file.
# Keep the log
map_path = os.path.join(os.environ.get('PWD'), '.networkcached.log')
mode = 'r+'
......@@ -75,18 +78,6 @@ def _update_network_cached_map(network_cache, sha256sum, url, logger):
finally:
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):
"""
......@@ -150,11 +141,10 @@ 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)}))
if result.code == 200 and \
json.loads(result.read()).get('sha') == sha256sum:
_update_network_cached_map(network_cache, sha256sum,
external_url, logger)
'data': base64.encodestring(data),
'url': base64.encodestring(external_url)}))
if result.code == 200:
_update_network_cached_map(sha256sum, external_url)
except (IOError, EOFError), e:
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