From: Frank Brehm Date: Tue, 19 Mar 2019 16:50:32 +0000 (+0100) Subject: Changed lib/webhooks/get_module_changes.py to use new objects X-Git-Tag: 1.6.4^2~9 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=0ce3d7d800be7d462fb481f2ec75d34933c63bef;p=pixelpark%2Fpuppetmaster-webhooks.git Changed lib/webhooks/get_module_changes.py to use new objects --- diff --git a/lib/webhooks/base_app.py b/lib/webhooks/base_app.py index ddcfed4..78d5be4 100644 --- a/lib/webhooks/base_app.py +++ b/lib/webhooks/base_app.py @@ -52,7 +52,7 @@ from .puppetfile import PuppetfileError, Puppetfile from .module_meta_info import ModuleMetadata -from .forge.mod_dict import ForgeModuleDict +from .forge.mod_dict import ForgeModuleDict, ForgeModuleDictError from .xlate import __module_dir__ as __xlate_module_dir__ from .xlate import __base_dir__ as __xlate_base_dir__ @@ -1403,6 +1403,63 @@ class BaseHookApp(BaseApplication): return ModuleInfo.init_from_json( json_data, env, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir) + # ------------------------------------------------------------------------- + def read_all_module_infos(self, only_main_branches=False): + + self.init_puppet_environments() + self.collect_local_modules() + + if not self.read_forge_cache(): + self.exit(7) + return + + module_infos = 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 only_main_branches and str(env) not in self.main_branches: + continue + for module_name in self.env_modules[env].keys(): + mod = self.env_modules[env][module_name] + module_infos.merge(mod) + + for m_name in module_infos.keys(): + module_name = str(m_name) + if module_name in self.forge_modules: + forge_mod = self.forge_modules[module_name] + module_infos[m_name].forge_avail = True + if forge_mod.current_release: + f_version = forge_mod.current_release.release_version + module_infos[m_name].forge_version = f_version + if forge_mod.current_release.metadata: + s_url = forge_mod.current_release.metadata.source + module_infos[m_name].forge_source = s_url + module_infos[m_name].forge_homepage_url = forge_mod.homepage_url + module_infos[m_name].ts_checked = forge_mod.ts_checked + module_infos[m_name].forge_deprecated_at = forge_mod.deprecated_at + module_infos[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'] + module_infos[m_name].forge_superseded_by = subst + + if self.verbose > 2: + LOG.debug(_("All modules infos:") + '\n' + pp(module_infos.as_list())) + + return module_infos + + # ------------------------------------------------------------------------- + def read_forge_cache(self): + + self.init_forge_module_dict() + try: + self.forge_modules.read_file() + except ForgeModuleDictError as e: + LOG.error(_("Got a {cn} reading input data as JSON: {e}").format( + cn=e.__class__.__name__, e=e)) + return False + return True + # ============================================================================= if __name__ == "__main__": diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py index 8d50419..dd8063e 100644 --- a/lib/webhooks/get_module_changes.py +++ b/lib/webhooks/get_module_changes.py @@ -162,7 +162,7 @@ class GetModuleChangesApp(BaseHookApp): LOG.info(_("Here I go. ...")) module_infos = [] try: - module_infos = self.read_cache_file(only_main_branches=False) + module_infos = self.read_all_module_infos() except UncriticalHookError as e: LOG.error(str(e)) self.exit(7) diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index c514ae8..c4fad23 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -192,59 +192,8 @@ class ShowModulesApp(BaseHookApp): self.print_out("#" * len_title) self.print_out('') - self.init_puppet_environments() - self.collect_local_modules() - - if not self.read_forge_cache(): - self.exit(7) - return - - 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 > 2: - LOG.debug(_("Modules to show:") + '\n' + pp(exposed_modules.as_list())) - - self.output_modules(exposed_modules) - - # ------------------------------------------------------------------------- - def read_forge_cache(self): - - self.init_forge_module_dict() - try: - self.forge_modules.read_file() - except ForgeModuleDictError as e: - LOG.error(_("Got a {cn} reading input data as JSON: {e}").format( - cn=e.__class__.__name__, e=e)) - return False - return True + module_infos = self.read_all_module_infos(only_main_branches=True) + self.output_modules(module_infos) # ------------------------------------------------------------------------- def output_modules(self, module_infos):