From f0c377235ac054de80126cacb3accbd853d8672c Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 25 Jan 2017 11:03:11 +0100 Subject: [PATCH] Reading in data from STDIN --- lib/webhooks/deploy.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index 641d5ed..2f147f1 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -14,10 +14,12 @@ import logging import re import textwrap import datetime +import json # Own modules import webhooks +from webhooks.common import pp __version__ = webhooks.__version__ log = logging.getLogger(__name__) @@ -59,6 +61,9 @@ class WebhookDeployApp(object): @type: int """ + self.data = None + self.json_data = None + self._log_directory = os.sep + os.path.join('var', 'log', 'webhooks') self.init_logging() @@ -138,7 +143,7 @@ class WebhookDeployApp(object): if 'REQUEST_METHOD' in os.environ: - sys.stderr.write("Trying to open logfile {!r} ...\n".format(self.logfile)) + #sys.stderr.write("Trying to open logfile {!r} ...\n".format(self.logfile)) # we are in a CGI environment if os.path.isdir(self.log_directory) and os.access(self.log_directory, os.W_OK): lh_file = logging.FileHandler( @@ -174,7 +179,16 @@ class WebhookDeployApp(object): log.info("Starting ...") log.debug("Base directory: {!r}".format(self.base_dir)) + self.data = sys.stdin.read() + try: + self.json_data = json.loads(self.data) + except Exception as e: + LOG.error("Got a {n} reading input data: {e}".format(n=e.__class__.__name__, e)) + LOG.error("Input data:\n{}".format(self.data) + sys.exit(0) + LOG.debug("Got data:\n{}".format(pp(self.json_data))) + sys.exit(0) # ============================================================================= -- 2.39.5