aboutsummaryrefslogtreecommitdiffstats
path: root/deploy.py
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2022-11-20 20:33:13 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2022-11-20 20:33:13 +0000
commit6b1b61f98813a58286e099d92767e01c2d40bc18 (patch)
treea3613fba312e0f324bdbca28ec3d3d0b5e6f6e13 /deploy.py
parent6a0e18aab79cefa8cd4917e9a6d121349f41eb3f (diff)
Redo deploy script
Diffstat (limited to 'deploy.py')
-rwxr-xr-xdeploy.py83
1 files changed, 49 insertions, 34 deletions
diff --git a/deploy.py b/deploy.py
index 466587c..5da1b49 100755
--- a/deploy.py
+++ b/deploy.py
@@ -1,45 +1,60 @@
#!/usr/bin/python3
-from os import listdir
-from os.path import isfile, join, abspath
-from shutil import copy2
-from pathlib import Path
+import os
-home = str(Path.home())
-contents = dict()
-directory = dict()
+from util.runners import run_step
+from util.exceptions import StepFailedError
+from util.helpers import check_preconditions
-with open('directoryinfo') as f:
- lines = f.readlines()
- for line in lines:
- line = line.replace('%HOME', home)
+import yaml
+from termcolor import colored
- if (line.isspace()):
+CWD = os.getcwd()
+
+
+def get_sections_meeting_preconditions(yaml):
+ sections = {}
+ for key, section in yaml["sections"].items():
+ if not check_preconditions(section):
continue
- if (line.startswith('#')):
+ sections[key] = section
+
+ return sections
+
+
+def run_section(title, section):
+ os.chdir(CWD)
+ if "directory" in section:
+ os.chdir(section["directory"])
+ elif os.path.exists(title):
+ os.chdir(title)
+
+ for step in section["steps"]:
+ if not check_preconditions(step):
continue
- parts = line.split()
- if parts[0] == 'copycontent':
- contents[parts[1]] = parts[2]
- elif parts[0] == 'copyfulldir':
- directory[parts[1]] = parts[2]
- else:
- print(f'directoryinfo: unknown directive \'{parts[0]}\'')
+ run_step(step)
+
+
+with open("info.yml", "r") as f:
+ yaml = yaml.safe_load(f)
-# Directive: copycontent
-for d, t in contents.items():
- files = [f for f in listdir(d) if isfile(join(d, f))]
- for file in files:
- print(f'Copying {abspath(join(d, file))} to {abspath(join(t, file))}')
- copy2(abspath(join(d, file)), join(t, file))
+sections = get_sections_meeting_preconditions(yaml)
-# Directive: copyfulldir
-for d, t in directory.items():
- files = [f for f in listdir(d) if isfile(join(d, f))]
- print(f'Creating {t}')
- Path(t).mkdir(parents=True, exist_ok=True)
- for file in files:
- print(f'Copying {abspath(join(d, file))} to {join(t, file)}')
- copy2(abspath(join(d, file)), join(t, file))
+print("Sections to run: " + ", ".join(
+ map(lambda x: colored(x, "green"), sections.keys())
+))
+print()
+section_count = 0
+total = len(sections.keys())
+for key, section in sections.items():
+ section_count += 1
+ print(colored(f"[{section_count}/{total}] ", "white", attrs=["bold"])
+ + "Section "
+ + colored(key, "green"))
+ try:
+ run_section(key, section)
+ except StepFailedError as e:
+ print(colored("Step failed: ", "red") + str(e))
+ print()