]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Minor changes on JSON output
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:20:23 +0000 (14:20 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:20:23 +0000 (14:20 +0200)
lib/webhooks/__init__.py
lib/webhooks/show_modules.py

index c64d4701e1a2a5f7f789225a5d32c937ad962eb2..8c0b94313db1f0f55446eb09e307fd0d7713b0b6 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.10.4'
+__version__ = '0.10.5'
 
 # vim: ts=4 et list
index 8b360ab05212df7d645fb4056a65c27c46d2282c..f093e28d7cb603bd0d9f2f46d6a79de5fc915930 100644 (file)
@@ -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):