From: Frank Brehm Date: Mon, 27 Aug 2018 12:20:23 +0000 (+0200) Subject: Minor changes on JSON output X-Git-Tag: 0.10.7^2~2 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=04dc90914ba5b7eaf2a0802a9a0974d6483285fc;p=pixelpark%2Fpuppetmaster-webhooks.git Minor changes on JSON output --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index c64d470..8c0b943 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '0.10.4' +__version__ = '0.10.5' # vim: ts=4 et list diff --git a/lib/webhooks/show_modules.py b/lib/webhooks/show_modules.py index 8b360ab..f093e28 100644 --- a/lib/webhooks/show_modules.py +++ b/lib/webhooks/show_modules.py @@ -156,28 +156,39 @@ class ShowModulesApp(BaseHookApp): output_list = [] for module_info in module_infos: - if module_info.ts_checked: - date_checked = datetime.datetime.fromtimestamp( - module_info.ts_checked, self.tz).strftime('%Y-%m-%d %H:%M:%S %Z') - else: - date_checked = None - data = { - 'name': module_info.name, - 'vendor': module_info.vendor, - 'full_name': module_info.full_name, - 'forge_version': module_info.forge_version, - 'forge_avail': module_info.forge_avail, - 'forge_homepage_url': module_info.forge_homepage_url, - 'repo': module_info.repo, - 'ts_checked': module_info.ts_checked, - 'date_checked': date_checked, - 'version_development': module_info.local_version_output('development'), - 'version_test': module_info.local_version_output('test'), - 'version_production': module_info.local_version_output('production'), - } - output_list.append(data) - - self.print_out(json.dumps(output_list)) + output_data = self.get_output_data(module_info) + output_list.append(output_data) + + indent = None + if self.verbose: + indent = 4 + + self.print_out(json.dumps(output_list, indent=indent, sort_keys=True)) + + # ------------------------------------------------------------------------- + def get_output_data(self, module_info): + + if module_info.ts_checked: + date_checked = datetime.datetime.fromtimestamp( + module_info.ts_checked, self.tz).strftime('%Y-%m-%d %H:%M:%S %Z') + else: + date_checked = None + + output_data = { + 'name': module_info.name, + 'vendor': module_info.vendor, + 'full_name': module_info.full_name, + 'forge_version': module_info.forge_version, + 'forge_avail': module_info.forge_avail, + 'forge_homepage_url': module_info.forge_homepage_url, + 'repo': module_info.repo, + 'ts_checked': module_info.ts_checked, + 'date_checked': date_checked, + 'version_development': module_info.local_version_output('development'), + 'version_test': module_info.local_version_output('test'), + 'version_production': module_info.local_version_output('production'), + } + return output_data # ------------------------------------------------------------------------- def read_cache_file(self):