MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / db_needs_update

Function db_needs_update

db_update.py:45–82  ·  view source on GitHub ↗

True if needs, false if it does not, none if we cannot check it.

()

Source from the content-addressed store, hash-verified

43
44
45def db_needs_update():
46 """True if needs, false if it does not, none if we cannot check it."""
47 try:
48 with open(os.path.join(JSON_DIR, 'phobos', 'metadata.0.json')) as f:
49 data_version = next((r['field_value'] for r in json.load(f) if r['field_name'] == 'client_build'))
50 except (KeyboardInterrupt, SystemExit):
51 raise
52 # If we have no source data - return None; should not update in this case
53 except:
54 return None
55 if not os.path.isfile(DB_PATH):
56 print('Gamedata DB not found')
57 return True
58 db_data_version = None
59 db_schema_version = None
60 try:
61 db = sqlite3.connect(DB_PATH)
62 cursor = db.cursor()
63 cursor.execute('SELECT field_value FROM metadata WHERE field_name = \'client_build\'')
64 for row in cursor:
65 db_data_version = int(row[0])
66 cursor.execute('SELECT field_value FROM metadata WHERE field_name = \'schema_version\'')
67 for row in cursor:
68 db_schema_version = int(row[0])
69 cursor.close()
70 db.close()
71 except (KeyboardInterrupt, SystemExit):
72 raise
73 except:
74 print('Error when fetching gamedata DB metadata')
75 return True
76 if data_version != db_data_version:
77 print('Gamedata DB data version mismatch: needed {}, DB has {}'.format(data_version, db_data_version))
78 return True
79 if GAMEDATA_SCHEMA_VERSION != db_schema_version:
80 print('Gamedata DB schema version mismatch: needed {}, DB has {}'.format(GAMEDATA_SCHEMA_VERSION, db_schema_version))
81 return True
82 return False
83
84
85def update_db():

Callers 1

pyfa.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected