From: Frank Brehm Date: Fri, 24 Aug 2018 15:33:51 +0000 (+0200) Subject: Evaluating content of cache file. X-Git-Tag: 0.10.7^2~7 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=2f5247be7ce79e2ada481c17f9306165a1aa1a47;p=pixelpark%2Fpuppetmaster-webhooks.git Evaluating content of cache file. --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index c960ac6..2aac0a9 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.10.2' +__version__ = '0.10.3' # vim: ts=4 et list diff --git a/lib/webhooks/module_info.py b/lib/webhooks/module_info.py index bddaa02..1d669bf 100644 --- a/lib/webhooks/module_info.py +++ b/lib/webhooks/module_info.py @@ -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): diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 1ed6bed..5822d74 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -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))