This repository has been archived by the owner on May 10, 2019. It is now read-only.
forked from Map-A-Droid/MAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configmode.py
93 lines (77 loc) · 3.02 KB
/
configmode.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import sys
from threading import Thread
from db.monocleWrapper import MonocleWrapper
from db.rmWrapper import RmWrapper
from utils.logging import initLogging, logger
from utils.mappingParser import MappingParser
from utils.version import MADVersion
from utils.walkerArgs import parseArgs
from websocket.WebsocketServer import WebsocketServer
args = parseArgs()
os.environ['LANGUAGE'] = args.language
initLogging(args)
def generate_mappingjson():
import json
newfile = {}
newfile['areas'] = []
newfile['auth'] = []
newfile['devices'] = []
newfile['walker'] = []
newfile['devicesettings'] = []
with open('configs/mappings.json', 'w') as outfile:
json.dump(newfile, outfile, indent=4, sort_keys=True)
def start_madmin(args, db_wrapper, ws_server):
from madmin.madmin import madmin_start
madmin_start(args, db_wrapper, ws_server)
def load_mappings(db_wrapper):
mapping_parser = MappingParser(db_wrapper, args, configmode=True)
device_mappings = mapping_parser.get_devicemappings()
routemanagers = mapping_parser.get_routemanagers()
auths = mapping_parser.get_auths()
return (device_mappings, routemanagers, auths)
if __name__ == "__main__":
logger.info('Start MAD configmode - pls wait')
filename = os.path.join('configs', 'config.ini')
if not os.path.exists(filename):
logger.error(
'Config.ini not found - check configs folder and copy .example')
sys.exit(1)
filename = os.path.join('configs', 'mappings.json')
if not os.path.exists(filename):
generate_mappingjson()
if args.db_method == "rm":
db_wrapper = RmWrapper(args)
elif args.db_method == "monocle":
db_wrapper = MonocleWrapper(args)
else:
logger.error("Invalid db_method in config. Exiting")
sys.exit(1)
db_wrapper.create_hash_database_if_not_exists()
db_wrapper.check_and_create_spawn_tables()
db_wrapper.create_quest_database_if_not_exists()
db_wrapper.create_status_database_if_not_exists()
db_wrapper.create_usage_database_if_not_exists()
version = MADVersion(args, db_wrapper)
version.get_version()
try:
(device_mappings, routemanagers, auths) = load_mappings(db_wrapper)
except KeyError as e:
logger.error(
"Could not parse mappings. Please check those. Reason: {}", str(e))
sys.exit(1)
except RuntimeError as e:
logger.error(
"There is something wrong with your mappings. Reason: {}", str(e))
sys.exit(1)
ws_server = WebsocketServer(args, None, db_wrapper,
routemanagers, device_mappings, auths, None, True)
t_ws = Thread(name='scanner', target=ws_server.start_server)
t_ws.daemon = False
t_ws.start()
logger.success(
'Starting MADmin on port {} - open browser and click "Mapping Editor"', int(args.madmin_port))
t_flask = Thread(name='madmin', target=start_madmin,
args=(args, db_wrapper, ws_server))
t_flask.daemon = False
t_flask.start()