Skip to content

Commit 39dc7e4

Browse files
committed
Compose DB out of data stored externally
1 parent 9e78cd1 commit 39dc7e4

22 files changed

+4019685
-29
lines changed

.appveyor.yml

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ before_build:
6565
build_script:
6666
- ECHO "Build pyfa:"
6767

68+
# Build gamedata DB
69+
- "python db_update.py"
6870
##########
6971
# PyInstaller - create binaries for pyfa
7072
##########

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ matrix:
1313
before_install:
1414
- bash scripts/setup-osx.sh
1515
install:
16+
- python3 db_update.py
1617
- export PYFA_VERSION="$(python3 scripts/dump_version.py)"
1718
- bash scripts/package-osx.sh
1819
before_deploy:

scripts/jsonToSql.py db_update.py

+52-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#======================================================================
33
# Copyright (C) 2012 Diego Duclos
44
#
@@ -18,35 +18,65 @@
1818
# License along with eos. If not, see <http://www.gnu.org/licenses/>.
1919
#======================================================================
2020

21+
2122
import functools
23+
import itertools
24+
import json
2225
import os
26+
import sqlite3
2327
import sys
2428

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, '..')))
2829

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
3236

3337

3438
CATEGORIES_TO_REMOVE = [
3539
30 # Apparel
3640
]
3741

38-
def main(db, json_path):
39-
if os.path.isfile(db):
40-
os.remove(db)
4142

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)
4379

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
5080
import eos.db
5181
import eos.gamedata
5282

@@ -274,7 +304,7 @@ def compareAttrs(attrs1, attrs2):
274304

275305
# Dump all data to memory so we can easely cross check ignored rows
276306
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:
278308
tableData = json.load(f)
279309
if jsonName in rowsInValues:
280310
newTableData = []
@@ -373,7 +403,7 @@ def isIgnored(file, row):
373403
eos.db.gamedata_session.add(instance)
374404

375405
# 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:
377407
bulkdata = json.load(f)
378408
for mutaID, data in bulkdata.items():
379409
muta = eos.gamedata.DynamicItem()
@@ -402,10 +432,8 @@ def isIgnored(file, row):
402432
# pyfa, we can do it here as a post-processing step
403433
eos.db.gamedata_engine.execute('UPDATE dgmtypeattribs SET value = 4.0 WHERE attributeID = ?', (1367,))
404434

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%\'')
406436

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, ''))
409437

410438
print()
411439
for x in CATEGORIES_TO_REMOVE:
@@ -418,11 +446,6 @@ def isIgnored(file, row):
418446

419447
print('done')
420448

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)
428449

450+
if __name__ == '__main__':
451+
update_db()

eve.db

-16.5 MB
Binary file not shown.

pyfa.py

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import config
2828
from service.prereqsCheck import PreCheckException, PreCheckMessage, version_block, version_precheck
29+
from db_update import db_needs_update, update_db
2930

3031

3132
# ascii_text = '''
@@ -116,6 +117,10 @@ def _process_args(self, largs, rargs, values):
116117
else:
117118
pyfalog.info("Running in a thawed state.")
118119

120+
if db_needs_update() is True:
121+
pyfalog.info("Gamedata needs an update")
122+
update_db()
123+
119124
# Lets get to the good stuff, shall we?
120125
import eos.db
121126
import eos.events # todo: move this to eos initialization?

0 commit comments

Comments
 (0)