From 1cd47a0ad68ee7a91d886cd899092665965e9e6b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 19 Mar 2019 15:33:07 +0100 Subject: [PATCH] Complete reading in cache file for forge modules --- lib/webhooks/module_info.py | 59 ++++++++++++++++++++++++++++++++++-- lib/webhooks/show_modules.py | 48 ++++++++++++++++++++++++----- 2 files changed, 96 insertions(+), 11 deletions(-) diff --git a/lib/webhooks/module_info.py b/lib/webhooks/module_info.py index e15f95e..00447c1 100644 --- a/lib/webhooks/module_info.py +++ b/lib/webhooks/module_info.py @@ -72,6 +72,9 @@ class ModuleInfo(BaseModuleInfo): self._forge_homepage_url = None self._forge_source = None self._ts_checked = None + self._forge_deprecated_at = None + self._forge_deprecated_for = None + self._forge_superseded_by = None super(ModuleInfo, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -139,6 +142,50 @@ class ModuleInfo(BaseModuleInfo): return self._forge_avail = to_bool(value) + # ------------------------------------------------------------------------- + @property + def forge_deprecated_at(self): + """Date of deprecation on Puppet forge.""" + return self._forge_deprecated_at + + @forge_deprecated_at.setter + def forge_deprecated_at(self, value): + self._forge_deprecated_at = value + + # ------------------------------------------------------------------------- + @property + def forge_deprecated_for(self): + """The reason of deprecation of this forge module.""" + return self._forge_deprecated_for + + @forge_deprecated_for.setter + def forge_deprecated_for(self, value): + if value is None: + self._forge_deprecated_for = None + return + v = str(value).strip() + if v == '': + self._forge_deprecated_for = None + return + self._forge_deprecated_for = v + + # ------------------------------------------------------------------------- + @property + def forge_superseded_by(self): + """The reason of deprecation of this forge module.""" + return self._forge_superseded_by + + @forge_superseded_by.setter + def forge_superseded_by(self, value): + if value is None: + self._forge_superseded_by = None + return + v = str(value).strip() + if v == '': + self._forge_superseded_by = None + return + self._forge_superseded_by = v + # ------------------------------------------------------------------------- @property def ts_checked(self): @@ -197,12 +244,15 @@ class ModuleInfo(BaseModuleInfo): res = super(ModuleInfo, self).as_dict(short=short) - res['forge_version'] = self.forge_version + res['date_checked'] = self.date_checked res['forge_avail'] = self.forge_avail + res['forge_deprecated_at'] = self.forge_deprecated_at + res['forge_deprecated_for'] = self.forge_deprecated_for res['forge_homepage_url'] = self.forge_homepage_url res['forge_source'] = self.forge_source + res['forge_superseded_by'] = self.forge_superseded_by + res['forge_version'] = self.forge_version res['ts_checked'] = self.ts_checked - res['date_checked'] = self.date_checked return res @@ -212,10 +262,13 @@ class ModuleInfo(BaseModuleInfo): res = super(ModuleInfo, self).to_data() - res['forge_version'] = self.forge_version res['forge_avail'] = self.forge_avail + res['forge_deprecated_at'] = self.forge_deprecated_at + res['forge_deprecated_for'] = self.forge_deprecated_for res['forge_homepage_url'] = self.forge_homepage_url res['forge_source'] = self.forge_source + res['forge_superseded_by'] = self.forge_superseded_by + res['forge_version'] = self.forge_version res['repo'] = self.repo res['ts_checked'] = self.ts_checked diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 40cc33a..090c174 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -24,6 +24,7 @@ from . import __version__ from .errors import BaseHookError, UncriticalHookError from .base_app import BaseHookApp +from .module_list import ModuleInfoDict from .forge.mod_dict import ForgeModuleDictError from .xlate import XLATOR @@ -197,15 +198,46 @@ class ShowModulesApp(BaseHookApp): if not self.read_forge_cache(): self.exit(7) return - return - module_infos = [] - try: - module_infos = self.read_cache_file() - except UncriticalHookError as e: - LOG.error(str(e)) - else: - self.output_modules(module_infos) + exposed_modules = ModuleInfoDict( + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, + sort_by_name=self.sort_by_name) + + for env in self.env_modules.keys(): + if str(env) not in self.main_branches: + continue + for module_name in self.env_modules[env].keys(): + mod = self.env_modules[env][module_name] + exposed_modules.merge(mod) + + for m_name in exposed_modules.keys(): + module_name = str(m_name) + if module_name in self.forge_modules: + forge_mod = self.forge_modules[module_name] + exposed_modules[m_name].forge_avail = True + if forge_mod.current_release: + f_version = forge_mod.current_release.release_version + exposed_modules[m_name].forge_version = f_version + if forge_mod.current_release.metadata: + s_url = forge_mod.current_release.metadata.source + exposed_modules[m_name].forge_source = s_url + exposed_modules[m_name].forge_homepage_url = forge_mod.homepage_url + exposed_modules[m_name].ts_checked = forge_mod.ts_checked + exposed_modules[m_name].forge_deprecated_at = forge_mod.deprecated_at + exposed_modules[m_name].forge_deprecated_for = forge_mod.deprecated_for + if forge_mod.superseded_by and forge_mod.superseded_by['slug']: + subst = forge_mod.superseded_by['slug'] + exposed_modules[m_name].forge_superseded_by = subst + + if self.verbose > 1: + LOG.debug(_("Modules to show:") + '\n' + pp(exposed_modules.as_list())) + +# try: +# module_infos = self.read_cache_file() +# except UncriticalHookError as e: +# LOG.error(str(e)) +# else: +# self.output_modules(module_infos) # ------------------------------------------------------------------------- def read_forge_cache(self): -- 2.39.5