Skip to content

Commit ab6db1f

Browse files
committed
ENH: test doesn't work yet but oar.py works
1 parent 29a1dfc commit ab6db1f

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

nipype/pipeline/plugins/oar.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
import os
5+
import stat
56
from time import sleep
67
import subprocess
78
import json
@@ -26,6 +27,7 @@ class OARPlugin(SGELikeBatchManagerBase):
2627

2728
# Addtional class variables
2829
_max_jobname_len = 15
30+
_oarsub_args = ''
2931

3032
def __init__(self, **kwargs):
3133
template = """
@@ -53,9 +55,10 @@ def _is_pending(self, taskid):
5355
stderr=subprocess.PIPE
5456
)
5557
o, e = proc.communicate()
58+
parsed_result = json.loads(o)[taskid].lower()
59+
is_pending = 'error' not in parsed_result
5660

57-
parsed_result = json.loads(o)[taskid]
58-
return 'error' not in parsed_result
61+
return is_pending
5962

6063
def _submit_batchtask(self, scriptfile, node):
6164
cmd = CommandLine('oarsub', environ=os.environ.data,
@@ -72,10 +75,7 @@ def _submit_batchtask(self, scriptfile, node):
7275
oarsubargs = node.plugin_args['oarsub_args']
7376
else:
7477
oarsubargs += (" " + node.plugin_args['oarsub_args'])
75-
if '-o' not in oarsubargs:
76-
oarsubargs = '%s -o %s' % (oarsubargs, path)
77-
if '-E' not in oarsubargs:
78-
oarsubargs = '%s -E %s' % (oarsubargs, path)
78+
7979
if node._hierarchy:
8080
jobname = '.'.join((os.environ.data['LOGNAME'],
8181
node._hierarchy,
@@ -87,6 +87,21 @@ def _submit_batchtask(self, scriptfile, node):
8787
jobnameitems.reverse()
8888
jobname = '.'.join(jobnameitems)
8989
jobname = jobname[0:self._max_jobname_len]
90+
91+
if '-O' not in oarsubargs:
92+
oarsubargs = '%s -O %s' % (
93+
oarsubargs,
94+
os.path.join(path, jobname + '.stdout')
95+
)
96+
if '-E' not in oarsubargs:
97+
oarsubargs = '%s -E %s' % (
98+
oarsubargs,
99+
os.path.join(path, jobname + '.stderr')
100+
)
101+
if '-J' not in oarsubargs:
102+
oarsubargs = '%s -J' % (oarsubargs)
103+
104+
os.chmod(scriptfile, stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
90105
cmd.inputs.args = '%s -n %s -S %s' % (
91106
oarsubargs,
92107
jobname,
@@ -106,7 +121,7 @@ def _submit_batchtask(self, scriptfile, node):
106121
# sleep 2 seconds and try again.
107122
else:
108123
iflogger.setLevel(oldlevel)
109-
raise RuntimeError('\n'.join((('Could not submit pbs task'
124+
raise RuntimeError('\n'.join((('Could not submit OAR task'
110125
' for node %s') % node._id,
111126
str(e))))
112127
else:
@@ -126,5 +141,4 @@ def _submit_batchtask(self, scriptfile, node):
126141
taskid = json.loads(o)['job_id']
127142
self._pending[taskid] = node.output_dir()
128143
logger.debug('submitted OAR task: %s for node %s' % (taskid, node._id))
129-
130144
return taskid

nipype/pipeline/plugins/tests/test_oar.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
from nipype import config, logging
2+
config.enable_debug_mode()
3+
logging.update_logging(config)
4+
15
import os
6+
from os import path
27
from shutil import rmtree
38
from tempfile import mkdtemp
49

@@ -7,6 +12,7 @@
712
import nipype.pipeline.engine as pe
813

914

15+
1016
class InputSpec(nib.TraitedSpec):
1117
input1 = nib.traits.Int(desc='a random int')
1218
input2 = nib.traits.Int(desc='a random int')
@@ -31,9 +37,9 @@ def _list_outputs(self):
3137

3238

3339
@skipif(False)
34-
def test_run_oargraph():
40+
def test_run_oar():
3541
cur_dir = os.getcwd()
36-
temp_dir = mkdtemp(prefix='test_engine_')
42+
temp_dir = mkdtemp(prefix='test_engine_', dir=os.getcwd())
3743
os.chdir(temp_dir)
3844

3945
pipe = pe.Workflow(name='pipe')
@@ -45,6 +51,7 @@ def test_run_oargraph():
4551
pipe.base_dir = os.getcwd()
4652
mod1.inputs.input1 = 1
4753
execgraph = pipe.run(plugin="OAR")
54+
print "Run"
4855
names = [
4956
'.'.join((node._hierarchy, node.name))
5057
for node in execgraph.nodes()

0 commit comments

Comments
 (0)