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). The provider must have an initialize function. """ # Load the manifest JSON using the loader in common.tools # It strips comments (which are invalid in strict json) before loading the data. self.data = load_json(self.path) # Get the provider name from the manifest and load the corresponding module provider_modname = 'bootstrapvz.providers.{provider}'.format(provider=self.data['provider']) log.debug('Loading provider `{modname}\''.format(modname=provider_modname)) # Create a modules dict that contains the loaded provider and plugins self.modules = {'provider': __import__(provider_modname, fromlist=['providers']), 'plugins': [], } # Run through all the plugins mentioned in the manifest and load them if 'plugins' in self.data: for plugin_name, plugin_data in self.data['plugins'].iteritems(): modname = 'bootstrapvz.plugins.{plugin}'.format(plugin=plugin_name) log.debug('Loading plugin `{modname}\''.format(modname=modname)) plugin = __import__(modname, fromlist=['plugins']) self.modules['plugins'].append(plugin) # Run the initialize function on the provider and plugins self.modules['provider'].initialize() for module in self.modules['plugins']: # Plugins are not required to have an initialize function init = getattr(module, 'initialize', None) if callable(init): init()
def schema_validator(self, data, schema_path): """This convenience function is passed around to all the validation functions so that they may run a json-schema validation by giving it the data and a path to the schema. :param dict data: Data to validate (normally the manifest data) :param str schema_path: Path to the json-schema to use for validation """ import jsonschema schema = load_json(schema_path) try: jsonschema.validate(data, schema) except jsonschema.ValidationError as e: self.validation_error(e.message, e.path)
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). The provider must have an initialize function. """ # Load the manifest JSON using the loader in common.tools # It strips comments (which are invalid in strict json) before loading the data. if self.path.endswith('.json'): self.data = load_json(self.path) elif self.path.endswith('.yml') or self.path.endswith('.yaml'): self.data = load_yaml(self.path) # Get the provider name from the manifest and load the corresponding module provider_modname = 'bootstrapvz.providers.' + self.data['provider'] log.debug('Loading provider ' + provider_modname) # Create a modules dict that contains the loaded provider and plugins import importlib self.modules = { 'provider': importlib.import_module(provider_modname), 'plugins': [], } # Run through all the plugins mentioned in the manifest and load them if 'plugins' in self.data: for plugin_name, plugin_data in self.data['plugins'].iteritems(): modname = 'bootstrapvz.plugins.' + plugin_name log.debug('Loading plugin ' + modname) plugin = importlib.import_module(modname) self.modules['plugins'].append(plugin) # Run the initialize function on the provider and plugins self.modules['provider'].initialize() for module in self.modules['plugins']: # Plugins are not required to have an initialize function init = getattr(module, 'initialize', None) if callable(init): init()
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). The provider must have an initialize function. """ # Load the manifest JSON using the loader in common.tools # It strips comments (which are invalid in strict json) before loading the data. if self.path.endswith('.json'): self.data = load_json(self.path) elif self.path.endswith('.yml') or self.path.endswith('.yaml'): self.data = load_yaml(self.path) # Get the provider name from the manifest and load the corresponding module provider_modname = 'bootstrapvz.providers.' + self.data['provider'] log.debug('Loading provider ' + provider_modname) # Create a modules dict that contains the loaded provider and plugins import importlib self.modules = {'provider': importlib.import_module(provider_modname), 'plugins': [], } # Run through all the plugins mentioned in the manifest and load them if 'plugins' in self.data: for plugin_name, plugin_data in self.data['plugins'].iteritems(): modname = 'bootstrapvz.plugins.' + plugin_name log.debug('Loading plugin ' + modname) plugin = importlib.import_module(modname) self.modules['plugins'].append(plugin) # Run the initialize function on the provider and plugins self.modules['provider'].initialize() for module in self.modules['plugins']: # Plugins are not required to have an initialize function init = getattr(module, 'initialize', None) if callable(init): init()