diff --git a/usr/lib/python3.8/spoc/app.py b/usr/lib/python3.8/spoc/app.py index 3ed1181..880506c 100644 --- a/usr/lib/python3.8/spoc/app.py +++ b/usr/lib/python3.8/spoc/app.py @@ -2,6 +2,7 @@ import json import os +import shutil import subprocess import tarfile import urllib.parse @@ -17,6 +18,7 @@ class App: def __init__(self, name, load_from_repo=True): self.name = name self.version = None + self.app_dir = os.path.join(APPS_DIR, name) self.meta = {} self.containers = [] if load_from_repo: @@ -50,15 +52,14 @@ class App: def run_script(self, action): # Runs script for an app, if the script is present - app_dir = os.path.join(APPS_DIR, self.name) - script_dir = os.path.join(app_dir, action) - script_path = os.path.join(app_dir, f'{script_dir}.sh') + script_dir = os.path.join(self.app_dir, action) + script_path = os.path.join(self.app_dir, f'{script_dir}.sh') if os.path.exists(script_path): # Run the script in its working directory, if there is one, so it doesn't have to figure out paths to packaged files env = os.environ.copy() env['LAYERS_DIR'] = LAYERS_DIR env['VOLUMES_DIR'] = VOLUMES_DIR - cwd = script_dir if os.path.exists(script_dir) else app_dir + cwd = script_dir if os.path.exists(script_dir) else self.app_dir subprocess.run(script_path, cwd=cwd, env=env, check=True) def create_container(self, name, definition): @@ -89,7 +90,18 @@ class App: raise NotImplementedError() def uninstall(self): - raise NotImplementedError() + definition = repo_local.get_app(self.name) + self.run_script('uninstall') + # Remove containers + for container in definition['containers']: + Container(container, False).destroy() + # Unregister app and remove scripts + repo_local.unregister_app(self.name) + try: + shutil.rmtree(self.app_dir) + except FileNotFoundError: + pass + # TODO: Remove unused images def start(self): for container in self.containers: