include user-agent in update requests
This commit is contained in:
parent
537eba0f0f
commit
d5a57708d3
1 changed files with 20 additions and 16 deletions
|
@ -10,7 +10,6 @@ import urllib2
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import requests
|
|
||||||
import ed25519
|
import ed25519
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
|
@ -32,22 +31,27 @@ def verify(release):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def download_module(url, filename):
|
def get(url, filename=None):
|
||||||
print 'download', os.path.basename(filename)
|
request = urllib2.Request(url, headers={
|
||||||
dirname = os.path.dirname(filename)
|
'User-Agent': settings.USER_AGENT
|
||||||
if dirname and not os.path.exists(dirname):
|
})
|
||||||
os.makedirs(dirname)
|
with closing(urllib2.urlopen(request)) as u:
|
||||||
with open(filename, 'w') as f:
|
if not filename:
|
||||||
with closing(urllib2.urlopen(url)) as u:
|
data = u.read()
|
||||||
data = u.read(4096)
|
return data
|
||||||
while data:
|
else:
|
||||||
f.write(data)
|
dirname = os.path.dirname(filename)
|
||||||
|
if dirname and not os.path.exists(dirname):
|
||||||
|
os.makedirs(dirname)
|
||||||
|
with open(filename, 'w') as fd:
|
||||||
data = u.read(4096)
|
data = u.read(4096)
|
||||||
|
while data:
|
||||||
|
fd.write(data)
|
||||||
|
data = u.read(4096)
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
if settings.release:
|
if settings.release:
|
||||||
r = requests.get(RELEASE_URL)
|
release_data = get(RELEASE_URL)
|
||||||
release_data = r.content
|
|
||||||
release = json.loads(release_data)
|
release = json.loads(release_data)
|
||||||
old = settings.release['modules']['openmedialibrary']['version']
|
old = settings.release['modules']['openmedialibrary']['version']
|
||||||
new = release['modules']['openmedialibrary']['version']
|
new = release['modules']['openmedialibrary']['version']
|
||||||
|
@ -56,8 +60,7 @@ def check():
|
||||||
def download():
|
def download():
|
||||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||||
return True
|
return True
|
||||||
r = requests.get(RELEASE_URL)
|
release_data = get(RELEASE_URL)
|
||||||
release_data = r.content
|
|
||||||
release = json.loads(release_data)
|
release = json.loads(release_data)
|
||||||
old = settings.release['modules']['openmedialibrary']['version']
|
old = settings.release['modules']['openmedialibrary']['version']
|
||||||
new = release['modules']['openmedialibrary']['version']
|
new = release['modules']['openmedialibrary']['version']
|
||||||
|
@ -70,7 +73,8 @@ def download():
|
||||||
module_tar = os.path.join(settings.updates_path, release['modules'][module]['name'])
|
module_tar = os.path.join(settings.updates_path, release['modules'][module]['name'])
|
||||||
url = RELEASE_URL.replace('release.json', release['modules'][module]['name'])
|
url = RELEASE_URL.replace('release.json', release['modules'][module]['name'])
|
||||||
if not os.path.exists(module_tar):
|
if not os.path.exists(module_tar):
|
||||||
download_module(url, module_tar)
|
print 'download', os.path.basename(module_tar)
|
||||||
|
get(url, module_tar)
|
||||||
if ox.sha1sum(module_tar) != release['modules'][module]['sha1']:
|
if ox.sha1sum(module_tar) != release['modules'][module]['sha1']:
|
||||||
os.unlink(module_tar)
|
os.unlink(module_tar)
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue