From 8e96327060d34be991f5179cd18293471236ce8d Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Fri, 14 Nov 2014 13:53:14 +0100 Subject: utils_prog: add and use "Popen with logging" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- utils_prog.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'utils_prog.py') diff --git a/utils_prog.py b/utils_prog.py index cfbecbf..c481cda 100644 --- a/utils_prog.py +++ b/utils_prog.py @@ -26,6 +26,8 @@ from .utils import areinstances, \ selfaware, \ tuplist +log = logging.getLogger(__name__) + # # generics @@ -182,6 +184,11 @@ def set_logging(opts): rootlog.setLevel(logging.getLevelName(opts.loglevel)) +def PopenLog(cmd, *args, **kwargs): + log.debug("Running: {0}".format(' '.join(cmd))) + return Popen(cmd, *args, **kwargs) + + class OneoffWrappedStdinPopen(object): """Singleton to watch for atmost one use of stdin in Popen context""" def __init__(self): @@ -195,7 +202,7 @@ class OneoffWrappedStdinPopen(object): # only the first '-' substituted args[args.index('-')] = '/dev/stdin' self._used |= True - return Popen(args, **kwargs) + return PopenLog(args, **kwargs) OneoffWrappedStdinPopen = OneoffWrappedStdinPopen() -- cgit