-
Notifications
You must be signed in to change notification settings - Fork 0
/
uhbuild
executable file
·76 lines (56 loc) · 1.81 KB
/
uhbuild
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import sys, argparse
parser = argparse.ArgumentParser(prog="Universal Home Builder")
parser.add_argument("config", type=str, help="Path to the entry config file")
parser.add_argument(
"--log-level",
type=str,
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
default="INFO",
help="Set the logging level",
)
parser.add_argument(
"--show-exceptions",
action="store_true",
default=False,
help="Show exceptions in the output for debugging purposes",
)
args = parser.parse_args()
import logging
from src.LoggingFormatter import Formatter
logger = logging.getLogger("Universal Home Builder")
logger.setLevel(args.log_level)
handler = logging.StreamHandler()
handler.setLevel(args.log_level)
handler.setFormatter(Formatter())
logger.addHandler(handler)
import os
def run_through_symlink() -> bool:
return os.path.islink(os.path.abspath(__file__))
from src.Script import Script
from src.ConfigEntity import ConfigEntity
def add_self_to_user_scripts(config: ConfigEntity) -> ConfigEntity:
uhb_build_script = Script(
"uhbuild",
{"src": os.path.basename(__file__), "user": True, "build": False},
os.path.abspath(__file__),
)
config.add_script(uhb_build_script)
return config
from src.ConfigFile import ConfigFile
from src.HomeBuilder import HomeBuilder
try:
config = ConfigEntity(ConfigFile(args.config))
if not run_through_symlink():
logger.info(
"UHB is not run as user script and will add itself to user scripts."
)
config = add_self_to_user_scripts(config)
home_builder = HomeBuilder(config)
home_builder.build()
logger.info("Build successful!")
except Exception as e:
logger.error(f"Build failed: {e}")
if args.show_exceptions:
raise e
sys.exit(1)