summaryrefslogtreecommitdiff
path: root/manage.py
diff options
context:
space:
mode:
Diffstat (limited to 'manage.py')
-rw-r--r--manage.py112
1 files changed, 90 insertions, 22 deletions
diff --git a/manage.py b/manage.py
index 6df9902..612f78c 100644
--- a/manage.py
+++ b/manage.py
@@ -25,8 +25,8 @@ def read_settings():
return settings
-def build_systemd_files(settings):
- """Generate all Systemd Unit Files with Settings from SETTINGS_PATH"""
+def build_systemd_file(settings):
+ """Generate Systemd Unit File with Settings from SETTINGS_PATH"""
with open(SYSTEMD_TEMPLATE, "r") as template:
template = template.read()
@@ -34,28 +34,28 @@ def build_systemd_files(settings):
template = jinja2.Template(template)
systemd_file = template.render(settings)
+ subprocess.call("mkdir -p systemd/build", shell=True)
file_path = "systemd/build/{}.service".format(settings["project_name"])
with open(file_path, "w") as _file:
_file.write(systemd_file)
-def build_flask_files(settings):
- """Generate all Python Flask Files with Settings from SETTINGS_PATH"""
+def build_flask(settings):
+ """Generate Python Flask File with Settings from SETTINGS_PATH"""
- if settings["web_framework"] == "flask":
- with open(FLASK_TEMPLATE, "r") as template:
- template = template.read()
-
- template = jinja2.Template(template)
- flask_file = template.render(settings)
+ with open(FLASK_TEMPLATE, "r") as template:
+ template = template.read()
- file_path = "flask/build/{}".format(settings["project_name"])
+ template = jinja2.Template(template)
+ flask_file = template.render(settings)
+
+ subprocess.call("mkdir -p flask/build", shell=True)
+
+ file_path = "flask/build/{}".format(settings["project_name"])
- with open(file_path, "w") as _file:
- _file.write(flask_file)
- else:
- print("Flask not enabled in settings.json - skipping file generation for Flask")
+ with open(file_path, "w") as _file:
+ _file.write(flask_file)
def install_webroot(settings):
@@ -65,17 +65,50 @@ def install_webroot(settings):
for _file in files:
path_to_file = os.path.join(directory, _file)
relative_path = os.path.relpath(path_to_file, REPOSITORY_WEBROOT)
- target_path = os.path.join(settings["webroot_installation_path"], relative_path)
+ target_path = os.path.join(settings["webroot"], relative_path)
subprocess.run("install -Dm 644 {} {}".format(path_to_file, target_path), shell=True)
def uninstall_webroot(settings):
"""Uninstalls every File from the Systems Webroot"""
- path_to_delete = os.path.join(settings["webroot_installation_path"], "*")
+ path_to_delete = os.path.join(settings["webroot"], "*")
subprocess.run("rm -rf {}".format(path_to_delete), shell=True)
+def install_flask(settings):
+ """Install the Executable for the Dynamic Web Server"""
+
+ subprocess.call("sudo mkdir -p /opt/{}".format(settings["project_name"]), shell=True)
+ subprocess.call("sudo install -Dm 744 flask/build/{0} /opt/{0}/{0}".format(settings["project_name"]), shell=True)
+ order = "sudo find /opt/{0} -exec chown -R {1}:{2}".format(
+ settings["project_name"],
+ settings["user"],
+ settings["group"]
+ )
+ order += " {} \;"
+ subprocess.call(order, shell=True)
+
+
+def uninstall_flask(settings):
+ """Uninstall the Executable for the Dynamic Web Server"""
+
+ subprocess.call("sudo rm -rf /opt/{}".format(settings["project_name"]), shell=True)
+
+
+def install_systemd_file(settings):
+ """Install the Systemd Unit for launching the dynamic Web Server"""
+
+ subprocess.call("sudo install -Dm 644 systemd/build/{0}.service /etc/systemd/system/{0}.service".format(settings["project_name"]), shell=True)
+ subprocess.call("sudo systemctl daemon-reload", shell=True)
+
+
+def uninstall_systemd_file(settings):
+ """Uninstall the Systemd Unit for launching the dynamic Web Server"""
+
+ subprocess.call("sudo rm /etc/systemd/system/{0}.service".format(settings["project_name"]), shell=True)
+
+
def main():
"""The main Function"""
@@ -88,17 +121,52 @@ def main():
# execute given command
command = sys.argv[1]
- if command == "build_systemd_files":
- build_systemd_files(settings)
- elif command == "build_flask_files":
- build_flask_files(settings)
+ if command == "build_systemd_file":
+ build_systemd_file(settings)
+ elif command == "build_framework":
+ if settings["framework"] == "flask":
+ build_flask(settings)
+ elif settings["framework"] == "actix-web":
+ print("actix-web is not yet implemented ...")
+ sys.exit(1)
+ elif settings["framework"] == None:
+ pass
+ else:
+ print("Unknown web framework selected")
+ sys.exit(1)
elif command == "install_webroot":
install_webroot(settings)
elif command == "uninstall_webroot":
uninstall_webroot(settings)
+ elif command == "install_framework":
+ if settings["framework"] == "flask":
+ install_flask(settings)
+ elif settings["framework"] == "actix-web":
+ print("actix-web is not yet implemented ...")
+ sys.exit(1)
+ elif settings["framework"] == None:
+ pass
+ else:
+ print("Unknown web framework selected")
+ sys.exit(1)
+ elif command == "uninstall_framework":
+ if settings["framework"] == "flask":
+ uninstall_flask(settings)
+ elif settings["framework"] == "actix-web":
+ print("actix-web is not yet implemented ...")
+ sys.exit(1)
+ elif settings["framework"] == None:
+ pass
+ else:
+ print("Unknown web framework selected")
+ sys.exit(1)
+ elif command == "install_systemd_file":
+ install_systemd_file(settings)
+ elif command == "uninstall_systemd_file":
+ uninstall_systemd_file(settings)
else:
print("Unknown command")
- exit(1)
+ sys.exit(1)
if __name__ == "__main__":