-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
142 lines (125 loc) · 3.33 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
Contains the main entrypoint for this application
"""
import argparse
import sys
from loguru import logger
from .graph import plot
from .transpiler import transpile
def main() -> None:
"""
Entrypoint of the application
"""
args = parse_args()
setup_logging(args.verbosity)
if args.command == "transpile":
# todo: verify valid dirs
transpile(
args.architecture, args.templates, args.output, args.report, args.debug
)
elif args.command == "plot":
plot(args.architecture, args.output, args.format)
def parse_args() -> dict:
"""
Setup the CLI interface
"""
parser = argparse.ArgumentParser(
description="Templating engine for cloud architectures"
)
parser.add_argument(
"--verbosity",
"-v",
default="info",
dest="verbosity",
nargs="?",
choices=["trace", "debug", "info", "success", "warning", "error", "critical"],
help="set the logging level",
)
subparsers = parser.add_subparsers(
help="sub commands", required=True, dest="command"
)
transpile_parser = subparsers.add_parser(
"transpile", help="transpiles the given architecture"
)
transpile_parser.add_argument(
"--architecture",
"-a",
default="architecture.yaml",
dest="architecture",
required=True,
help="the architecture definition file",
)
transpile_parser.add_argument(
"--output", "-o", default="out/", dest="output", help="the output directory"
)
transpile_parser.add_argument(
"--templates",
"-t",
default="templates/",
dest="templates",
help="the template directory",
)
transpile_parser.add_argument(
"--report",
"-r",
action="store_true",
dest="report",
help="generates a report of the generated files",
)
transpile_parser.add_argument(
"--debug",
"-d",
action="store_true",
dest="debug",
help="enable debug output and report",
)
plot_parser = subparsers.add_parser(
"plot", help="generates a graphviz .dot file of the architecture"
)
plot_parser.add_argument(
"--architecture",
"-a",
default="architecture.yaml",
dest="architecture",
required=True,
help="the architecture definition file",
)
plot_parser.add_argument(
"--output", "-o", default="out.dot", dest="output", help="the generated file"
)
plot_parser.add_argument(
"--format",
"-f",
default="dot",
dest="format",
nargs="?",
choices=[
"neato",
"dot",
"twopi",
"circo",
"fdp",
"nop",
"osage",
"patchwork",
"gc",
"acyclic",
"gvpr",
"gvcolor",
"ccomps",
"sccmap",
"tred",
"sfdp",
"unflatten",
],
help="the file format of the output",
)
return parser.parse_args()
def setup_logging(verbosity: str) -> None:
"""
Sets up the logging system
"""
logger.remove()
logger.add(sys.stderr, level=verbosity.upper(), backtrace=True, colorize=True)
if __name__ == "__main__":
main()