- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
Latest commit
152 lines (100 loc) · 3.45 KB
/
Copy pathdatabase.py
File metadata and controls
152 lines (100 loc) · 3.45 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""
Kristoffer Langeland Knudsen
rainbowponyprincess@gmail.com
"""
importos
importbz2
importtime
importurllib2
importsqlite3assql
importcache
globaldb
## --------------------------------------------------------------- ##
definitialize(configtree):
"""
Initialize the sqlite3 database. This provides access to the EVE Online database
dump, containing information about item names, reprocessing yields, and so on.
"""
globaldb
filename=configtree.findtext(".//updates/database/filename")
ifnotos.path.isfile(filename):
# Some skank has sabotaged the database. It's time for an update.
updateDatabase(configtree)
db=sql.connect(filename)
## --------------------------------------------------------------- ##
defcursor():
globaldb
returndb.cursor()
## --------------------------------------------------------------- ##
defupdate(configtree):
cache.resetUpdateTimer('database',
time.time() +
float(configtree.findtext('.//updates/database/timer')))
local=configtree.findtext('.//updates/database/filename') +'.md5'
remote=configtree.findtext('.//updates/database/md5')
ifcheckDatabaseHash(local, remote):
print("")
print(" Update available.")
print("")
updateDatabase(configtree)
else:
print("")
print(" No update available")
print("")
defcheckDatabaseHash(local, remote):
ifnotos.path.isfile(local):
returnTrue
localHash=open(local)
remoteHash=urllib2.urlopen(remote)
returnlocalHash.read() !=remoteHash.read()
defupdateDatabase(configtree):
"""
Update the EVE Online database SDE. Awesome.
"""
url=configtree.findtext(".//updates/database/url")
filename=configtree.findtext(".//updates/database/filename")
print("Updating database...")
print("Fetching sqlite database dump:")
print(url)
# All right - get the sqlite dump.
response=urllib2.urlopen(url)
print("\tResponse: "+str(response.getcode()))
ifresponse.getcode() !=200:
return
print("Downloading...")
dump=response.read()
print("Decompressing...")
dump=bz2.decompress(dump)
# Let's put it in a file.
sqlitefile=open(filename, 'wb')
sqlitefile.write(dump)
print("Wrote file: "+filename)
print("Fetching hash...")
md5=urllib2.urlopen(configtree.findtext('.//updates/database/md5'))
md5file=open(configtree.findtext('.//updates/database/filename') +'.md5', 'w')
md5file.write(md5.read())
print("Trimming database...")
try:
trimDatabase(filename)
print("\tOK")
except:
print("\tFAILED - This is common, don't worry.")
print("")
print("")
deftrimDatabase(filename):
# This is a hardcoded list for now, deal with it.
tables= ['invTypes',
'invGroups',
'invMarketGroups',
'invTypeMaterials',
'mapSolarSystems',
'staStations']
db=sql.connect(filename)
cursor=db.cursor()
cursor.execute("SELECT name, type FROM sqlite_master WHERE type='table'")
forname, _incursor.fetchall():
ifnamenotintables:
db.execute("DROP TABLE "+name+";")
db.commit()
db.execute("VACUUM")
db.close()