archive
/
lantern
Archived
1
Fork 0

Add handle runner

This commit is contained in:
Jake Howard 2017-04-11 13:19:16 +01:00
parent 5f8eee57bc
commit 5cbc5a8c35
1 changed files with 20 additions and 0 deletions

20
lantern/handle.py Normal file
View File

@ -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