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