|
|
@@ -0,0 +1,65 @@
|
|
|
+
|
|
|
+install_dir = "/opt/eu.tsimnet.git/dasimmet/raspi-zero-waveshare"
|
|
|
+git_remote = "https://git.tsimnet.eu/dasimmet/raspi-zero-waveshare.git"
|
|
|
+
|
|
|
+def submit_form(inp, form):
|
|
|
+ import os
|
|
|
+ import json
|
|
|
+ from bootstrap_captive.helper import runck
|
|
|
+ print(json.dumps(inp, indent=4, sort_keys=True))
|
|
|
+ print(json.dumps(form, indent=4, sort_keys=True))
|
|
|
+ resp = {
|
|
|
+ "ok": True,
|
|
|
+ "out": "",
|
|
|
+ "err": ""
|
|
|
+ }
|
|
|
+ if not inp["subcommand"]:
|
|
|
+ return {
|
|
|
+ "ok": False,
|
|
|
+ "err": "No Subcommand Defined"
|
|
|
+ }
|
|
|
+ subcommand = inp["subcommand"]
|
|
|
+ branch = os.path.basename(inp["branch"])
|
|
|
+ ref = "origin/"+branch
|
|
|
+ cron_timer = inp["cron_timer"]
|
|
|
+ try:
|
|
|
+ proc = None
|
|
|
+ if not os.path.isdir(install_dir):
|
|
|
+ CMD = ["apt-get", "install", "-y", "git"]
|
|
|
+ proc = runck(CMD)
|
|
|
+ os.path.makedirs(install_dir, exist_ok=True)
|
|
|
+ CMD = ["git","init"]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["git","remote","add","origin",git_remote]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["git","branch", branch]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["git","checkout", branch]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ if inp["update"] == True:
|
|
|
+ CMD = ["git","fetch"]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["git","reset","--hard", ref]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["git","submodule","update","--init"]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["cp","config.mk.j2","config.mk"]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ CMD = ["make","deps"]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ if inp["install"] == True:
|
|
|
+ CMD = ["make","install", "CRON_T="+cron_timer, "DEPLOY_DIR="+install_dir, "CRON_SUBCOMMAND="+ subcommand]
|
|
|
+ else:
|
|
|
+ CMD = ["./bin/simpi.py", subcommand]
|
|
|
+ proc = runck(CMD, cwd=install_dir)
|
|
|
+ except Exception as ex:
|
|
|
+ resp["ok"] = False
|
|
|
+ resp["err"] = str(ex)
|
|
|
+
|
|
|
+ resp["out"] = str(CMD) + " "
|
|
|
+ if proc:
|
|
|
+ resp["ok"] = proc.returncode == 0
|
|
|
+ resp["out"] = resp["out"] + proc.stdout.decode()
|
|
|
+ resp["err"] = proc.stderr.decode()
|
|
|
+
|
|
|
+ return resp
|