From 5755d14d8465724c6fc93db61514145c3308409b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 24 Jul 2017 12:19:34 +0200 Subject: [PATCH] initial checkin Signed-off-by: Jan Lindemann --- .gitignore | 15 +++++++++++++ Makefile | 4 ++++ VERSION | 1 + make/Makefile | 4 ++++ make/proj.mk | 11 ++++++++++ make/project.conf | 18 ++++++++++++++++ test/Makefile | 4 ++++ test/mute-stdio/Makefile | 5 +++++ test/mute-stdio/main.py | 14 +++++++++++++ tools/Makefile | 4 ++++ tools/python/Makefile | 4 ++++ tools/python/jwutil/Makefile | 4 ++++ tools/python/jwutil/MuteStdIO.py | 36 ++++++++++++++++++++++++++++++++ 13 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 VERSION create mode 100644 make/Makefile create mode 100644 make/proj.mk create mode 100644 make/project.conf create mode 100644 test/Makefile create mode 100644 test/mute-stdio/Makefile create mode 100644 test/mute-stdio/main.py create mode 100644 tools/Makefile create mode 100644 tools/python/Makefile create mode 100644 tools/python/jwutil/Makefile create mode 100644 tools/python/jwutil/MuteStdIO.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..466337c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.done +*.dep.mk +*.o +*.so.* +*.so +*.a +*.rep +ld-*.conf +*.ldscript +*.pc +jw-python +*_generated_* +*.secret +local.mk +.gdb_history diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..70c6f93 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +TOPDIR = . + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/topdir.mk diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..7824e43 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0-0-dev diff --git a/make/Makefile b/make/Makefile new file mode 100644 index 0000000..7b0b68f --- /dev/null +++ b/make/Makefile @@ -0,0 +1,4 @@ +TOPDIR = .. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/make.mk diff --git a/make/proj.mk b/make/proj.mk new file mode 100644 index 0000000..14c1a8f --- /dev/null +++ b/make/proj.mk @@ -0,0 +1,11 @@ +# to be included from inside the project directory + +CVS_PROJ_DIR ?= $(TOPDIR)/.. + +ifeq ($(TARGET),mingw) +FLAVOUR_PATH_PREFIX = win32/ +endif +MODDIR = $(firstword $(wildcard $(CVS_PROJ_DIR)/jw-build /opt/$(FLAVOUR_PATH_PREFIX)jw-build)) + +USE_PROJECT_LIB = false +HDRDIR_SCOPE_SUFFIX = $(PROJECT) diff --git a/make/project.conf b/make/project.conf new file mode 100644 index 0000000..2531b0c --- /dev/null +++ b/make/project.conf @@ -0,0 +1,18 @@ +[summary] +janware Python utility library + +[description] +janware Python utility library + +[global] +group = "Amusements/Teaching/Other" +subpackages = run +license = Copyright (c) Jan Lindemann, all rights reserved +jw-maintainer = jan + +[build] +libname = none + +[pkg.requires.jw] +devel = jw-python-run = VERSION-REVISION, jw-build-devel = VERSION +build = jw-build-devel diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..6e9f4ed --- /dev/null +++ b/test/Makefile @@ -0,0 +1,4 @@ +TOPDIR = .. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/cleandirs.mk diff --git a/test/mute-stdio/Makefile b/test/mute-stdio/Makefile new file mode 100644 index 0000000..348baf5 --- /dev/null +++ b/test/mute-stdio/Makefile @@ -0,0 +1,5 @@ +TOPDIR = ../.. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/py-run.mk + diff --git a/test/mute-stdio/main.py b/test/mute-stdio/main.py new file mode 100644 index 0000000..a8f1a40 --- /dev/null +++ b/test/mute-stdio/main.py @@ -0,0 +1,14 @@ +import jwutil + +print "This is without muted output" + +with jwutil.MuteStdIO(): + print "This is with muted output" + +with jwutil.MuteStdIO(): + print "This will have an error" + print "Second suppressed line of output" + print "Third suppressed line of output" + raise Exception("Something went wrong") + +print "Output is unmuted again" diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..2f00ade --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,4 @@ +TOPDIR = .. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/dirs.mk diff --git a/tools/python/Makefile b/tools/python/Makefile new file mode 100644 index 0000000..a5f2187 --- /dev/null +++ b/tools/python/Makefile @@ -0,0 +1,4 @@ +TOPDIR = ../.. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/dirs.mk diff --git a/tools/python/jwutil/Makefile b/tools/python/jwutil/Makefile new file mode 100644 index 0000000..a45fe49 --- /dev/null +++ b/tools/python/jwutil/Makefile @@ -0,0 +1,4 @@ +TOPDIR = ../../.. + +include $(TOPDIR)/make/proj.mk +include $(MODDIR)/make/py-mod.mk diff --git a/tools/python/jwutil/MuteStdIO.py b/tools/python/jwutil/MuteStdIO.py new file mode 100644 index 0000000..66b91b9 --- /dev/null +++ b/tools/python/jwutil/MuteStdIO.py @@ -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)