-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
executable file
·89 lines (73 loc) · 2.53 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
79
80
81
82
83
84
85
86
87
88
89
from db.QuestList import *
from db.NpcList import *
from db.ObjList import *
from db.CoordList import *
from db.ItemList import *
from preExtract.CoordPreExtract import printCoordFiles
import sys
import pymysql
import config
import time
version = config.version
debug = config.debug
if version not in ['classic', 'tbc', 'wotlk']:
print(f'Unknown version {version}')
sys.exit(1)
def getClassInstances(recache=False):
"""Get new instances of the list classes"""
quests = QuestList(cursor, dictCursor, version, recache=recache)
npcs = NpcList(cursor, dictCursor, version, recache=recache, debug=debug)
obj = ObjList(cursor, dictCursor, version, recache=recache)
items = ItemList(dictCursor, version, recache=recache)
return quests, npcs, obj, items
def recache():
_, _, _, _ = getClassInstances(True)
def main(recache):
"""Extracts and prints quest related data"""
quests, npcs, objects, items = getClassInstances(recache)
print("Printing files...")
quests.printQuestFile(f'output/{version}/{version}QuestDB.lua')
npcs.printNpcFile(f'output/{version}/{version}NpcDB.lua')
objects.printObjFile(f'output/{version}/{version}ObjectDB.lua')
items.writeFile(f'output/{version}/{version}ItemDB.lua')
print("Done.")
return 0
def getCursors(v):
connection = pymysql.connect(
host=config.dbInfo['host'],
user=config.dbInfo['user'],
password=config.dbInfo['password'],
database=config.dbInfo[v],
port=config.dbInfo["port"],
charset='utf8'
)
c = connection.cursor()
dc = connection.cursor(pymysql.cursors.DictCursor)
return c, dc
def preExtract(v):
c, dc = getCursors(v)
printCoordFiles(c, v)
# DB connection needs to be set up first and globally, but after CLI
# arguments are checked, in case the argument differs from the config
# file, so the main function being run is delayed by use of this variable
runMain = False
reCache = False
if __name__ == "__main__":
"""Executes only if run as a script"""
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
if arg == '-r':
reCache = True
elif arg in ['classic', 'tbc', 'wotlk']:
version = arg
else:
print(f'Unknown argument "{arg}"')
print(f'Using version {version}')
runMain = True
cursor, dictCursor = getCursors(version)
if runMain:
start_time = time.time()
main(reCache)
print("--- %s seconds ---" % (time.time() - start_time))
else:
print(f'Using version {version}')