-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
executable file
·32 lines (28 loc) · 1.09 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
#!/opt/local/bin/python2.7
import os, sys, yaml
from parse.state import Overrides, State
from gen.cmd import Cmd
if __name__ == '__main__':
state = None
router_attrs = {}
for key, envname in {'dev': 'ROUTER_DEV', 'src': 'ROUTER_SRC'}.iteritems():
router_attrs[key] = dict(map(lambda token: token.split(':'),
os.environ.get(envname, '').split()))
if 'CFG' in os.environ:
overrides = None
if 'OVERRIDES' in os.environ:
overrides = Overrides.load(os.environ['OVERRIDES'])
with open(os.environ['CFG'], 'r') as cfgfile:
state = State(yaml.load(cfgfile),
overrides=overrides, router_attrs=router_attrs)
else:
state = State(yaml.load(sys.stdin, Loader=yaml.CLoader), router_attrs)
if len(state.errors):
for error in state.errors: print >> sys.stderr, 'Error: %s' % error
sys.exit(1)
else:
try:
print Cmd.execute(state, sys.argv[1:])
except Exception as e:
print >> sys.stderr, e
sys.exit(1)