-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsys-start.py
More file actions
executable file
·35 lines (29 loc) · 1016 Bytes
/
consys-start.py
File metadata and controls
executable file
·35 lines (29 loc) · 1016 Bytes
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
#!/usr/bin/env python2
from __future__ import print_function
from __future__ import unicode_literals
import sys
valid_actions = ['client', 'server', 'admin']
def choose_by_name(name):
for a in valid_actions:
if name.endswith(a):
return a
return None
if __name__ == '__main__':
action = choose_by_name(sys.argv[0])
if not action:
if len(sys.argv) < 2 or not sys.argv[1] in valid_actions:
print('Please specify one of '
'{{{0}}}.'.format(', '.join(valid_actions)),
file=sys.stderr)
sys.exit(-1)
else:
action = sys.argv[1]
sys.argv[0] += ' ' + action
sys.argv = sys.argv[0:1] + sys.argv[2:]
try:
# FIXME when migrating to Python 3!
a = __import__('consys.' + action, fromlist=[b'run'])
a.run()
except ImportError as e:
print('Sorry, \'{0}\' is not available on this system'.format(action),
file=sys.stderr)