Fix ready command

This commit is contained in:
Disassembler 2019-09-24 10:52:33 +02:00
parent d14fba7ec1
commit 171aa76043
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
4 changed files with 22 additions and 12 deletions

View File

@ -84,13 +84,11 @@ def list_updates():
else:
print('No applications packages installed.')
def install_app(app):
pm = PkgMgr()
app = App(app)
def run_install_action(action, app):
with ThreadPoolExecutor() as executor:
future = executor.submit(pm.install_app, app)
future = executor.submit(action, app)
while not future.done():
time.sleep(1)
time.sleep(0.25)
print_install_status(app)
# Get the result of the future and let it raise exception, if there was any
data = future.result()
@ -108,16 +106,23 @@ def print_install_status(app):
print('\x1b[KInstalling...', end='\r')
elif app.stage == Stage.UNINSTALL:
print('\x1b[KUninstalling...', end='\r')
elif app.stage == Stage.UPDATE:
print('\x1b[KUpdating...', end='\r')
elif app.stage == Stage.DONE:
print('\x1b[KDone.')
def install_app(app):
pm = PkgMgr()
app = App(app)
run_install_action(pm.install_app, app)
def update_app(app):
pm = PkgMgr()
pm.update_app(app)
run_install_action(pm.update_app, app)
def uninstall_app(app):
pm = PkgMgr()
pm.uninstall_app(app)
run_install_action(pm.uninstall_app, app)
args = parser.parse_args()
if not hasattr(args, 'action'):

View File

@ -21,7 +21,8 @@ class Stage(Enum):
UNPACK = 3
INSTALL = 4
UNINSTALL = 5
DONE = 6
UPDATE = 6
DONE = 7
class RepoUnauthorized(Exception):
pass
@ -215,7 +216,7 @@ class PkgMgr:
image = self.online_packages['images'][image].copy()
if 'mounts' in self.online_packages['apps'][app]['containers'][container]:
image['mounts'] = self.online_packages['apps'][app]['containers'][container]['mounts']
if 'depends' in self.online_packages['apps'][app]['containers'][container]
if 'depends' in self.online_packages['apps'][app]['containers'][container]:
image['depends'] = self.online_packages['apps'][app]['containers'][container]['depends']
lxcmgr.create_container(container, image)
svcmgr.create_service(app, container, image)
@ -224,12 +225,15 @@ class PkgMgr:
def uninstall_app(self, app):
# Main uninstallation function. Wrapper for uninstall script and filesystem purge
if app not in self.installed_packages['apps']:
app.stage = Stage.DONE
return
app.stage = Stage.UNINSTALL
self.run_uninstall_script(app)
self.destroy_containers(app)
self.purge_scripts(app)
self.unregister_app(app)
self.purge_unused_layers()
app.stage = Stage.DONE
def destroy_containers(self, app):
# Destroy LXC containers
@ -255,6 +259,7 @@ class PkgMgr:
# TODO: Implement actual update
uninstall_app(app)
install_app(app, item)
app.stage = Stage.DONE
def has_update(self, app):
# Check if online repository list a newer version of app

View File

@ -8,9 +8,9 @@ from .templates import SERVICE
def create_service(app, container, image):
depends = ' '.join(image['depends']) if 'depends' in image else ''
check = 'lxc-execute {} -- sh -c \'until $({}); do sleep 0.1; done\''.format(container, image['check']) if 'check' in image else ''
ready = 'lxc-attach {} -- sh -c \'until $({}); do sleep 0.1; done\''.format(container, image['ready']) if 'ready' in image else ''
with open(os.path.join(SERVICE_DIR, container), 'w') as f:
f.write(SERVICE.format(app=app, container=container, depends=depends, check=check))
f.write(SERVICE.format(app=app, container=container, depends=depends, ready=ready))
update_services()
def delete_service(service):

View File

@ -63,7 +63,7 @@ start() {{
}}
start_post() {{
{check}
{ready}
}}
stop() {{