]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Changing output
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 26 Jan 2017 11:16:47 +0000 (12:16 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 26 Jan 2017 11:16:47 +0000 (12:16 +0100)
lib/webhooks/deploy.py

index 66a35811442c4a1ba05a08ed3c2ed4b74463aeb6..81dc5b070e7e14e0d30f3339c749c75cea5994d0 100644 (file)
@@ -361,6 +361,15 @@ class WebhookDeployApp(object):
 
         return
 
+    # -------------------------------------------------------------------------
+    def print_out(self, *objects, sep=' ', end='\n', file=sys.stdout.buffer, flush=True):
+
+        file.write(to_bytes(sep.join(map(lambda x: str(x), objects))))
+        if end:
+            file.write(to_bytes(end))
+        if flush:
+            file.flush()
+
     # -------------------------------------------------------------------------
     def __call__(self):
         """Helper method to make the resulting object callable."""
@@ -420,9 +429,12 @@ class WebhookDeployApp(object):
             'user_name': 'Frank Brehm'}
         """
 
-        print("Content-Type: text/plain;charset=utf-8")
-        print()
-        sys.stdout.buffer.write(to_bytes("Python CGI läuft.\n"))
+        #print("Content-Type: text/plain;charset=utf-8")
+        #print()
+        #sys.stdout.buffer.write(to_bytes("Python CGI läuft.\n"))
+        #sys.stdout.flush()
+        self.print_out("Content-Type: text/plain;charset=utf-8\n")
+        self.print_out("Python CGI läuft.\n")
 
         LOG.info("Starting ...")
         LOG.debug("Base directory: {!r}".format(self.base_dir))
@@ -445,6 +457,7 @@ class WebhookDeployApp(object):
                 n=e.__class__.__name__, e=e))
             LOG.error("Traceback:\n{}".format(traceback.format_exc()))
 
+        LOG.info("Finished.")
         sys.exit(0)
 
     # -------------------------------------------------------------------------
@@ -592,11 +605,15 @@ class WebhookDeployApp(object):
 
         LOG.debug("Return value: {}".format(ret_val))
         if stdoutdata:
-            LOG.debug("Output:\n{}".format(to_str(stdoutdata)))
+            msg = "Output:\n{}".format(to_str(stdoutdata))
+            LOG.debug(msg)
+            self.print_out(msg)
         else:
             LOG.debug("No output.")
         if stderrdata:
-            LOG.warn("Error messages on '{c}': {e}".format(c=cmd_str, e=to_str(stderrdata)))
+            msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata))
+            LOG.warn(msg)
+            self.print_out(msg)
 
 # =============================================================================