From 5cbc5a8c35750dcc503980efc4d54647cf24bc83 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 11 Apr 2017 13:19:16 +0100 Subject: [PATCH] Add handle runner --- lantern/handle.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lantern/handle.py diff --git a/lantern/handle.py b/lantern/handle.py new file mode 100644 index 0000000..3addfb9 --- /dev/null +++ b/lantern/handle.py @@ -0,0 +1,20 @@ +import subprocess +import json +from collections import namedtuple + + +Result = namedtuple('Result', ['exit_code', 'html', 'error']) + + +def execute_handle(executable, request_data): + input_data = json.dumps(request_data).encode('utf-8') + cmd = subprocess.run(executable, input=input_data, stdout=subprocess.PIPE) + return Result( + cmd.returncode, + cmd.stdout.decode('utf-8'), + cmd.stderr.decode('utf-8') + ) + + +def get_http_status_code(exit_code): + return 200 if exit_code == 0 else 500