-
Notifications
You must be signed in to change notification settings - Fork 2
/
haraka-configure.py
executable file
·56 lines (46 loc) · 1.19 KB
/
haraka-configure.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
#!/usr/bin/env python3
import jinja2
import argparse
import os
argParser = argparse.ArgumentParser()
argParser.add_argument(
"-c",
"--haraka-config-dir",
help="Haraka config dir",
type=str
)
argParser.add_argument(
"-t",
"--haraka-config-templates-dir",
help="Haraka templates config dir",
type=str
)
argParser.add_argument(
"-d",
"--debug",
help="Turn debug outputs on",
default=False,
action='store_true'
)
args = argParser.parse_args()
DEBUG = args.debug or False
templatesPath = args.haraka_config_templates_dir or "./templates"
# check if templatesPath exists
if not os.path.exists(templatesPath):
print("Templates path does not exist: {}".format(templatesPath))
exit(1)
harakaConfigDir = args.haraka_config_dir or "./output"
# Write input configs
inputEnv = jinja2.Environment(
loader=jinja2.FileSystemLoader(
searchpath = templatesPath
)
)
for file in os.listdir(templatesPath):
template = inputEnv.get_template(file)
r = template.render(env=os.environ, debug=DEBUG)
print("--------------------")
print(os.path.join(harakaConfigDir, file))
print(r)
with open(os.path.join(harakaConfigDir, file), "w") as f:
f.write(r)