Implement app uninstall

This commit is contained in:
Disassembler 2020-03-12 21:54:18 +01:00
parent ac4b7f9995
commit d1e5b83186
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499

View File

@ -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: