]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Using class ModuleDependency for a list of requirements in ModuleMetadata
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 4 Jan 2019 16:01:19 +0000 (17:01 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 4 Jan 2019 16:01:19 +0000 (17:01 +0100)
lib/webhooks/module_meta_info.py

index 98c3f7e6937852fbf594777e7aae1d196ba59c0a..ce56beeb2ac6711a7d343e7ac1382cd46bea43a7 100644 (file)
@@ -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)))