1
- #!/usr/bin/env python
1
+ #!/usr/bin/env python3
2
2
#======================================================================
3
3
# Copyright (C) 2012 Diego Duclos
4
4
#
18
18
# License along with eos. If not, see <http://www.gnu.org/licenses/>.
19
19
#======================================================================
20
20
21
+
21
22
import functools
23
+ import itertools
24
+ import json
22
25
import os
26
+ import sqlite3
23
27
import sys
24
28
25
- # Add eos root path to sys.path so we can import ourselves
26
- path = os .path .dirname (__file__ )
27
- sys .path .insert (0 , os .path .realpath (os .path .join (path , '..' )))
28
29
29
- import json
30
- import argparse
31
- import itertools
30
+ ROOT_DIR = os .path .realpath (os .path .dirname (__file__ ))
31
+ DB_PATH = os .path .join (ROOT_DIR , 'eve.db' )
32
+ JSON_DIR = os .path .join (ROOT_DIR , 'staticdata' )
33
+ if ROOT_DIR not in sys .path :
34
+ sys .path .insert (0 , ROOT_DIR )
35
+ GAMEDATA_SCHEMA_VERSION = 1
32
36
33
37
34
38
CATEGORIES_TO_REMOVE = [
35
39
30 # Apparel
36
40
]
37
41
38
- def main (db , json_path ):
39
- if os .path .isfile (db ):
40
- os .remove (db )
41
42
42
- jsonPath = os .path .expanduser (json_path )
43
+ def db_needs_update ():
44
+ """True if needs, false if it does not, none if we cannot check it."""
45
+ try :
46
+ with open (os .path .join (JSON_DIR , 'phobos' , 'metadata.json' )) as f :
47
+ data_version = next ((r ['field_value' ] for r in json .load (f ) if r ['field_name' ] == 'client_build' ))
48
+ except KeyboardInterrupt :
49
+ raise
50
+ # If we have no source data - return None; should not update in this case
51
+ except :
52
+ return None
53
+ if not os .path .isfile (DB_PATH ):
54
+ return True
55
+ db_data_version = None
56
+ db_schema_version = None
57
+ try :
58
+ db = sqlite3 .connect (DB_PATH )
59
+ cursor = db .cursor ()
60
+ cursor .execute ('SELECT field_value FROM metadata WHERE field_name = \' client_build\' ' )
61
+ for row in cursor :
62
+ db_data_version = int (row [0 ])
63
+ cursor .execute ('SELECT field_value FROM metadata WHERE field_name = \' schema_version\' ' )
64
+ for row in cursor :
65
+ db_schema_version = int (row [0 ])
66
+ cursor .close ()
67
+ db .close ()
68
+ except KeyboardInterrupt :
69
+ raise
70
+ except :
71
+ return True
72
+ return data_version != db_data_version or GAMEDATA_SCHEMA_VERSION != db_schema_version
73
+
74
+
75
+ def update_db ():
76
+
77
+ if os .path .isfile (DB_PATH ):
78
+ os .remove (DB_PATH )
43
79
44
- # Import eos.config first and change it
45
- import eos .config
46
- eos .config .gamedata_connectionstring = db
47
- eos .config .debug = False
48
-
49
- # Now thats done, we can import the eos modules using the config
50
80
import eos .db
51
81
import eos .gamedata
52
82
@@ -274,7 +304,7 @@ def compareAttrs(attrs1, attrs2):
274
304
275
305
# Dump all data to memory so we can easely cross check ignored rows
276
306
for jsonName , (minerName , cls ) in tables .items ():
277
- with open (os .path .join (jsonPath , minerName , '{}.json' .format (jsonName )), encoding = 'utf-8' ) as f :
307
+ with open (os .path .join (JSON_DIR , minerName , '{}.json' .format (jsonName )), encoding = 'utf-8' ) as f :
278
308
tableData = json .load (f )
279
309
if jsonName in rowsInValues :
280
310
newTableData = []
@@ -373,7 +403,7 @@ def isIgnored(file, row):
373
403
eos .db .gamedata_session .add (instance )
374
404
375
405
# quick and dirty hack to get this data in
376
- with open (os .path .join (jsonPath , 'fsd_binary' , 'dynamicitemattributes.json' ), encoding = 'utf-8' ) as f :
406
+ with open (os .path .join (JSON_DIR , 'fsd_binary' , 'dynamicitemattributes.json' ), encoding = 'utf-8' ) as f :
377
407
bulkdata = json .load (f )
378
408
for mutaID , data in bulkdata .items ():
379
409
muta = eos .gamedata .DynamicItem ()
@@ -402,10 +432,8 @@ def isIgnored(file, row):
402
432
# pyfa, we can do it here as a post-processing step
403
433
eos .db .gamedata_engine .execute ('UPDATE dgmtypeattribs SET value = 4.0 WHERE attributeID = ?' , (1367 ,))
404
434
405
- eos .db .gamedata_engine .execute ('UPDATE invtypes SET published = 0 WHERE typeName LIKE \' %abyssal%\' ' )
435
+ eos .db .gamedata_engine .execute ('UPDATE invtypes SET published = 0 WHERE typeName LIKE \' %abyssal%\' ' )
406
436
407
- # fix for #1722 until CCP gets their shit together
408
- eos .db .gamedata_engine .execute ('UPDATE invtypes SET typeName = \' Small Abyssal Energy Nosferatu\' WHERE typeID = ? AND typeName = ?' , (48419 , '' ))
409
437
410
438
print ()
411
439
for x in CATEGORIES_TO_REMOVE :
@@ -418,11 +446,6 @@ def isIgnored(file, row):
418
446
419
447
print ('done' )
420
448
421
- if __name__ == '__main__' :
422
- parser = argparse .ArgumentParser (description = 'This scripts dumps effects from an sqlite cache dump to mongo' )
423
- parser .add_argument ('-d' , '--db' , required = True , type = str , help = 'The sqlalchemy connectionstring, example: sqlite:///c:/tq.db' )
424
- parser .add_argument ('-j' , '--json' , required = True , type = str , help = 'The path to the json dump' )
425
- args = parser .parse_args ()
426
-
427
- main (args .db , args .json )
428
449
450
+ if __name__ == '__main__' :
451
+ update_db ()
0 commit comments