aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/__pycache__/exceptions.cpython-310.pycbin0 -> 308 bytes
-rw-r--r--util/__pycache__/exceptions.cpython-39.pycbin0 -> 304 bytes
-rw-r--r--util/__pycache__/helpers.cpython-39.pycbin0 -> 369 bytes
-rw-r--r--util/__pycache__/runners.cpython-310.pycbin0 -> 402 bytes
-rw-r--r--util/__pycache__/runners.cpython-39.pycbin0 -> 1002 bytes
-rw-r--r--util/exceptions.py2
-rw-r--r--util/helpers.py13
-rw-r--r--util/runners.py29
8 files changed, 44 insertions, 0 deletions
diff --git a/util/__pycache__/exceptions.cpython-310.pyc b/util/__pycache__/exceptions.cpython-310.pyc
new file mode 100644
index 0000000..f00abf6
--- /dev/null
+++ b/util/__pycache__/exceptions.cpython-310.pyc
Binary files differ
diff --git a/util/__pycache__/exceptions.cpython-39.pyc b/util/__pycache__/exceptions.cpython-39.pyc
new file mode 100644
index 0000000..3e6ee44
--- /dev/null
+++ b/util/__pycache__/exceptions.cpython-39.pyc
Binary files differ
diff --git a/util/__pycache__/helpers.cpython-39.pyc b/util/__pycache__/helpers.cpython-39.pyc
new file mode 100644
index 0000000..2522a13
--- /dev/null
+++ b/util/__pycache__/helpers.cpython-39.pyc
Binary files differ
diff --git a/util/__pycache__/runners.cpython-310.pyc b/util/__pycache__/runners.cpython-310.pyc
new file mode 100644
index 0000000..81b112d
--- /dev/null
+++ b/util/__pycache__/runners.cpython-310.pyc
Binary files differ
diff --git a/util/__pycache__/runners.cpython-39.pyc b/util/__pycache__/runners.cpython-39.pyc
new file mode 100644
index 0000000..6e66aae
--- /dev/null
+++ b/util/__pycache__/runners.cpython-39.pyc
Binary files differ
diff --git a/util/exceptions.py b/util/exceptions.py
new file mode 100644
index 0000000..b14896d
--- /dev/null
+++ b/util/exceptions.py
@@ -0,0 +1,2 @@
+class StepFailedError(Exception):
+ pass
diff --git a/util/helpers.py b/util/helpers.py
new file mode 100644
index 0000000..5f970df
--- /dev/null
+++ b/util/helpers.py
@@ -0,0 +1,13 @@
+import os
+
+OS_TYPE = os.getenv("OS_TYPE")
+
+
+# Returns True if all preconditions pass
+def check_preconditions(obj):
+ if "preconditions" in obj:
+ if ("os" in obj["preconditions"]
+ and obj["preconditions"]["os"] != OS_TYPE):
+ return False
+
+ return True
diff --git a/util/runners.py b/util/runners.py
new file mode 100644
index 0000000..9252d86
--- /dev/null
+++ b/util/runners.py
@@ -0,0 +1,29 @@
+import os
+import re
+from util.exceptions import StepFailedError
+
+HOME = os.getenv("HOME")
+
+
+def run_step(step):
+ step_type = step["=="]
+
+ if step_type == "run":
+ do_run(step["command"])
+ elif step_type == "link":
+ do_link(step["from"], step["to"])
+
+
+def do_run(command):
+ print(f"! {command}")
+ if not os.system(command) == 0:
+ raise StepFailedError("Non-zero return code")
+
+
+def do_link(source, destination):
+ destination = re.sub(r"^~/", HOME + "/", destination)
+ print(f"Linking {source} -> {destination}")
+ try:
+ os.link(source, destination)
+ except Exception as e:
+ raise StepFailedError("Link raised exeption: " + str(e)) from e