From: Frank Brehm Date: Thu, 26 Jan 2017 11:16:47 +0000 (+0100) Subject: Changing output X-Git-Tag: 0.8.4~49 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=f033ca5f07bc77573c699db92dd866f4cd0b95b1;p=pixelpark%2Fpuppetmaster-webhooks.git Changing output --- diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 66a3581..81dc5b0 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -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) # =============================================================================