Allow loading schema data from an arbitrary file.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-08-05 22:51:09 +00:00
parent 476863a44b
commit 07983b4a32
No known key found for this signature in database
GPG key ID: BF535D811F52F68B

View file

@ -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")