Skip to content
Snippets Groups Projects
Commit 6f8ebf44 authored by Martin Craig's avatar Martin Craig
Browse files

Make log key 'cmd' into a stream rather than a boolean

This enables a common use case - logging the command but not the standard output
parent 6b34f405
No related branches found
No related tags found
No related merge requests found
...@@ -163,8 +163,8 @@ def run(*args, **kwargs): ...@@ -163,8 +163,8 @@ def run(*args, **kwargs):
- stderr: Optional file-like object to which the command's - stderr: Optional file-like object to which the command's
standard error stream can be forwarded. standard error stream can be forwarded.
- cmd: If ``True``, the command itself is logged to the - cmd: Optional file-like object to which the command itself
standard output stream(s). is logged.
:returns: If ``submit`` is provided, the return value of :returns: If ``submit`` is provided, the return value of
:func:`.fslsub` is returned. Otherwise returns a single :func:`.fslsub` is returned. Otherwise returns a single
...@@ -191,7 +191,7 @@ def run(*args, **kwargs): ...@@ -191,7 +191,7 @@ def run(*args, **kwargs):
tee = log .get('tee', False) tee = log .get('tee', False)
logStdout = log .get('stdout', None) logStdout = log .get('stdout', None)
logStderr = log .get('stderr', None) logStderr = log .get('stderr', None)
logCmd = log .get('cmd', False) logCmd = log .get('cmd', None)
args = _prepareArgs(args) args = _prepareArgs(args)
if not bool(submit): if not bool(submit):
...@@ -269,8 +269,8 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args): ...@@ -269,8 +269,8 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
:arg logStderr: Optional file-like object to which the command's standard :arg logStderr: Optional file-like object to which the command's standard
error stream can be forwarded. error stream can be forwarded.
:arg logCmd: If ``True``, the command itself is logged to the standard :arg logCmd: Optional file-like object to which the command itself is
output stream(s). logged.
:arg args: Command to run :arg args: Command to run
...@@ -305,15 +305,13 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args): ...@@ -305,15 +305,13 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
if logStdout is not None: outstreams.append(logStdout) if logStdout is not None: outstreams.append(logStdout)
if logStderr is not None: errstreams.append(logStderr) if logStderr is not None: errstreams.append(logStderr)
# log the command to # log the command if requested
# stdout if requested if logCmd is not None:
if logCmd:
cmd = ' '.join(args) + '\n' cmd = ' '.join(args) + '\n'
for o in outstreams: if 'b' in getattr(logCmd, 'mode', 'w'):
if 'b' in getattr(o, 'mode', 'w'): logCmd.write(cmd.encode('utf-8'))
o.write(cmd.encode('utf-8')) else:
else: logCmd.write(cmd)
o.write(cmd)
stdoutt = _forwardStream(proc.stdout, *outstreams) stdoutt = _forwardStream(proc.stdout, *outstreams)
stderrt = _forwardStream(proc.stderr, *errstreams) stderrt = _forwardStream(proc.stderr, *errstreams)
...@@ -369,6 +367,7 @@ def runfsl(*args, **kwargs): ...@@ -369,6 +367,7 @@ def runfsl(*args, **kwargs):
return run(*args, **kwargs) return run(*args, **kwargs)
def wait(job_ids): def wait(job_ids):
"""Proxy for :func:`.fslsub.wait`. """ """Proxy for :func:`.fslsub.wait`. """
return fslsub.wait(job_ids) return fslsub.wait(job_ids)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment