-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (37 loc) · 1.12 KB
/
main.py
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
#!/usr/bin/env python
import code_generator.codegen as cg
import fmg_operations.fmgops as fo
from yaml import full_load
import logging.config
from logging_config import logging_schema
from os import makedirs
# create directories
makedirs("_logs/", exist_ok=True)
makedirs("_backups/", exist_ok=True)
# setup logging
logging.config.dictConfig(logging_schema)
log_msg = logging.getLogger("priLogger")
config_file = "config.yaml"
class YAMLException(Exception):
pass
def yaml_values(config_file) -> dict:
"""
Open YAML and assign var cfg to file
:param config_file: path of yaml file
:return dict
"""
try:
with open(config_file, mode="rt") as yfile:
return full_load(yfile)
except IOError:
log_msg.error(f"Config file: {config_file} is missing. Exiting..")
exit(1)
def main():
cfg = yaml_values(config_file)
if not cfg:
raise YAMLException(f"Unable to parse {config_file}")
log_msg.debug(f"Successfully processed {config_file}")
rendered_cmds = cg.gen_template(cfg)
fo.process(rendered_cmds, **cfg)
if __name__ == "__main__":
main()