Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sean Fitzgibbon
fslpy
Commits
1bd1ab69
Commit
1bd1ab69
authored
Apr 19, 2018
by
Paul McCarthy
🚵
Browse files
Added new fslsub.output function. Bugfix to run.run.
parent
14083ed6
Changes
2
Hide whitespace changes
Inline
Side-by-side
fsl/utils/fslsub.py
View file @
1bd1ab69
...
...
@@ -33,17 +33,20 @@ Example usage, building a short pipeline::
submit
info
output
wait
func_to_cmd
"""
import
logging
from
six
import
string_types
,
BytesIO
import
subprocess
as
sp
import
os.path
as
op
import
time
import
pickle
import
sys
import
tempfile
import
logging
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -141,7 +144,7 @@ def info(job_id):
try
:
result
=
sp
.
call
([
'qstat'
,
'-j'
,
job_id
]).
decode
(
'utf-8'
)
except
FileNotFoundError
:
log
.
debug
(
"qstat not found; assum
es
not n
ot
cluster"
)
log
.
debug
(
"qstat not found; assum
ing
not
o
n cluster"
)
return
{}
if
'Following jobs do not exist:'
in
result
:
return
{}
...
...
@@ -152,6 +155,38 @@ def info(job_id):
return
res
def
output
(
job_id
,
command
,
cwd
=
'.'
,
name
=
None
):
"""Returns the output of the given job.
:arg job_id: String with job id
:arg command: Command that was run
:arg cwd: Directory from which command was submitted - defaults to
the current directory.
:arg name: Job name if it was specified.
:returns: A tuple containing the standard output and standard error.
"""
if
name
is
None
:
name
=
op
.
basename
(
command
)
stdout
=
op
.
join
(
cwd
,
'{}.o{}'
.
format
(
name
,
job_id
))
stderr
=
op
.
join
(
cwd
,
'{}.e{}'
.
format
(
name
,
job_id
))
if
op
.
exists
(
stdout
):
with
open
(
stdout
,
'rt'
)
as
f
:
stdout
=
f
.
read
()
else
:
stdout
=
None
if
op
.
exists
(
stderr
):
with
open
(
stderr
,
'rt'
)
as
f
:
stderr
=
f
.
read
()
else
:
stderr
=
None
return
stdout
,
stderr
def
wait
(
job_ids
):
"""Wait for one or more jobs to finish
...
...
@@ -212,4 +247,5 @@ def func_to_cmd(func, args, kwargs, tmp_dir=None, clean=False):
with
open
(
filename
,
'w'
)
as
python_file
:
python_file
.
write
(
python_cmd
)
# TODO use current interpreter (e.g. fslpython)?
return
"python "
+
filename
+
(
'; rm '
+
filename
if
clean
else
''
)
fsl/utils/run.py
View file @
1bd1ab69
...
...
@@ -112,9 +112,9 @@ def run(*args, **kwargs):
``err``), and return code (if ``ret``).
"""
err
=
kwargs
.
get
(
'err'
,
False
)
ret
=
kwargs
.
get
(
'ret'
,
False
)
submit
=
kwargs
.
get
(
'
re
t'
,
None
)
err
=
kwargs
.
get
(
'err'
,
False
)
ret
=
kwargs
.
get
(
'ret'
,
False
)
submit
=
kwargs
.
get
(
'
submi
t'
,
None
)
args
=
_prepareArgs
(
args
)
if
not
bool
(
submit
):
...
...
@@ -185,5 +185,5 @@ def runfsl(*args, **kwargs):
def
wait
(
job_ids
):
"""
Calls
:func:`.fslsub.wait`
for the given ``job_ids``
. """
"""
Proxy for
:func:`.fslsub.wait`. """
return
fslsub
.
wait
(
job_ids
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment