forked from Autodesk/hubble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.py
34 lines (26 loc) · 883 Bytes
/
schema.py
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
import csv
import os
import sys
from config import *
from helpers import *
schemaVersion = 1
# Check the data repository's schema version and fail if it's outdated
# Assumes that the data directory is already initialized and up-to-date
def checkSchemaVersion(dataDirectory):
schemaVersionLocal = 0
try:
metaFilePath = os.path.join(dataDirectory, "meta.tsv")
# If no meta.tsv has been created yet, no schema compatibility check is necessary
if not os.path.exists(metaFilePath):
return
with open(metaFilePath, "r") as tsvFile:
tsvReader = csv.reader(tsvFile, delimiter = "\t")
for row in tsvReader:
if row[0] == "schema-version":
schemaVersionLocal = int(row[1])
break
except:
pass
if schemaVersionLocal < schemaVersion:
print("error: the data repository has an outdated scheme and needs to be migrated", file = sys.stderr)
sys.exit(1)