diff --git a/usr/bin/spoc-app b/usr/bin/spoc-app index 1642a94..338e52a 100755 --- a/usr/bin/spoc-app +++ b/usr/bin/spoc-app @@ -15,6 +15,7 @@ from spoc.flock import locked from spoc.image import Image def listing(list_type): + # Lists applications in particular state if list_type == 'installed': apps = repo_local.get_apps() elif list_type == 'online': @@ -29,6 +30,7 @@ def listing(list_type): @locked(LOCK_FILE, print_lock) def install(app_name): + # Install application from online repository queue = ActionQueue() required_images = [] for container in repo_online.get_app(app_name)['containers'].values(): @@ -37,24 +39,40 @@ 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, False)) + queue.install_app(App(app_name, False, False)) queue.process() @locked(LOCK_FILE, print_lock) def update(app_name): - App(app_name, False).update() + # Update application from online repository + queue = ActionQueue() + required_images = [] + for container in repo_online.get_app(app_name)['containers'].values(): + required_images.extend(repo_online.get_image(container['image'])['layers']) + local_images = repo_local.get_images() + for layer in set(required_images): + if layer not in local_images: + queue.download_image(Image(layer, False)) + queue.update_app(App(app_name, False)) + queue.process() @locked(LOCK_FILE, print_lock) def uninstall(app_name): - App(app_name, False).uninstall() + # Remove application and its containers from local repository + queue = ActionQueue() + queue.uninstall_app(App(app_name, False)) + queue.process() def start(app_name): + # Start all application containers App(app_name).start() def stop(app_name): + # Stop all application containers App(app_name).stop() def status(app_name): + # Print status of all application containers for container,status in App(app_name).status(): print(f'{container}: {status}') @@ -71,18 +89,22 @@ def publish(filename, force): print(f'Application {app_name} already published, skipping publish task') def unpublish(app_name): + # Remove the application from publish repo App(app_name, False, False).unpublish() def autostart(app_name, value): + # Set if the application should be autostarted on boot value = value.lower() in ('1', 'on', 'enable', 'true') App(app_name, False).set_autostart(value) def start_autostarted(): + # Start all applications (resp. their containers) which are set to be autoostarted on boot apps = [App(a) for a,d in repo_local.get_apps() if d['autostart']] for app in apps: app.start() def stop_all(): + # Stop all applications (resp. their containers) apps = [App(a) for a,d in repo_local.get_apps()] for app in apps: app.stop() diff --git a/usr/bin/spoc-container b/usr/bin/spoc-container index affc1f2..e759179 100755 --- a/usr/bin/spoc-container +++ b/usr/bin/spoc-container @@ -12,6 +12,7 @@ from spoc.container import Container, State from spoc.image import Image def listing(state): + # Lits containers in particular state if state == 'all': containers = repo_local.get_containers().keys() elif state == 'running': @@ -22,6 +23,7 @@ def listing(state): print(container) def modify_depend(container, depend): + # Change container dependencies if depend.startswith('!'): try: container.depends.remove(depend[1:]) @@ -33,6 +35,7 @@ def modify_depend(container, depend): container.depends = list(set(container.depends)) def modify_mount(container, mount): + # Change container mount points volume,mountpoint = mount.split(':', 1) if mountpoint: container.mounts[volume] = mountpoint @@ -43,6 +46,7 @@ def modify_mount(container, mount): pass def modify_env(container, env): + # Change container environment values key,value = env.split('=', 1) if value: container.env[key] = value @@ -53,6 +57,7 @@ def modify_env(container, env): pass def modify_container(container, depends, mounts, envs, uid, gid, cmd, cwd, ready, halt): + # Change container definition for depend in depends: modify_depend(container, depend) for mount in mounts: @@ -66,7 +71,7 @@ def modify_container(container, depends, mounts, envs, uid, gid, cmd, cwd, ready setattr(container, member, value) def create(container_name, image_name, depends, mounts, env, uid, gid, cmd, cwd, ready, halt): - # Create container based on image definition and extrea fields + # Create container based on image definition and extra fields container = Container(container_name, False) container.set_definition(Image(image_name).get_definition()) modify_container(container, depends, mounts, env, uid, gid, cmd, cwd, ready, halt) diff --git a/usr/bin/spoc-image b/usr/bin/spoc-image index 2420b55..2a0f30d 100755 --- a/usr/bin/spoc-image +++ b/usr/bin/spoc-image @@ -25,6 +25,7 @@ def get_image_name(file_path): return None def listing(list_type): + # Lists images in particular state if list_type == 'installed': images = repo_local.get_images() elif list_type == 'online': @@ -36,6 +37,7 @@ def listing(list_type): @locked(LOCK_FILE, print_lock) def download(image_name): + # Download and unpack image from online repository queue = ActionQueue() local_images = repo_local.get_images() for layer in repo_online.get_image(image_name)['layers']: @@ -111,6 +113,7 @@ def publish(image_name, force): print(f'Image {image_name} already published, skipping publish task') def unpublish(image_name): + # Remove the image from publish repo Image(image_name, False).unpublish() parser = argparse.ArgumentParser(description='SPOC image manager') diff --git a/usr/lib/python3.8/spoc/cli.py b/usr/lib/python3.8/spoc/cli.py index 720bc44..0400f8c 100644 --- a/usr/lib/python3.8/spoc/cli.py +++ b/usr/lib/python3.8/spoc/cli.py @@ -18,11 +18,19 @@ class ActionQueue: def delete_image(self, image): self.queue.append(ActionItem(f'Deleting image {image.name}', image.delete, False)) - def download_app(self, app): + def install_app(self, app): self.queue.append(ActionItem(f'Downloading application {app.name}', app.download)) self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded)) self.queue.append(ActionItem(f'Installing application {app.name}', app.install, False)) + def update_app(self, app): + self.queue.append(ActionItem(f'Downloading application {app.name}', app.download)) + self.queue.append(ActionItem(f'Unpacking application {app.name}', app.unpack_downloaded)) + self.queue.append(ActionItem(f'Updating application {app.name}', app.update, False)) + + def uninstall_app(self, app): + self.queue.append(ActionItem(f'Uninstalling application {app.name}', app.uninstall, False)) + def process(self): index = 0 queue_length = len(self.queue)