From 1dc9ae18db10b52d547a2692ae2bfb1244bd4bac Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 6 Jul 2014 22:27:36 +0200 Subject: [PATCH] Do a basic validation of the manifest before accessing it. This prevents cryptic error messages --- bootstrapvz/base/manifest.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bootstrapvz/base/manifest.py b/bootstrapvz/base/manifest.py index 44f56f1..8151bdd 100644 --- a/bootstrapvz/base/manifest.py +++ b/bootstrapvz/base/manifest.py @@ -25,13 +25,21 @@ class Manifest(object): self.parse() def load(self): - """Loads the manifest. - This function not only reads the manifest but also loads the specified provider and plugins. - Once they are loaded, the initialize() function is called on each of them (if it exists). + """Loads the manifest and performs a basic validation. + This function reads the manifest, loads the specified provider and plugins, and performs + some basic validation of the manifest itself to ensure that the properties + required for initalization are accessible + (otherwise the user would be presented with some cryptic error messages). + Once the provider and plugins are loaded, + the initialize() function is called on each of them (if it exists). The provider must have an initialize function. """ self.data = load_data(self.path) + from . import validate_manifest + # Validate the manifest with the base validation function in __init__ + validate_manifest(self.data, self.schema_validator, self.validation_error) + # Get the provider name from the manifest and load the corresponding module provider_modname = 'bootstrapvz.providers.' + self.data['provider']['name'] log.debug('Loading provider ' + provider_modname) @@ -57,12 +65,9 @@ class Manifest(object): init() def validate(self): - """Validates the manifest using the base, provider and plugin validation functions. + """Validates the manifest using the provider and plugin validation functions. Plugins are not required to have a validate_manifest function """ - from . import validate_manifest - # Validate the manifest with the base validation function in __init__ - validate_manifest(self.data, self.schema_validator, self.validation_error) # Run the provider validation self.modules['provider'].validate_manifest(self.data, self.schema_validator, self.validation_error)