forked from qwc-services/qwc-config-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_generator_cli.py
76 lines (59 loc) · 2.06 KB
/
config_generator_cli.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
"""
Copyright © 2023 by BGEO. All rights reserved.
The program is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
"""
import argparse
from collections import OrderedDict
from datetime import datetime
import json
import os
from config_generator.config_generator import ConfigGenerator
class Logger():
"""Simple logger class"""
def debug(self, msg):
print("[%s] \033[36mDEBUG: %s\033[0m" % (self.timestamp(), msg))
def info(self, msg):
print("[%s] INFO: %s" % (self.timestamp(), msg))
def warning(self, msg):
print("[%s] \033[33mWARNING: %s\033[0m" % (self.timestamp(), msg))
def warn(self, msg):
self.warning(msg)
def error(self, msg):
print("[%s] \033[31mERROR: %s\033[0m" % (self.timestamp(), msg))
def critical(self, msg):
print("[%s] \033[91mCRITICAL: %s\033[0m" % (self.timestamp(), msg))
def timestamp(self):
return datetime.now()
print("QWC ConfigGenerator")
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument(
'config_file', help="Path to ConfigGenerator config file"
)
parser.add_argument(
"command", choices=['all', 'service_configs', 'permissions'],
help="generate service configs and/or permissions"
)
args = parser.parse_args()
# read ConfigGenerator config file
try:
with open(args.config_file) as f:
# parse config JSON with original order of keys
config = json.load(f, object_pairs_hook=OrderedDict)
except Exception as e:
print("Error loading ConfigGenerator config:\n%s" % e)
exit(1)
# create logger
logger = Logger()
# create ConfigGenerator
generator = ConfigGenerator(config, logger)
if args.command == 'all':
generator.write_configs()
generator.write_permissions()
elif args.command == 'service_configs':
generator.write_configs()
elif args.command == 'permissions':
generator.write_permissions()
generator.cleanup_temp_dir()