initial checkin

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-07-24 12:19:34 +02:00
commit 5755d14d84
13 changed files with 124 additions and 0 deletions

4
tools/Makefile Normal file
View file

@ -0,0 +1,4 @@
TOPDIR = ..
include $(TOPDIR)/make/proj.mk
include $(MODDIR)/make/dirs.mk

4
tools/python/Makefile Normal file
View file

@ -0,0 +1,4 @@
TOPDIR = ../..
include $(TOPDIR)/make/proj.mk
include $(MODDIR)/make/dirs.mk

View file

@ -0,0 +1,4 @@
TOPDIR = ../../..
include $(TOPDIR)/make/proj.mk
include $(MODDIR)/make/py-mod.mk

View file

@ -0,0 +1,36 @@
from __future__ import print_function
import os
import io
import sys
import traceback
from fcntl import fcntl, F_GETFL, F_SETFL
class MuteStdIO: # export
def __init__(self, mute_stderr=False, mute_stdout=True):
# TODO: arguments not implemented
pass
def __enter__(self):
rfd, wfd = os.pipe()
flags = fcntl(rfd, F_GETFL)
fcntl(rfd, F_SETFL, flags | os.O_NONBLOCK)
self.rfile = io.open(rfd, 'r')
self.fake_stdout_stream = io.open(wfd, 'w')
self.real_stdout_fd = os.dup(1)
#os.close(1)
os.dup2(wfd, 1)
def __exit__(self, type, value, traceback):
sys.stdout.flush()
os.dup2(self.real_stdout_fd, 1)
if type is not None:
#print("-------- Error while stdio was suppressed --------")
#traceback.print_stack()
#print(traceback)
print("-------- Captured output --------")
print(*self.rfile.readlines())
self.rfile.close()
#print('type = ' + str(type))
#print('value = ' + str(value))
raise type(value)