manifest: Load the metaschema only once

This commit is contained in:
Nicolas Braud-Santoni 2016-03-01 15:05:05 +01:00
parent 324a2fb7d4
commit bcd1c7b536

View file

@ -27,6 +27,11 @@ class Manifest(object):
if path is None and data is None:
raise ManifestError('`path\' or `data\' must be provided')
self.path = path
import os.path
self.metaschema = load_data(os.path.normpath(os.path.join(os.path.dirname(__file__),
'metaschema.json')))
self.load_data(data)
self.load_modules()
self.validate()
@ -119,13 +124,11 @@ class Manifest(object):
:param str schema_path: Path to the json-schema to use for validation
"""
import jsonschema
import os.path
schema = load_data(schema_path)
metaschema = load_data(os.path.normpath(os.path.join(os.path.dirname(__file__), 'metaschema.json')))
try:
jsonschema.validate(schema, metaschema)
jsonschema.validate(schema, self.metaschema)
jsonschema.validate(data, schema)
except jsonschema.ValidationError as e:
self.validation_error(e.message, e.path)