From: Frank Brehm Date: Fri, 4 Oct 2019 14:26:56 +0000 (+0200) Subject: Retrieving list of modules, which were updated a longer time ago. X-Git-Tag: 1.7.4~1^2~4 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=fa8e8094281fc7d84a4543516c1c92aac7cb6a16;p=pixelpark%2Fpuppetmaster-webhooks.git Retrieving list of modules, which were updated a longer time ago. --- diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py index 086c4a5..732e7a2 100644 --- a/lib/webhooks/get_module_changes.py +++ b/lib/webhooks/get_module_changes.py @@ -19,7 +19,7 @@ from numbers import Number from distutils.version import LooseVersion # Third party modules -from babel.dates import format_datetime, LOCALTZ +from babel.dates import format_datetime, format_timedelta, LOCALTZ # Own modules from fb_tools.common import pp, to_bool @@ -288,6 +288,8 @@ class GetModuleChangesApp(BaseHookApp): depr_infos = self.check_deprecations(module_infos) self.generate_deprecation_msgs(depr_infos) + update_infos = self.check_updates(module_infos) + self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str)) # ------------------------------------------------------------------------- @@ -535,6 +537,67 @@ class GetModuleChangesApp(BaseHookApp): for info in module_infos: self.error_data.append(template.format(**info)) + # ------------------------------------------------------------------------- + def check_updates(self, module_infos): + + env_found = False + + LOG.info(_("Checking for last updets modules on Puppet forge ...")) + + infos = [] + + warn_update_timediff = datetime.timedelta(self.warn_update_days) + + for module_info in module_infos.values(): + + if self.verbose > 1: + LOG.debug("Checking module {!r} ...".format(module_info.full_name)) + + if self.environment not in module_info.local_versions: + LOG.debug("Module {m!r} not used in environment {e!r}.".format( + m=module_info.full_name, e=self.environment)) + continue + env_found = True + + if not module_info.forge_avail or not module_info.forge_version: + LOG.debug("Module {m!r} not available on Puppet forge.".format( + m=module_info.full_name)) + continue + + if not module_info.forge_updated_at: + LOG.debug("Did not found last update_date of module {m!r}.".format( + m=module_info.full_name)) + continue + + mod_update_timediff = self.check_date - module_info.forge_updated_at + tdiff = format_timedelta( + mod_update_timediff * -1, granularity='day', add_direction=True, + format='long') + if self.verbose > 1: + LOG.debug("Last update of module {m!r} was {d} days ago ({t}).".format( + m=module_info.full_name, d=mod_update_timediff.days, t=tdiff)) + + if mod_update_timediff < warn_update_timediff: + continue + + local_dt_str = format_datetime( + module_info.forge_updated_at, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ) + LOG.info(_( + "Module {m!r} was last updated at {at}, {d} days ago ({t}).").format( + m=module_info.full_name, at=local_dt_str, d=mod_update_timediff.days, t=tdiff)) + + info = { + 'module': module_info.full_name, + 'upd_date': module_info.forge_updated_at, + 'upd_date_str': local_dt_str, + 'timediff': mod_update_timediff, + } + infos.append(info) + + if self.verbose > 1: + LOG.debug("Modules with an update on Forge long time ago:\n" + pp(infos)) + return infos + # ============================================================================= if __name__ == "__main__":