From 39ae4f5d4e99f83f1098bc62ab78c1695d6c358a Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 4 Sep 2018 17:51:51 +0200 Subject: [PATCH] Using lib/webhooks/module_list.py in lib/webhooks/show_modules.py --- lib/webhooks/__init__.py | 2 +- lib/webhooks/module_list.py | 4 ++-- lib/webhooks/show_modules.py | 28 ++++++++++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index ea0a12e..b8c85cc 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.11.1' +__version__ = '0.11.2' # vim: ts=4 et list diff --git a/lib/webhooks/module_list.py b/lib/webhooks/module_list.py index 362c0da..b07d236 100644 --- a/lib/webhooks/module_list.py +++ b/lib/webhooks/module_list.py @@ -32,7 +32,7 @@ from .obj import BaseObject from .module_info import ModuleInfo -__version__ = '0.1.1' +__version__ = '0.1.2' LOG = logging.getLogger(__name__) @@ -85,7 +85,7 @@ class ModuleInfoDict(MutableMapping, BaseObject): if not isinstance(module_info, ModuleInfo): raise TypeError(self.msg_invalid_modinfo_type.format(module_info.__class__.__name__)) - self._set_item(module_info.name, module_info) + self._set_item(module_info.full_name, module_info) # ------------------------------------------------------------------------- def as_dict(self, short=True): diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 633bc7e..0a29a95 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -31,6 +31,8 @@ from .base_app import BaseHookError, BaseHookApp from .module_info import ModuleInfo +from .module_list import ModuleInfoDict + LOG = logging.getLogger(__name__) DEFAULT_PARENT_DIR = '/etc/puppetlabs/code/fileserver' @@ -205,7 +207,8 @@ class ShowModulesApp(BaseHookApp): def output_modules_json(self, module_infos): output_list = [] - for module_info in module_infos: + for full_name in module_infos.keys(): + module_info = module_infos[full_name] output_data = self.get_output_data(module_info) output_list.append(output_data) @@ -218,7 +221,7 @@ class ShowModulesApp(BaseHookApp): # ------------------------------------------------------------------------- def output_modules_html(self, module_infos): - if not module_infos: + if not len(module_infos): self.print_out() self.print_out('

Keine passenden Module gefunden.

') self.print_out() @@ -247,7 +250,8 @@ class ShowModulesApp(BaseHookApp): line_class = 'even' - for module_info in module_infos: + for full_name in module_infos.keys(): + module_info = module_infos[full_name] nr_modules += 1 if nr_modules % 2: line_class = 'odd' @@ -320,7 +324,8 @@ class ShowModulesApp(BaseHookApp): nr_modules = 0 - for module_info in module_infos: + for full_name in module_infos.keys(): + module_info = module_infos[full_name] nr_modules += 1 output_data = self.get_output_data(module_info) for key in label.keys(): @@ -357,7 +362,8 @@ class ShowModulesApp(BaseHookApp): self.print_out(header) self.print_out('=' * len(header)) - for module_info in module_infos: + for full_name in module_infos.keys(): + module_info = module_infos[full_name] nr_modules += 1 output_data = self.get_output_data(module_info) if not output_data['forge_version']: @@ -409,7 +415,9 @@ class ShowModulesApp(BaseHookApp): raise ShowModulesUncriticalError( "Cache file {!r} not readable.".format(self.cache_file)) - data = [] + modules = ModuleInfoDict( + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir) + LOG.debug("Reading {!r} ...".format(self.cache_file)) try: with open(self.cache_file, 'r', **self.open_args) as fh: @@ -432,16 +440,16 @@ class ShowModulesApp(BaseHookApp): if not in_main_branches: continue if self.should_display(module_info): - data.append(module_info) + modules.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)) if self.verbose > 3: - LOG.debug("Content of {f!r}:\n{c}".format(f=self.cache_file, c=pp(data))) - if not data: + LOG.debug("Content of {f!r}:\n{c}".format(f=self.cache_file, c=pp(modules.as_list()))) + if not len(modules): LOG.debug("Did not found any matching modules.") - return data + return modules # ------------------------------------------------------------------------- def should_display(self, module_info): -- 2.39.5