From: Frank Brehm Date: Fri, 4 Jan 2019 16:01:19 +0000 (+0100) Subject: Using class ModuleDependency for a list of requirements in ModuleMetadata X-Git-Tag: 1.6.4^2~69 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=12f2b29ec4e6a7c1bfbad35487cce8acceb78123;p=pixelpark%2Fpuppetmaster-webhooks.git Using class ModuleDependency for a list of requirements in ModuleMetadata --- diff --git a/lib/webhooks/module_meta_info.py b/lib/webhooks/module_meta_info.py index 98c3f7e..ce56bee 100644 --- a/lib/webhooks/module_meta_info.py +++ b/lib/webhooks/module_meta_info.py @@ -27,7 +27,7 @@ from fb_tools.obj import FbBaseObjectError, FbBaseObject from .xlate import XLATOR -__version__ = '0.3.1' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) @@ -105,6 +105,7 @@ class ModuleMetadata(FbBaseObject): self._summary = None self._source = None self.dependencies = [] + self.requirements = [] super(ModuleMetadata, self).__init__( appname=appname, verbose=verbose, version=version, @@ -213,6 +214,9 @@ class ModuleMetadata(FbBaseObject): res['dependencies'] = [] for dep in self.dependencies: res['dependencies'].append(dep.as_dict()) + res['requirements'] = [] + for req in self.requirements: + res['requirements'].append(req.as_dict()) return res @@ -240,9 +244,14 @@ class ModuleMetadata(FbBaseObject): raise MetadataInitError(msg) if not is_sequence(json_data['dependencies']): - msg = _("Invalid dependencies - not a list.") + msg = _("Invalid item {} - not a list.").format('dependencies') raise MetadataInitError(msg) + if 'requirements' in json_data: + if not is_sequence(json_data['requirements']): + msg = _("Invalid item {} - not a list.").format('requirements') + raise MetadataInitError(msg) + metadata = cls(appname=appname, verbose=verbose, base_dir=base_dir) metadata.name = json_data['name'] @@ -257,6 +266,10 @@ class ModuleMetadata(FbBaseObject): for item in json_data['dependencies']: dep = ModuleDependency.from_data(item) metadata.dependencies.append(dep) + if 'requirements' in json_data: + for item in json_data['requirements']: + req = ModuleDependency.from_data(item) + metadata.requirements.append(req) metadata.initialized = True if verbose > 3: @@ -277,6 +290,8 @@ class ModuleMetadata(FbBaseObject): new.source = self.source for dep in self.dependencies: new.dependencies.append(copy.copy(dep)) + for req in self.requirements: + new.requirements.append(copy.copy(req)) new.initialized = True @@ -295,6 +310,10 @@ class ModuleMetadata(FbBaseObject): data['dependencies'] = [] for dep in self.dependencies: data['dependencies'].append(dep.to_data()) + if self.requirements: + data['requirements'] = [] + for req in self.requirements: + data['requirements'].append(req.to_data()) if self.verbose > 4: LOG.debug("ModuleMetadata:\n{}".format(pp(data)))