move update api to update.py

This commit is contained in:
j 2014-08-22 19:46:45 +02:00
parent 2cd77e07a2
commit 5ede07edca
2 changed files with 33 additions and 32 deletions

View file

@ -10,10 +10,9 @@ import ox
from oxtornado import actions
import settings
import item.api
import user.api
import update
def selectFolder(data):
@ -78,33 +77,3 @@ def autocompleteFolder(data):
'items': ox.sorted_strings(folders)
}
actions.register(autocompleteFolder, cache=False)
def getVersion(data):
'''
check if new version is available
'''
response = {
'current': settings.MINOR_VERSION,
'upgrade': False,
}
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
return response
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
return response
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
release = json.load(fd)
current = settings.release['modules']['openmedialibrary']['version']
response['current'] = current
new = release['modules']['openmedialibrary']['version']
response['new'] = new
response['update'] = current < new
return response
actions.register(getVersion, cache=False)
def restart(data):
'''
restart (and upgrade if upgrades are available)
'''
subprocess.Popen(['./ctl', 'restart'], close_fds=True)
return {}
actions.register(restart, cache=False)

View file

@ -12,9 +12,11 @@ import subprocess
import ed25519
import ox
from oxtornado import actions
import settings
ENCODING='base64'
RELEASE_URL = 'http://downloads.openmedialibrary.com/release.json'
@ -125,3 +127,33 @@ def install():
subprocess.call(cmd)
return True
return True
def getVersion(data):
'''
check if new version is available
'''
response = {
'current': settings.MINOR_VERSION,
'upgrade': False,
}
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
return response
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
return response
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
release = json.load(fd)
current = settings.release['modules']['openmedialibrary']['version']
response['current'] = current
new = release['modules']['openmedialibrary']['version']
response['new'] = new
response['update'] = current < new
return response
actions.register(getVersion, cache=False)
def restart(data):
'''
restart (and upgrade if upgrades are available)
'''
subprocess.Popen(['./ctl', 'restart'], close_fds=True)
return {}
actions.register(restart, cache=False)