From cdb976808652217eb03070f7d4fe82dbd8f308f4 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 26 Mar 2020 19:47:15 +0100 Subject: [PATCH] Allow App definition without full container definition --- usr/bin/spoc-app | 4 ++-- usr/lib/python3.8/spoc/app.py | 19 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/usr/bin/spoc-app b/usr/bin/spoc-app index 27051dc..6e32556 100755 --- a/usr/bin/spoc-app +++ b/usr/bin/spoc-app @@ -37,7 +37,7 @@ def install(app_name): for layer in set(required_images): if layer not in local_images: queue.download_image(Image(layer, False)) - queue.download_app(App(app_name, False)) + queue.download_app(App(app_name, False, False)) queue.process() @locked(LOCK_FILE, print_lock) @@ -71,7 +71,7 @@ def publish(filename, force): print(f'Application {app_name} already published, skipping publish task') def unpublish(app_name): - App(app_name, False).unpublish() + App(app_name, False, False).unpublish() def autostart(value): value = value.lower() in ('1', 'on', 'enable', 'true') diff --git a/usr/lib/python3.8/spoc/app.py b/usr/lib/python3.8/spoc/app.py index 3c8cbfa..dbf5cf7 100644 --- a/usr/lib/python3.8/spoc/app.py +++ b/usr/lib/python3.8/spoc/app.py @@ -15,7 +15,7 @@ from .container import Container from .image import Image class App: - def __init__(self, name, load_from_repo=True): + def __init__(self, name, define_containers=True, load_from_repo=True): self.name = name self.version = None self.app_dir = os.path.join(APPS_DIR, name) @@ -23,13 +23,13 @@ class App: self.autostart = False self.containers = [] if load_from_repo: - self.set_definition(repo_local.get_app(name)) + self.set_definition(repo_local.get_app(name), define_containers) - def set_definition(self, definition): + def set_definition(self, definition, define_containers): self.version = definition['version'] self.meta = definition['meta'] self.autostart = definition['autostart'] - self.containers = [Container(container) for container in definition['containers']] + self.containers = [Container(container, define_containers) for container in definition['containers']] def get_definition(self): return { @@ -91,9 +91,7 @@ class App: def update(self): # Remove containers - # Load the local repo data here instead set_definition() to avoid fully defining containers which may not exist already - containers = [Container(container, False) for container in repo_local.get_app(self.name)['containers']] - for container in containers: + for container in self.containers: container.destroy() # Load online definition definition = repo_online.get_app(self.name) @@ -108,14 +106,12 @@ class App: def uninstall(self): # Make sure the containers are stopped - # Load the local repo data here instead set_definition() to avoid fully defining containers which may not exist already - containers = [Container(container, False) for container in repo_local.get_app(self.name)['containers']] - for container in containers: + for container in self.containers: container.stop() # Run uninstall script self.run_script('uninstall') # Remove containers - for container in containers: + for container in self.containers: container.destroy() # Unregister app and remove scripts repo_local.unregister_app(self.name) @@ -123,7 +119,6 @@ class App: shutil.rmtree(self.app_dir) except FileNotFoundError: pass - # TODO: Remove unused images def start(self): for container in self.containers: