]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Creating HTML table
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:50:49 +0000 (14:50 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Aug 2018 12:50:49 +0000 (14:50 +0200)
lib/webhooks/__init__.py
lib/webhooks/show_modules.py

index 8c0b94313db1f0f55446eb09e307fd0d7713b0b6..79baaa97890d73a4add6643c16143432da7ddc07 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '0.10.5'
+__version__ = '0.10.6'
 
 # vim: ts=4 et list
index f093e28d7cb603bd0d9f2f46d6a79de5fc915930..e8d8cfaa56d45ac7da9a8fc360121c4b6ef036de 100644 (file)
@@ -150,6 +150,8 @@ class ShowModulesApp(BaseHookApp):
 
         if self.output_type == 'json':
             self.output_modules_json(module_infos)
+        elif self.output_type == 'html':
+            self.output_modules_html(module_infos)
 
     # -------------------------------------------------------------------------
     def output_modules_json(self, module_infos):
@@ -165,6 +167,63 @@ class ShowModulesApp(BaseHookApp):
 
         self.print_out(json.dumps(output_list, indent=indent, sort_keys=True))
 
+    # -------------------------------------------------------------------------
+    def output_modules_html(self, module_infos):
+
+        self.print_out('<table>')
+        self.print_out('  <colgroup span="9"></colgroup>')
+        self.print_out('  <thead>')
+        self.print_out('    <tr>')
+        self.print_out('      <th rowspan="2">Name</th>')
+        self.print_out('      <th rowspan="2">Vollständiger Name</th>')
+        self.print_out('      <th rowspan="2">Repository</th>')
+        self.print_out('      <th rowspan="2">Homepage bei Puppet Forge</th>')
+        self.print_out('      <th colspan="4">Version</th>')
+        self.print_out('      <th rowspan="2">Letzter Check</th>')
+        self.print_out('    </tr><tr>')
+        self.print_out('      <th>Puppet Forge</th>')
+        self.print_out('      <th>Development</th>')
+        self.print_out('      <th>Test</th>')
+        self.print_out('      <th>Production</th>')
+        self.print_out('    </tr>')
+        self.print_out('  </thead>')
+        self.print_out('  <tbody>')
+
+        nr_modules = 0
+
+        for module_info in module_infos:
+            nr_modules += 1
+            output_data = self.get_output_data(module_info)
+            if not output_data['forge_version']:
+                output_data['forge_version'] = '~'
+            if not output_data['forge_homepage_url']:
+                output_data['forge_homepage_url'] = '~'
+            if not output_data['repo']:
+                output_data['repo'] = '~'
+            tpl = '    <tr>\n'
+            tpl += '      <th>{name}</th>\n'
+            tpl += '      <td>{full_name}</td>\n'
+            tpl += '      <td>{repo}</td>\n'
+            tpl += '      <td>{forge_homepage_url}</td>\n'
+            tpl += '      <td>{forge_version}</td>\n'
+            tpl += '      <td>{version_development}</td>\n'
+            tpl += '      <td>{version_test}</td>\n'
+            tpl += '      <td>{version_production}</td>\n'
+            tpl += '      <td>{date_checked}</td>\n'
+            tpl += '    </tr>'
+            if self.verbose > 2:
+                LOG.debug("Row template:\n{}".format(tpl))
+            self.print_out(tpl.format(**output_data))
+
+        self.print_out("  </tbody>")
+        self.print_out("</table>")
+
+        plural_e = 'e'
+        if nr_modules == 1:
+            plural_e = ''
+        msg = "<br/>Insgesamt <b>{nr} Modul{e}</b> gefunden.".format(nr=nr_modules, e=plural_e)
+        self.print_out(msg)
+
     # -------------------------------------------------------------------------
     def get_output_data(self, module_info):
 
@@ -188,6 +247,8 @@ class ShowModulesApp(BaseHookApp):
             'version_test': module_info.local_version_output('test'),
             'version_production': module_info.local_version_output('production'),
         }
+        if self.verbose > 2:
+            LOG.debug("Output data:\n{}".format(pp(output_data)))
         return output_data
 
     # -------------------------------------------------------------------------