-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathk4cglicht.py
executable file
·52 lines (45 loc) · 1.43 KB
/
k4cglicht.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
#!/usr/bin/env python
def load_modes():
importdir.do("modes", globals())
modes = {}
for mode in Mode.__subclasses__():
params = mode.get_params()
try:
for name, option in params:
modes[name] = mode
except:
modes[params[0]] = mode
return modes
def init_parser(modes):
def add_arg(parser, name, option):
if not option:
parser.add_argument('--' + name, action='store_true')
else:
parser.add_argument('--' + name, metavar=option)
parser = ArgumentParser(prog='k4cglicht.py')
for mode in modes:
params = mode.get_params()
try:
for name, option in params:
add_arg(parser, name, option)
except:
add_arg(parser, params[0], params[1])
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1')
return parser
import sys
import json
from argparse import ArgumentParser
from vendor import importdir
from mode import Mode
from lightutils.LightUtils import LightUtils
if __name__ == '__main__':
modes = load_modes()
parser = init_parser(set(modes.values()))
args = parser.parse_args()
config = []
with open('config.json') as configFile:
config = json.load(configFile)
lightutils = LightUtils(config)
for key, value in args.__dict__.iteritems():
if value:
modes[key].execute(lightutils, value)