Add update check and action stub

This commit is contained in:
Disassembler 2019-06-04 15:23:43 +02:00
parent ebd24befaf
commit 14876bc139
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
5 changed files with 37 additions and 5 deletions

View File

@ -65,6 +65,12 @@ class AppMgr:
self.update_app_autostart(app, False) self.update_app_autostart(app, False)
self.pkgmgr.uninstall_app(app) self.pkgmgr.uninstall_app(app)
def update_app(self, item):
# Main update function. Wrapper for download and update script
self.stop_app(item)
item.data = Pkg()
self.pkgmgr.update_app(item.key, item.data)
def get_services_deps(self): def get_services_deps(self):
# Fisrt, build a dictionary of {app: [needs]} # Fisrt, build a dictionary of {app: [needs]}
needs = {} needs = {}

View File

@ -7,6 +7,7 @@ import shutil
import subprocess import subprocess
from enum import Enum from enum import Enum
from packaging.version import Version
from werkzeug.exceptions import BadRequest, NotFound, Unauthorized from werkzeug.exceptions import BadRequest, NotFound, Unauthorized
from . import crypto from . import crypto
@ -82,6 +83,12 @@ class PkgMgr:
self.purge_package(dep) self.purge_package(dep)
self.unregister_package(dep) self.unregister_package(dep)
def update_app(self, app, item):
# Main update function.
# TODO: Implement actual update
uninstall_app(app)
install_app(app, item)
def download_package(self, name, item): def download_package(self, name, item):
# Download tar.xz package and verify its hash. Can raise InvalidSignature # Download tar.xz package and verify its hash. Can raise InvalidSignature
pkg_archive = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release']) pkg_archive = '{}_{}-{}.tar.xz'.format(name, self.online_packages[name]['version'], self.online_packages[name]['release'])
@ -164,3 +171,8 @@ class PkgMgr:
for d in self.conf['packages'][name]['depends']: for d in self.conf['packages'][name]['depends']:
deps.setdefault(d, []).append(name) deps.setdefault(d, []).append(name)
return deps return deps
def has_update(self, app):
if not self.online_packages:
return False
return Version(self.conf['packages'][app]['version']) < Version(self.online_packages[app]['version'])

View File

@ -62,6 +62,7 @@ class WSGIApp:
Rule('/get-app-status', endpoint='get_app_status_action'), Rule('/get-app-status', endpoint='get_app_status_action'),
Rule('/clear-app-status', endpoint='clear_app_status_action'), Rule('/clear-app-status', endpoint='clear_app_status_action'),
Rule('/uninstall-app', endpoint='uninstall_app_action'), Rule('/uninstall-app', endpoint='uninstall_app_action'),
Rule('/update-app', endpoint='update_app_action'),
Rule('/update-password', endpoint='update_password_action'), Rule('/update-password', endpoint='update_password_action'),
Rule('/shutdown-vm', endpoint='shutdown_vm_action'), Rule('/shutdown-vm', endpoint='shutdown_vm_action'),
Rule('/reboot-vm', endpoint='reboot_vm_action'), Rule('/reboot-vm', endpoint='reboot_vm_action'),
@ -247,12 +248,15 @@ class WSGIApp:
if not installed: if not installed:
status = lang.status_not_installed() status = lang.status_not_installed()
actions = '<a href="#" class="app-install">{}</a>'.format(lang.action_install()) actions = '<a href="#" class="app-install">{}</a>'.format(lang.action_install())
elif self.appmgr.is_service_started(app): else:
if self.appmgr.is_service_started(app):
status = '<span class="info">{}</span>'.format(lang.status_started()) status = '<span class="info">{}</span>'.format(lang.status_started())
actions = '<a href="#" class="app-stop">{}</a>'.format(lang.action_stop()) actions = '<a href="#" class="app-stop">{}</a>'.format(lang.action_stop())
else: else:
status = '<span class="error">{}</span>'.format(lang.status_stopped()) status = '<span class="error">{}</span>'.format(lang.status_stopped())
actions = '<a href="#" class="app-start">{}</a>, <a href="#" class="app-uninstall">{}</a>'.format(lang.action_start(), lang.action_uninstall()) actions = '<a href="#" class="app-start">{}</a>, <a href="#" class="app-uninstall">{}</a>'.format(lang.action_start(), lang.action_uninstall())
if self.appmgr.pkgmgr.has_update(app):
actions = '{}, <a href="#" class="app-update">{}</a>'.format(actions, lang.action_update())
app_data[app] = {'title': title, 'visible': visible, 'installed': installed, 'autostarted': autostarted, 'status': status, 'actions': actions} app_data[app] = {'title': title, 'visible': visible, 'installed': installed, 'autostarted': autostarted, 'status': status, 'actions': actions}
return self.render_template('setup-apps-table.html', request, app_data=app_data) return self.render_template('setup-apps-table.html', request, app_data=app_data)
@ -385,6 +389,10 @@ class WSGIApp:
# Queues application uninstallation # Queues application uninstallation
return self.enqueue_app_action(request, self.appmgr.uninstall_app) return self.enqueue_app_action(request, self.appmgr.uninstall_app)
def update_app_action(self, request):
# Queues application update
return self.enqueue_app_action(request, self.appmgr.update_app)
def get_app_status_action(self, request): def get_app_status_action(self, request):
# Gets application and queue status # Gets application and queue status
return self.render_json({'ok': self.render_setup_apps_table(request)}) return self.render_json({'ok': self.render_setup_apps_table(request)})

View File

@ -50,6 +50,7 @@ class WSGILang:
'action_stop': 'Zastavit', 'action_stop': 'Zastavit',
'action_install': 'Instalovat', 'action_install': 'Instalovat',
'action_uninstall': 'Odinstalovat', 'action_uninstall': 'Odinstalovat',
'action_update': 'Aktualizovat',
'ssh_keys_installed': 'SSH klíče byly úspěšně změněny.', 'ssh_keys_installed': 'SSH klíče byly úspěšně změněny.',
'vpn_updated': 'Nastavení VPN bylo úspěšně změněno.', 'vpn_updated': 'Nastavení VPN bylo úspěšně změněno.',
} }

View File

@ -15,6 +15,7 @@ $(function() {
.on('click', '.app-stop', stop_app) .on('click', '.app-stop', stop_app)
.on('click', '.app-install', install_app) .on('click', '.app-install', install_app)
.on('click', '.app-uninstall', uninstall_app) .on('click', '.app-uninstall', uninstall_app)
.on('click', '.app-update', update_app)
.on('click', '.app-clear-status', clear_app_status); .on('click', '.app-clear-status', clear_app_status);
$('#update-password').on('submit', update_password); $('#update-password').on('submit', update_password);
$('#reboot-vm').on('click', reboot_vm); $('#reboot-vm').on('click', reboot_vm);
@ -165,6 +166,10 @@ function uninstall_app(ev) {
return false; return false;
} }
function update_app(ev) {
return _do_app('/update-app', ev);
}
function clear_app_status(ev) { function clear_app_status(ev) {
return _do_app('/clear-app-status', ev); return _do_app('/clear-app-status', ev);
} }