summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-09-25 09:29:49 -0400
committerRob Crittenden <rcritten@redhat.com>2012-10-17 18:29:35 -0400
commit049bc7042e63904555e87dab8997851398ffe05b (patch)
treebfc03f8dd4f1e65cc8fd5af8d4c49c785a4ffb1b /ipapython
parent89e315d639e972608df11ae052029aaaf0eb1083 (diff)
downloadfreeipa-049bc7042e63904555e87dab8997851398ffe05b.tar.gz
freeipa-049bc7042e63904555e87dab8997851398ffe05b.tar.xz
freeipa-049bc7042e63904555e87dab8997851398ffe05b.zip
ipautil.run: Log the command line before running the command
When the user interrupts a long-running command, this ensures that the command is logged. Also, when watching log files (or the -d output), it's apparent what's being done. https://fedorahosted.org/freeipa/ticket/3174
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 0b519c295..e76d87d3d 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -292,30 +292,35 @@ def run(args, stdin=None, raiseonerr=True,
p_out = subprocess.PIPE
p_err = subprocess.PIPE
+ arg_string = nolog_replace(' '.join(args), nolog)
+ root_logger.debug('Starting external process')
+ root_logger.debug('args=%s' % arg_string)
+
try:
p = subprocess.Popen(args, stdin=p_in, stdout=p_out, stderr=p_err,
close_fds=True, env=env, cwd=cwd)
stdout,stderr = p.communicate(stdin)
stdout,stderr = str(stdout), str(stderr) # Make pylint happy
except KeyboardInterrupt:
+ root_logger.debug('Process interrupted')
p.wait()
raise
+ except:
+ root_logger.debug('Process execution failed')
+ raise
+
+ root_logger.debug('Process finished, return code=%s', p.returncode)
# The command and its output may include passwords that we don't want
# to log. Replace those.
- args = ' '.join(args)
if capture_output:
stdout = nolog_replace(stdout, nolog)
stderr = nolog_replace(stderr, nolog)
- args = nolog_replace(args, nolog)
-
- root_logger.debug('args=%s' % args)
- if capture_output:
root_logger.debug('stdout=%s' % stdout)
root_logger.debug('stderr=%s' % stderr)
if p.returncode != 0 and raiseonerr:
- raise CalledProcessError(p.returncode, args)
+ raise CalledProcessError(p.returncode, arg_string)
return (stdout, stderr, p.returncode)