From d0230378ea3184a59110e968ee9d98efde1a4687 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 4 Oct 2019 11:29:06 +0200 Subject: [PATCH] Starting extending get-module-changes --- lib/webhooks/__init__.py | 2 +- lib/webhooks/get_module_changes.py | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 867247b..3b07309 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.6.5' +__version__ = '1.7.0' # vim: ts=4 et list diff --git a/lib/webhooks/get_module_changes.py b/lib/webhooks/get_module_changes.py index dd8063e..4dcff09 100644 --- a/lib/webhooks/get_module_changes.py +++ b/lib/webhooks/get_module_changes.py @@ -77,12 +77,16 @@ class GetModuleChangesApp(BaseHookApp): def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__): """Constructor.""" + self._check_date = None + description = _( "Generates a list of all Puppets modules, which are newer " "in Puppet forge than in a defined environment.") self._environment = self.default_env + self._check_date = datetime.datetime.now(LOCALTZ) + super(GetModuleChangesApp, self).__init__( appname=appname, base_dir=base_dir, verbose=verbose, version=version, no_cc=True, description=description) @@ -106,6 +110,20 @@ class GetModuleChangesApp(BaseHookApp): self._environment = val + # ----------------------------------------------------------- + @property + def check_date(self): + """The timestamp of the check as a datetime object.""" + return self._check_date + + # ----------------------------------------------------------- + @property + def check_date_str(self): + """The timestamp of the check as a string.""" + if self.check_date is None: + return None + return format_datetime(self.check_date, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ) + # ------------------------------------------------------------------------- def as_dict(self, short=True): """ @@ -117,6 +135,8 @@ class GetModuleChangesApp(BaseHookApp): res = super(GetModuleChangesApp, self).as_dict(short=short) + res['check_date'] = self.check_date + res['check_date_str'] = self.check_date_str res['default_env'] = self.default_env res['environment'] = self.environment @@ -170,6 +190,8 @@ class GetModuleChangesApp(BaseHookApp): version_infos = self.get_newer_modules(module_infos) self.generate_version_msgs(version_infos) + self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str)) + # ------------------------------------------------------------------------- def get_newer_modules(self, module_infos): @@ -243,15 +265,12 @@ class GetModuleChangesApp(BaseHookApp): "Results of checking for newer versions of Puppet modules " "in environment {!r}:").format(self.environment) - dt = datetime.datetime.now(LOCALTZ) - dt_str = format_datetime(dt, 'yyyy-MM-dd HH:mm:ss z', tzinfo=LOCALTZ) - if not version_infos: msg = _( "Didn't found any modules in environment {!r} with a\n" "newer version on Puppet Forge.").format(self.environment) + "\n\n:-D" self.error_data.append(msg) - self.error_data.append("\n" + _("Checked at: {}").format(dt_str)) + self.error_data.append("\n" + _("Checked at: {}").format(self.check_date_str)) return msg = ngettext( @@ -305,8 +324,6 @@ class GetModuleChangesApp(BaseHookApp): forge_version=str(version_info['forge_version']) )) - self.error_data.append("\n" + _("Checked at: {}").format(dt_str)) - # ============================================================================= if __name__ == "__main__": -- 2.39.5