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

15
.gitignore vendored Normal file
View file

@ -0,0 +1,15 @@
*.done
*.dep.mk
*.o
*.so.*
*.so
*.a
*.rep
ld-*.conf
*.ldscript
*.pc
jw-python
*_generated_*
*.secret
local.mk
.gdb_history

4
Makefile Normal file
View file

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

1
VERSION Normal file
View file

@ -0,0 +1 @@
1.0.0-0-dev

4
make/Makefile Normal file
View file

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

11
make/proj.mk Normal file
View file

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

18
make/project.conf Normal file
View file

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

4
test/Makefile Normal file
View file

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

5
test/mute-stdio/Makefile Normal file
View file

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

14
test/mute-stdio/main.py Normal file
View file

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

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)