Allow loading schema data from an arbitrary file.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
476863a44b
commit
07983b4a32
1 changed files with 8 additions and 4 deletions
|
|
@ -291,27 +291,31 @@ class Schema:
|
|||
|
||||
@staticmethod
|
||||
def load(path):
|
||||
vault = newfol.filemanip.FileStorage('csv', path + "/schema")
|
||||
return Schema.load_file("%s/schema" % path)
|
||||
|
||||
@staticmethod
|
||||
def load_file(path):
|
||||
vault = newfol.filemanip.FileStorage('csv', path)
|
||||
try:
|
||||
recs = vault.load()
|
||||
except IOError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
vault.store([newfol.filemanip.Record(["fmt", "0",
|
||||
"newfol schema file"])])
|
||||
return Schema.load(path)
|
||||
return Schema.load_file(path)
|
||||
else:
|
||||
raise
|
||||
except FileNotFoundError:
|
||||
vault.store([newfol.filemanip.Record(["fmt", "0",
|
||||
"newfol schema file"])])
|
||||
return Schema.load(path)
|
||||
return Schema.load_file(path)
|
||||
if recs[0].fields[0] != "fmt":
|
||||
raise newfol.exception.NewfolError("Schema file does not " +
|
||||
"have format declaration")
|
||||
if recs[0].fields[1] in ['0', '1', '2']:
|
||||
func = getattr(Schema, '_upgrade_v%s' % recs[0].fields[1])
|
||||
func(vault, recs)
|
||||
return Schema.load(path)
|
||||
return Schema.load_file(path)
|
||||
elif recs[0].fields[1] != "3":
|
||||
raise newfol.exception.NewfolError("Schema file has unknown " +
|
||||
"format")
|
||||
|
|
|
|||
Loading…
Reference in a new issue