From d5cec3491b8b667f039826fac6d30f22fc12f8a1 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Tue, 26 Feb 2019 21:33:56 +0100 Subject: [PATCH] Add unpack installation stage and use enum for stages --- usr/lib/python3.6/vmmgr/pkgmgr.py | 17 +++++++++++------ usr/lib/python3.6/vmmgr/wsgiapp.py | 9 ++++++--- usr/lib/python3.6/vmmgr/wsgilang.py | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/usr/lib/python3.6/vmmgr/pkgmgr.py b/usr/lib/python3.6/vmmgr/pkgmgr.py index fa1c57f..b0fd1ad 100644 --- a/usr/lib/python3.6/vmmgr/pkgmgr.py +++ b/usr/lib/python3.6/vmmgr/pkgmgr.py @@ -6,18 +6,21 @@ import requests import shutil import subprocess +from enum import Enum from werkzeug.exceptions import BadRequest, NotFound, Unauthorized from . import crypto from .paths import LXC_ROOT -STAGE_DOWNLOAD = 0 -STAGE_INSTALL_DEPS = 1 -STAGE_INSTALL_APP = 2 +class Stage(Enum): + DOWNLOAD = 1 + UNPACK = 2 + INSTALL_DEPS = 3 + INSTALL_APP = 4 class Pkg: def __init__(self): - self.stage = STAGE_DOWNLOAD + self.stage = Stage.DOWNLOAD self.bytes_total = 1 self.bytes_downloaded = 0 @@ -58,11 +61,13 @@ class PkgMgr: for dep in deps: self.download_package(dep, item) for dep in deps: - # Set stage to INSTALLING_DEPS or INSTALLING based on which package in sequence is being installed - item.stage = STAGE_INSTALL_APP if dep == deps[-1] else STAGE_INSTALL_DEPS # Purge old data before unpacking to clean previous failed installation + item.stage = Stage.UNPACK self.purge_package(dep) self.unpack_package(dep) + for dep in deps: + # Set stage to INSTALLING_DEPS or INSTALLING based on which package in sequence is being installed + item.stage = Stage.INSTALL_APP if dep == deps[-1] else Stage.INSTALL_DEPS # Run uninstall script before installation to clean previous failed installation self.run_uninstall_script(dep) self.run_install_script(dep) diff --git a/usr/lib/python3.6/vmmgr/wsgiapp.py b/usr/lib/python3.6/vmmgr/wsgiapp.py index 4b6dc0a..d03c6b8 100644 --- a/usr/lib/python3.6/vmmgr/wsgiapp.py +++ b/usr/lib/python3.6/vmmgr/wsgiapp.py @@ -17,6 +17,7 @@ from . import validator from .actionqueue import ActionQueue from .appmgr import AppMgr from .config import Config +from .pkgmgr import Stage from .vmmgr import VMMgr from .wsgilang import WSGILang from .wsgisession import WSGISession @@ -182,7 +183,7 @@ class WSGIApp: actionable_apps = sorted(set([k for k, v in online_packages.items() if 'title' in v] + list(self.conf['apps'].keys()))) app_data = {} for app in actionable_apps: - installed = app in self.conf['packages'] + installed = app in self.conf['packages'] and app in self.conf['apps'] title = self.conf['packages'][app]['title'] if installed else online_packages[app]['title'] visible = self.conf['apps'][app]['visible'] if installed else False autostarted = self.appmgr.is_service_autostarted(app) if installed else False @@ -218,9 +219,11 @@ class WSGIApp: status = '{} OK'.format(lang.package_manager_error()) actions = None else: - if item.data.stage == 0: + if item.data.stage == Stage.DOWNLOAD: status = '{} ({} %)'.format(lang.status_downloading(), item.data.percent_downloaded) - elif item.data.stage == 1: + elif item.data.stage == Stage.UNPACK: + status = lang.status_unpacking() + elif item.data.stage == Stage.INSTALL_DEPS: status = lang.status_installing_deps() else: status = lang.status_installing() diff --git a/usr/lib/python3.6/vmmgr/wsgilang.py b/usr/lib/python3.6/vmmgr/wsgilang.py index 16310a3..3dbadbe 100644 --- a/usr/lib/python3.6/vmmgr/wsgilang.py +++ b/usr/lib/python3.6/vmmgr/wsgilang.py @@ -40,6 +40,7 @@ class WSGILang: 'status_stopping': 'Zastavuje se', 'status_stopped': 'Zastavena', 'status_downloading': 'Stahuje se', + 'status_unpacking': 'Rozbaluje se', 'status_installing': 'Instaluje se', 'status_installing_deps': 'Instalují se závislosti', 'status_uninstalling': 'Odinstalovává se',