visual feedback during updates

This commit is contained in:
j 2016-01-12 20:30:51 +05:30
commit 516397ae44
9 changed files with 274 additions and 25 deletions

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os
import sys
import signal
@ -23,6 +22,7 @@ import setup
import state
import tasks
import websocket
import update
import logging
@ -31,13 +31,15 @@ logger = logging.getLogger(__name__)
class MainHandler(OMLHandler):
def get(self, path):
path = os.path.join(settings.static_path, 'html', 'oml.html')
with open(path) as fd:
content = fd.read()
version = settings.MINOR_VERSION.split('-')[0]
if version == 'git':
version = int(time.mktime(time.gmtime()))
content = content.replace('oml.js?1', 'oml.js?%s' % version)
path = os.path.join(settings.static_path, 'html', 'oml.html')
with open(path) as fd:
content = fd.read()
content = content.replace('.js?1', '.js?%s' % version)
if state.update:
content = content.replace('oml.js', 'oml.update.js')
self.set_header('Content-Type', 'text/html')
self.set_header('Content-Length', str(len(content)))
self.write(content)
@ -133,11 +135,11 @@ def run():
with open(PID, 'w') as pid:
pid.write('%s' % os.getpid())
state.update = update.update_available()
state.PID = PID
state.http_server = http_server
state.main = IOLoop.instance()
state.cache = Cache(ttl=60)
state.tasks = tasks.Tasks()
def start_node():
import downloads
@ -156,7 +158,13 @@ def run():
else:
nodes.publish_node()
state.main.add_callback(publish)
state.main.add_callback(start_node)
if not state.update:
state.tasks = tasks.Tasks()
state.main.add_callback(start_node)
else:
state.tasks = update.Update()
if ':' in settings.server['address']:
host = '[%s]' % settings.server['address']
elif not settings.server['address']:

View file

@ -78,7 +78,8 @@ else:
NODE_PROTOCOL="0.4"
VERSION="%s.%s" % (NODE_PROTOCOL, MINOR_VERSION)
USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
DEBUG_HTTP = server.get('debug_http', False)
DB_VERSION = 0

View file

@ -2,11 +2,13 @@ bandwidth = None
host = None
main = None
nodes = False
node = False
online = False
tasks = False
scraping = False
downloads = False
tor = False
update = False
websockets = []
activity = {}

View file

@ -6,7 +6,7 @@ from queue import Queue
from threading import Thread
from websocket import trigger_event
import state
import logging
logger = logging.getLogger(__name__)
@ -34,8 +34,6 @@ class Tasks(Thread):
item.scan.run_import(data)
elif action == 'scan':
item.scan.run_scan()
elif action == 'update':
trigger_event('error', {'error': 'not implemented'})
else:
trigger_event('error', {'error': 'unknown action'})
except:

View file

@ -238,7 +238,7 @@ def install_tor():
if get_tor():
print('found existing tor installation')
url = torbrowser_url()
target = os.path.join(settings.base_dir, 'tor')
target = os.path.normpath(os.path.join(settings.base_dir, '..', 'tor'))
if url:
print('downloading and installing tor')
if sys.platform.startswith('linux'):

View file

@ -6,10 +6,12 @@ from contextlib import closing
import json
import os
import tarfile
from threading import Thread
import urllib.request, urllib.error, urllib.parse
import shutil
import subprocess
import sys
import time
import ed25519
import ox
@ -145,7 +147,6 @@ def install():
shutil.copy(os.path.join(settings.updates_path, 'release.json'), os.path.join(settings.config_path, 'release.json'))
for cmd in [
['./ctl', 'stop'],
['./ctl', 'setup'],
['./ctl', 'postupdate', '-o', old_version, '-n', new_version]
]:
subprocess.call(cmd)
@ -153,6 +154,26 @@ def install():
return True
return True
def update_available():
db_version = settings.server.get('db_version', 0)
if db_version < settings.DB_VERSION:
return True
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
return False
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
return False
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
release = json.load(fd)
old_version = current_version('openmedialibrary')
new_version = release['modules']['openmedialibrary']['version']
return verify(release) and old_version < new_version
def restart_oml(update=False):
if update:
get_latest_release()
subprocess.Popen([os.path.join(settings.base_dir, 'ctl'), 'restart'],
close_fds=True, start_new_session=True)
def get_app_version(app):
plist = app + '/Contents/Info.plist'
if os.path.exists(plist):
@ -214,9 +235,50 @@ def restart(data):
'''
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, start_new_session=True)
restart_oml(data.get('update'))
return {}
actions.register(restart, cache=False)
class Update(Thread):
def __init__(self):
Thread.__init__(self)
self.daemon = True
self.start()
def status(self, status, reload=False):
from websocket import trigger_event
trigger_event('updatestatus', {
'reload': reload,
'status': status,
})
def install(self):
while update_available():
self.status('Downloading new version...')
while not download():
self.status('Download failed... (try again in 10 seconds)')
time.sleep(10)
self.status('Downloading new version...')
self.status('Installing new version...')
# install right now calls stop!
'''
if not install():
self.status('Installation failed...')
'''
restart_oml()
def update_database(self):
db_version = settings.server.get('db_version', 0)
if db_version < settings.DB_VERSION:
self.status('Migrating database...')
time.sleep(1)
settings.server['db_version'] = settings.DB_VERSION
def run(self):
self.status('Checking for Updates...')
self.update_database()
self.install()
self.status('Restarting...', True)
restart_oml()