Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
1bd1ab69
Commit
1bd1ab69
authored
6 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Added new fslsub.output function. Bugfix to run.run.
parent
14083ed6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/utils/fslsub.py
+38
-2
38 additions, 2 deletions
fsl/utils/fslsub.py
fsl/utils/run.py
+4
-4
4 additions, 4 deletions
fsl/utils/run.py
with
42 additions
and
6 deletions
fsl/utils/fslsub.py
+
38
−
2
View file @
1bd1ab69
...
@@ -33,17 +33,20 @@ Example usage, building a short pipeline::
...
@@ -33,17 +33,20 @@ Example usage, building a short pipeline::
submit
submit
info
info
output
wait
wait
func_to_cmd
"""
"""
import
logging
from
six
import
string_types
,
BytesIO
from
six
import
string_types
,
BytesIO
import
subprocess
as
sp
import
subprocess
as
sp
import
os.path
as
op
import
time
import
time
import
pickle
import
pickle
import
sys
import
sys
import
tempfile
import
tempfile
import
logging
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -141,7 +144,7 @@ def info(job_id):
...
@@ -141,7 +144,7 @@ def info(job_id):
try
:
try
:
result
=
sp
.
call
([
'
qstat
'
,
'
-j
'
,
job_id
]).
decode
(
'
utf-8
'
)
result
=
sp
.
call
([
'
qstat
'
,
'
-j
'
,
job_id
]).
decode
(
'
utf-8
'
)
except
FileNotFoundError
:
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
{}
return
{}
if
'
Following jobs do not exist:
'
in
result
:
if
'
Following jobs do not exist:
'
in
result
:
return
{}
return
{}
...
@@ -152,6 +155,38 @@ def info(job_id):
...
@@ -152,6 +155,38 @@ def info(job_id):
return
res
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
):
def
wait
(
job_ids
):
"""
Wait for one or more jobs to finish
"""
Wait for one or more jobs to finish
...
@@ -212,4 +247,5 @@ def func_to_cmd(func, args, kwargs, tmp_dir=None, clean=False):
...
@@ -212,4 +247,5 @@ def func_to_cmd(func, args, kwargs, tmp_dir=None, clean=False):
with
open
(
filename
,
'
w
'
)
as
python_file
:
with
open
(
filename
,
'
w
'
)
as
python_file
:
python_file
.
write
(
python_cmd
)
python_file
.
write
(
python_cmd
)
# TODO use current interpreter (e.g. fslpython)?
return
"
python
"
+
filename
+
(
'
; rm
'
+
filename
if
clean
else
''
)
return
"
python
"
+
filename
+
(
'
; rm
'
+
filename
if
clean
else
''
)
This diff is collapsed.
Click to expand it.
fsl/utils/run.py
+
4
−
4
View file @
1bd1ab69
...
@@ -112,9 +112,9 @@ def run(*args, **kwargs):
...
@@ -112,9 +112,9 @@ def run(*args, **kwargs):
``err``), and return code (if ``ret``).
``err``), and return code (if ``ret``).
"""
"""
err
=
kwargs
.
get
(
'
err
'
,
False
)
err
=
kwargs
.
get
(
'
err
'
,
False
)
ret
=
kwargs
.
get
(
'
ret
'
,
False
)
ret
=
kwargs
.
get
(
'
ret
'
,
False
)
submit
=
kwargs
.
get
(
'
re
t
'
,
None
)
submit
=
kwargs
.
get
(
'
submi
t
'
,
None
)
args
=
_prepareArgs
(
args
)
args
=
_prepareArgs
(
args
)
if
not
bool
(
submit
):
if
not
bool
(
submit
):
...
@@ -185,5 +185,5 @@ def runfsl(*args, **kwargs):
...
@@ -185,5 +185,5 @@ def runfsl(*args, **kwargs):
def
wait
(
job_ids
):
def
wait
(
job_ids
):
"""
Calls
:func:`.fslsub.wait`
for the given ``job_ids``
.
"""
"""
Proxy for
:func:`.fslsub.wait`.
"""
return
fslsub
.
wait
(
job_ids
)
return
fslsub
.
wait
(
job_ids
)
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