waf/waflib/processor.py

50 lines
1.0 KiB
Python
Raw Normal View History

#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2015 (ita)
"""
"""
2016-02-26 14:25:54 +01:00
import os, threading, sys, signal, time, traceback, base64
try:
import cPickle
except ImportError:
import pickle as cPickle
try:
import subprocess32 as subprocess
except ImportError:
import subprocess
while 1:
2016-02-26 14:25:54 +01:00
txt = sys.stdin.readline().strip()
if not txt:
# parent process probably ended
break
2016-02-26 14:25:54 +01:00
[cmd, kwargs, cargs] = cPickle.loads(base64.b64decode(txt))
cargs = cargs or {}
ret = 1
out, err = (None, None)
ex = None
try:
proc = subprocess.Popen(cmd, **kwargs)
out, err = proc.communicate(**cargs)
ret = proc.returncode
except OSError as e:
# TODO
exc_type, exc_value, tb = sys.exc_info()
exc_lines = traceback.format_exception(exc_type, exc_value, tb)
ex = str(cmd) + '\n' + ''.join(exc_lines)
except ValueError as e:
# TODO
ex = str(e)
# it is just text so maybe we do not need to pickle()
tmp = [ret, out, err, ex]
2016-02-26 14:25:54 +01:00
obj = base64.b64encode(cPickle.dumps(tmp))
sys.stdout.write(obj.decode())
sys.stdout.write('\n')
sys.stdout.flush()