-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
executable file
·78 lines (60 loc) · 2.54 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
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
77
78
from collections import OrderedDict
from tempfile import NamedTemporaryFile
import argparse
import yaml
import json
import os
from crossbar import run
from twisted.logger import Logger
from twisted.python.logfile import DailyLogFile
from mdstudio.logging.brand import ascii_brand
from mdstudio.logging.impl.printing_observer import PrintingLogObserver
if __name__ == '__main__':
temp_config = None
log_file = None
try:
with open('crossbar_config.yml', 'r') as cc:
config = yaml.safe_load(cc)
ring0_config = [{
"type": "class",
"classname": "{role}.application.{component}Component".format(role=role, component=component),
"realm": "mdstudio",
"role": role
} for role, component in OrderedDict([
('auth', 'Auth'),
('cache', 'Cache'),
('db', 'DB'),
('schema', 'Schema'),
('logger', 'Logger')
]).items()]
ticket_config = {
"type": "static",
"principals": OrderedDict((role, {'role': role, 'ticket': role}) for role in ['auth', 'db', 'schema', 'logger'])
}
parser = argparse.ArgumentParser(description='MDstudio application startup script')
parser.add_argument('--dev', action='store_true', help='Flag to run in dev mode. Allows core components to start separately.')
parser.add_argument('-s', '--skip-startup', nargs='+', metavar='COMPONENT', help='List of core components that are not started (--dev required)')
args = parser.parse_args()
if args.dev:
if args.skip_startup:
ring0_config = [v for v in ring0_config if v['role'] not in args.skip_startup]
else:
ring0_config = None
config['workers'][0]['transports'][0]['paths']['ws']['auth'].update({'ticket': ticket_config})
if ring0_config:
config['workers'][0]['components'] = ring0_config
temp_config = NamedTemporaryFile(delete=False, suffix='.json')
temp_config.write(json.dumps(config).encode('utf-8'))
temp_config.close()
if not os.path.isdir('logs'):
os.mkdir('logs')
log_file = DailyLogFile('daily.log', 'logs')
log = Logger(observer=PrintingLogObserver(log_file))
print(ascii_brand)
run(['start', '--cbdir', '.', '--config', temp_config.name, '--loglevel', 'info',])
finally:
if temp_config:
os.remove(temp_config.name)
if log_file:
log_file.flush()
log_file.close()