Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
184dd60f
Commit
184dd60f
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: run function now passes all extra kwargs through to sp.Popen
parent
57cb76ed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/run.py
+14
-9
14 additions, 9 deletions
fsl/utils/run.py
with
14 additions
and
9 deletions
fsl/utils/run.py
+
14
−
9
View file @
184dd60f
...
@@ -165,17 +165,21 @@ def run(*args, **kwargs):
...
@@ -165,17 +165,21 @@ def run(*args, **kwargs):
- cmd: Optional file-like object to which the command
- cmd: Optional file-like object to which the command
itself is logged.
itself is logged.
All other keyword arguments are passed through to the ``subprocess.Popen``
object (via :func:`_realrun`), unless ``submit=True``, in which case they
are ignored.
: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
value or a tuple, based on the based on the ``stdout``,
value or a tuple, based on the based on the ``stdout``,
``stderr``, and ``exitcode`` arguments.
``stderr``, and ``exitcode`` arguments.
"""
"""
returnStdout
=
kwargs
.
get
(
'
stdout
'
,
True
)
returnStdout
=
kwargs
.
pop
(
'
stdout
'
,
True
)
returnStderr
=
kwargs
.
get
(
'
stderr
'
,
False
)
returnStderr
=
kwargs
.
pop
(
'
stderr
'
,
False
)
returnExitcode
=
kwargs
.
get
(
'
exitcode
'
,
False
)
returnExitcode
=
kwargs
.
pop
(
'
exitcode
'
,
False
)
submit
=
kwargs
.
get
(
'
submit
'
,
{})
submit
=
kwargs
.
pop
(
'
submit
'
,
{})
log
=
kwargs
.
get
(
'
log
'
,
{})
log
=
kwargs
.
pop
(
'
log
'
,
{})
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
)
...
@@ -207,7 +211,7 @@ def run(*args, **kwargs):
...
@@ -207,7 +211,7 @@ def run(*args, **kwargs):
# Run directly - delegate to _realrun
# Run directly - delegate to _realrun
stdout
,
stderr
,
exitcode
=
_realrun
(
stdout
,
stderr
,
exitcode
=
_realrun
(
tee
,
logStdout
,
logStderr
,
logCmd
,
*
args
)
tee
,
logStdout
,
logStderr
,
logCmd
,
*
args
,
**
kwargs
)
if
not
returnExitcode
and
(
exitcode
!=
0
):
if
not
returnExitcode
and
(
exitcode
!=
0
):
raise
RuntimeError
(
'
{} returned non-zero exit code: {}
'
.
format
(
raise
RuntimeError
(
'
{} returned non-zero exit code: {}
'
.
format
(
...
@@ -222,7 +226,6 @@ def run(*args, **kwargs):
...
@@ -222,7 +226,6 @@ def run(*args, **kwargs):
else
:
return
tuple
(
results
)
else
:
return
tuple
(
results
)
def
_dryrun
(
submit
,
returnStdout
,
returnStderr
,
returnExitcode
,
*
args
):
def
_dryrun
(
submit
,
returnStdout
,
returnStderr
,
returnExitcode
,
*
args
):
"""
Used by the :func:`run` function when the :attr:`DRY_RUN` flag is
"""
Used by the :func:`run` function when the :attr:`DRY_RUN` flag is
active.
active.
...
@@ -243,7 +246,7 @@ def _dryrun(submit, returnStdout, returnStderr, returnExitcode, *args):
...
@@ -243,7 +246,7 @@ def _dryrun(submit, returnStdout, returnStderr, returnExitcode, *args):
else
:
return
tuple
(
results
)
else
:
return
tuple
(
results
)
def
_realrun
(
tee
,
logStdout
,
logStderr
,
logCmd
,
*
args
):
def
_realrun
(
tee
,
logStdout
,
logStderr
,
logCmd
,
*
args
,
**
kwargs
):
"""
Used by :func:`run`. Runs the given command and manages its standard
"""
Used by :func:`run`. Runs the given command and manages its standard
output and error streams.
output and error streams.
...
@@ -262,12 +265,14 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
...
@@ -262,12 +265,14 @@ def _realrun(tee, logStdout, logStderr, logCmd, *args):
:arg args: Command to run
:arg args: Command to run
:arg kwargs: Passed through to the ``subprocess.Popen`` object.
:returns: A tuple containing:
:returns: A tuple containing:
- the command
'
s standard output as a string.
- the command
'
s standard output as a string.
- the command
'
s standard error as a string.
- the command
'
s standard error as a string.
- the command
'
s exit code.
- the command
'
s exit code.
"""
"""
proc
=
sp
.
Popen
(
args
,
stdout
=
sp
.
PIPE
,
stderr
=
sp
.
PIPE
)
proc
=
sp
.
Popen
(
args
,
stdout
=
sp
.
PIPE
,
stderr
=
sp
.
PIPE
,
**
kwargs
)
with
tempdir
.
tempdir
(
changeto
=
False
)
as
td
:
with
tempdir
.
tempdir
(
changeto
=
False
)
as
td
:
# We always direct the command's stdout/
# We always direct the command's stdout/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment