aboutsummaryrefslogtreecommitdiffstats
path: root/deploy.py
blob: 5da1b497323ec551d13461405dfa90fad87a0e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
import os

from util.runners import run_step
from util.exceptions import StepFailedError
from util.helpers import check_preconditions

import yaml
from termcolor import colored

CWD = os.getcwd()


def get_sections_meeting_preconditions(yaml):
    sections = {}
    for key, section in yaml["sections"].items():
        if not check_preconditions(section):
            continue

        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

        run_step(step)


with open("info.yml", "r") as f:
    yaml = yaml.safe_load(f)

sections = get_sections_meeting_preconditions(yaml)

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()