check for new version in getVersion

This commit is contained in:
j 2016-01-04 17:32:40 +05:30
parent 8f80e60766
commit 2fbe881935
2 changed files with 18 additions and 9 deletions

View file

@ -75,12 +75,19 @@ def current_version(module):
version = '' version = ''
return version return version
def download(): def get_latest_release():
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
return True
release_data = get(settings.server.get('release_url')) release_data = get(settings.server.get('release_url'))
release = json.loads(release_data.decode('utf-8')) release = json.loads(release_data.decode('utf-8'))
if verify(release): if verify(release):
with open(os.path.join(settings.updates_path, 'release.json'), 'wb') as fd:
fd.write(release_data)
return release
def download():
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
return True
release = get_latest_release()
if release:
ox.makedirs(settings.updates_path) ox.makedirs(settings.updates_path)
os.chdir(os.path.dirname(settings.base_dir)) os.chdir(os.path.dirname(settings.base_dir))
current_files = {'release.json'} current_files = {'release.json'}
@ -90,14 +97,13 @@ def download():
base_url = settings.server.get('release_url').rsplit('/', 1)[0] base_url = settings.server.get('release_url').rsplit('/', 1)[0]
url = '/'.join([base_url, release['modules'][module]['name']]) url = '/'.join([base_url, release['modules'][module]['name']])
if not os.path.exists(module_tar): if not os.path.exists(module_tar):
print('downloading', os.path.basename(module_tar)) logger.debug('download', os.path.basename(module_tar))
get(url, module_tar) get(url, module_tar)
if ox.sha1sum(module_tar) != release['modules'][module]['sha1']: if ox.sha1sum(module_tar) != release['modules'][module]['sha1']:
logger.debug('invalid checksum', os.path.basename(module_tar))
os.unlink(module_tar) os.unlink(module_tar)
return False return False
current_files.add(os.path.basename(module_tar)) current_files.add(os.path.basename(module_tar))
with open(os.path.join(settings.updates_path, 'release.json'), 'wb') as fd:
fd.write(release_data)
for f in set(next(os.walk(settings.updates_path))[2])-current_files: for f in set(next(os.walk(settings.updates_path))[2])-current_files:
os.unlink(os.path.join(settings.updates_path, f)) os.unlink(os.path.join(settings.updates_path, f))
return True return True
@ -189,6 +195,7 @@ def getVersion(data):
''' '''
response['update'] = False response['update'] = False
else: else:
get_latest_release()
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')): if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
return response return response
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')):
@ -207,6 +214,8 @@ def restart(data):
''' '''
restart (and upgrade if upgrades are available) restart (and upgrade if upgrades are available)
''' '''
if data.get('update'):
download()
subprocess.Popen([os.path.join(settings.base_dir, 'ctl'), 'restart'], close_fds=True) subprocess.Popen([os.path.join(settings.base_dir, 'ctl'), 'restart'], close_fds=True)
return {} return {}
actions.register(restart, cache=False) actions.register(restart, cache=False)

View file

@ -56,7 +56,7 @@ oml.ui.appDialog = function() {
disabled: true, disabled: true,
title: 'Installing...' title: 'Installing...'
}); });
oml.api.restart(function(response) { oml.api.restart({update: true},function(response) {
if (response.status.code == 200) { if (response.status.code == 200) {
setTimeout(reload, 500); setTimeout(reload, 500);
} }
@ -66,9 +66,9 @@ oml.ui.appDialog = function() {
} }
} else { } else {
if (response.data.current == 'git') { if (response.data.current == 'git') {
$update.html(Ox._('No updates available')); $update.html(Ox._('You\'re up to date'));
} else { } else {
$update.html(Ox._('You are running Version {0}. No updates available', [response.data.current])); $update.html(Ox._('You are running Version {0}. You\'re up to date.', [response.data.current]));
} }
} }
}); });