]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Evaluating content of cache file.
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 24 Aug 2018 15:33:51 +0000 (17:33 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 24 Aug 2018 15:33:51 +0000 (17:33 +0200)
lib/webhooks/__init__.py
lib/webhooks/module_info.py
lib/webhooks/show_modules.py

index c960ac60c0717cf4203034c069946f7a47b51806..2aac0a99f51f64d456f41d9119ab64df0588f302 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.10.2'
+__version__ = '0.10.3'
 
 # vim: ts=4 et list
index bddaa02cf5c2bc8da8ba89d05292e6d2278f92bb..1d669bf4a68c76a14a52ac8b93f309ac9078397a 100644 (file)
@@ -26,7 +26,7 @@ from .common import pp, to_str, to_bool, is_sequence
 from .obj import BaseObjectError
 from .obj import BaseObject
 
-__version__ = '0.5.1'
+__version__ = '0.6.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -362,6 +362,61 @@ class ModuleInfo(BaseObject):
 
         return module_info
 
+    # -------------------------------------------------------------------------
+    @classmethod
+    def init_from_data(cls, data, appname=None, verbose=0, base_dir=None):
+        """Reverse method of to_data()."""
+
+        if verbose > 3:
+            LOG.debug("Trying to init module_info from:\n{}".format(pp(data)))
+
+        if 'full_name' not in data:
+            LOG.warn("Did not found module name in data.")
+            return None
+
+        module_info = None
+
+        try:
+            module_info = cls(
+                appname=appname, verbose=verbose, base_dir=base_dir,
+                full_name=data['full_name'],
+            )
+        except ModuleInfoError as e:
+            LOG.warn("{c}: {e}".format(c=e.__class__.__name__, e=e))
+            return None
+
+        if 'full_name_orig' in data:
+            module_info._full_name_orig = data['full_name_orig']
+
+        if 'forge_version' in data:
+            module_info.forge_version = data['forge_version']
+
+        if 'forge_avail' in data:
+            module_info._full_name_orig = data['forge_avail']
+
+        if 'forge_homepage_url' in data:
+            module_info.forge_homepage_url = data['forge_homepage_url']
+
+        if 'forge_source' in data:
+            module_info.forge_source = data['forge_source']
+
+        if 'repo' in data:
+            module_info.repo = data['repo']
+
+        if 'ts_checked' in data:
+            module_info.ts_checked = data['ts_checked']
+
+        if 'local_versions' in data:
+            module_info.local_versions = copy.copy(data['local_versions'])
+
+        if 'expected_versions' in data:
+            module_info.expected_versions = copy.copy(data['expected_versions'])
+
+        if 'forge_releases' in data:
+            module_info.forge_releases = copy.copy(data['forge_releases'])
+
+        return module_info
+
     # -------------------------------------------------------------------------
     @classmethod
     def init_from_puppetfile_line(cls, line, env, appname=None, verbose=0, base_dir=None):
index 1ed6bed21192528ae58147988895c28210e3780f..5822d7427c6adfe118942a2f8f9244925d6bdb02 100644 (file)
@@ -138,8 +138,12 @@ class ShowModulesApp(BaseHookApp):
         LOG.debug("Reading {!r} ...".format(self.cache_file))
         try:
             with open(self.cache_file, 'r', **self.open_args) as fh:
-                for struct in yaml.load_all(fh):
-                    data.append(struct)
+                for struct in yaml.load(fh):
+                    module_info = ModuleInfo.init_from_data(
+                        struct, appname=self.appname, verbose=self.verbose,
+                        base_dir=self.base_dir)
+                    if module_info:
+                        data.append(module_info)
         except yaml.YAMLError as e:
             raise ShowModulesUncriticalError(
                 "Could not evaluate content of {f!r}: {e}".format(f=self.cache_file, e=e))