Commit 0cfecd5e authored by Manuel Günther's avatar Manuel Günther

Further improved python 3 compatibility.

parent 81d7ca74
......@@ -22,15 +22,13 @@ def environ(context):
try:
command = ['bash', '-c', 'source %s && env' % idiap_source]
pi = subprocess.Popen(command, stdout = subprocess.PIPE)
except OSError as e:
# occurs when the file is not executable or not found
raise OSError, "Error executing '%s': %s (%d)" % \
(' '.join(command), e.strerror, e.errno)
# overwrite the default environment
for line in pi.stdout:
(key, _, value) = line.partition("=")
os.environ[key.strip()] = value.strip()
except OSError as e:
# occurs when the file is not executable or not found
pass
# in case the BASEDIRSETSHELL environment variable is not set,
# we are not at Idiap,
......@@ -49,8 +47,7 @@ def environ(context):
p = subprocess.Popen(command, stdout = subprocess.PIPE)
except OSError as e:
# occurs when the file is not executable or not found
raise OSError, "Error executing '%s': %s (%d)" % \
(' '.join(command), e.strerror, e.errno)
raise OSError("Error executing '%s': %s (%d)" % (' '.join(command), e.strerror, e.errno))
try:
source = p.communicate()[0]
......@@ -67,8 +64,7 @@ def environ(context):
p2 = subprocess.Popen(command2, stdout = subprocess.PIPE)
except OSError as e:
# occurs when the file is not executable or not found
raise OSError, "Error executing '%s': %s (%d)" % \
(' '.join(command2), e.strerror, e.errno)
raise OSError("Error executing '%s': %s (%d)" % (' '.join(command2), e.strerror, e.errno))
new_environ = dict(os.environ)
for line in p2.stdout:
......@@ -102,9 +98,7 @@ def sexec(context, command, error_on_nonzero=True):
(stdout, stderr) = p.communicate() #note: stderr will be 'None'
if p.returncode != 0:
if error_on_nonzero:
raise RuntimeError, \
"Execution of '%s' exited with status != 0 (%d): %s" % \
(' '.join(command), p.returncode, stdout)
raise RuntimeError("Execution of '%s' exited with status != 0 (%d): %s" % (' '.join(command), p.returncode, stdout))
else:
logger.debug("Execution of '%s' exited with status != 0 (%d): %s" % \
(' '.join(command), p.returncode, stdout))
......
......@@ -197,7 +197,7 @@ def qsub(command, queue=None, cwd=True, name=None, deps=[], stdout='',
scmd.append('1-%d:1' % array)
if isinstance(array, (tuple, list)):
if len(array) < 1 or len(array) > 3:
raise RuntimeError, "Array tuple should have length between 1 and 3"
raise RuntimeError("Array tuple should have length between 1 and 3")
elif len(array) == 1:
scmd.append('%s' % array[0])
elif len(array) == 2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment