forked from Muehe/sqlua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·122 lines (107 loc) · 4.04 KB
/
Copy pathmain.py
File metadata and controls
executable file
·122 lines (107 loc) · 4.04 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from db.QuestList import QuestList
from db.NpcList import *
from db.ObjList import *
from db.ItemList import *
from preExtract.CoordPreExtract import printCoordFiles
import sys
import pymysql
import config
import time
version = config.version
if version not in versions:
print(f'Unknown version {version}')
sys.exit(1)
flavor = config.flavor
if flavor not in flavors:
print(f'Unknown flavor {flavor}')
sys.exit(1)
debug = config.debug
def getClassInstances(recache=False, v=version, f=flavor):
"""Get new instances of the list classes"""
print(f"Reading data from database {f} {v}...")
c, dc = getCursors(v, f)
quests = QuestList(v, f, c, dc, recache=recache)
npcs = NpcList(v, f, c, dc, recache=recache, extractSpawns=True, debug=debug)
obj = ObjList(v, f, c, extractSpawns=True, recache=recache)
items = ItemList(v, f, dc, locale='enUS', recache=recache)
return quests, npcs, obj, items
def recache():
_, _, _, _ = getClassInstances(True)
def main(recache=False, v=version, f=flavor):
"""Extracts and prints quest related data"""
if not individualUpdates:
quests, npcs, objects, items = getClassInstances(recache, v, f)
print("Printing files...")
quests.printQuestFile(f'output/{v}/{f}/{v}QuestDB.lua')
npcs.printNpcFile(f'output/{v}/{f}/{v}NpcDB.lua')
objects.printObjFile(f'output/{v}/{f}/{v}ObjectDB.lua')
items.writeFile(f'output/{v}/{f}/{v}ItemDB.lua')
print("Done.")
return 0
else:
c, dc = getCursors(v, f)
if 'items' in sys.argv:
items = ItemList(v, f, dc, locale='enUS', recache=recache)
items.writeFile(f'output/{v}/{f}/{v}ItemDB.lua')
if 'npcs' in sys.argv:
npcs = NpcList(v, f, c, dc, recache=recache, extractSpawns=True, debug=debug)
npcs.printNpcFile(f'output/{v}/{f}/{v}NpcDB.lua')
if 'objects' in sys.argv:
objects = ObjList(v, f, c, extractSpawns=True, recache=recache)
objects.printObjFile(f'output/{v}/{f}/{v}ObjectDB.lua')
if 'quests' in sys.argv:
quests = QuestList(v, f, c, dc, recache=recache)
quests.printQuestFile(f'output/{v}/{f}/{v}QuestDB.lua')
return 0
def getCursors(v=version, f=flavor):
conversions = pymysql.converters.conversions
conversions[pymysql.FIELD_TYPE.DECIMAL] = lambda x: float(x)
conversions[pymysql.FIELD_TYPE.NEWDECIMAL] = lambda x: float(x)
connection = pymysql.connect(
host=config.dbInfo['host'],
user=config.dbInfo['user'],
password=config.dbInfo['password'],
database=config.dbInfo[f][v],
port=config.dbInfo["port"],
charset='utf8',
conv=conversions
)
c = connection.cursor()
dc = connection.cursor(pymysql.cursors.DictCursor)
return c, dc
def preExtract(v=version, f=flavor):
c, dc = getCursors(v, f)
printCoordFiles(c, v, f)
# 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
individualUpdates = False
reCache = False
if __name__ == "__main__":
"""Executes only if run as a script"""
print(len(sys.argv))
print(sys.argv)
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
if arg == '-r':
reCache = True
elif arg in versions:
version = arg
elif arg in flavors:
flavor = arg
elif arg in ['items', 'npcs', 'objects', 'quests']:
individualUpdates = True
else:
print(f'Unknown argument "{arg}"')
print(f'Using version {version}')
print(f'Using DB flavour {flavor}')
runMain = True
cursor, dictCursor = getCursors(version, flavor)
if runMain:
start_time = time.time()
main(reCache, version, flavor)
print("--- %s seconds ---" % (time.time() - start_time))
else:
print(f'Using version {version}')
print(f'Using DB flavour {flavor}')