Fix Python 2.6 compatibility issue.
This commit is contained in:
parent
6ad5210216
commit
1e2f421faa
@ -92,7 +92,7 @@ def display_specs(specs, **kwargs):
|
|||||||
# Print one spec per line along with prefix path
|
# Print one spec per line along with prefix path
|
||||||
width = max(len(s) for s in abbreviated)
|
width = max(len(s) for s in abbreviated)
|
||||||
width += 2
|
width += 2
|
||||||
format = " %-{}s%s".format(width)
|
format = " %%-%ds%%s" % width
|
||||||
|
|
||||||
for abbrv, spec in zip(abbreviated, specs):
|
for abbrv, spec in zip(abbreviated, specs):
|
||||||
if hashes:
|
if hashes:
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
import spack
|
import spack
|
||||||
import spack.error
|
import spack.error
|
||||||
|
|
||||||
|
|
||||||
class Executable(object):
|
class Executable(object):
|
||||||
"""Class representing a program that can be run on the command line."""
|
"""Class representing a program that can be run on the command line."""
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@ -58,7 +59,20 @@ def __call__(self, *args, **kwargs):
|
|||||||
return_output = kwargs.get("return_output", False)
|
return_output = kwargs.get("return_output", False)
|
||||||
fail_on_error = kwargs.get("fail_on_error", True)
|
fail_on_error = kwargs.get("fail_on_error", True)
|
||||||
ignore_errors = kwargs.get("ignore_errors", ())
|
ignore_errors = kwargs.get("ignore_errors", ())
|
||||||
|
|
||||||
|
output = kwargs.get("output", sys.stdout)
|
||||||
error = kwargs.get("error", sys.stderr)
|
error = kwargs.get("error", sys.stderr)
|
||||||
|
input = kwargs.get("input", None)
|
||||||
|
|
||||||
|
def streamify(arg, mode):
|
||||||
|
if isinstance(arg, basestring):
|
||||||
|
return open(arg, mode), True
|
||||||
|
elif arg is None and mode != 'r':
|
||||||
|
return open(os.devnull, mode), True
|
||||||
|
return arg, False
|
||||||
|
output, ostream = streamify(output, 'w')
|
||||||
|
error, estream = streamify(error, 'w')
|
||||||
|
input, istream = streamify(input, 'r')
|
||||||
|
|
||||||
# if they just want to ignore one error code, make it a tuple.
|
# if they just want to ignore one error code, make it a tuple.
|
||||||
if isinstance(ignore_errors, int):
|
if isinstance(ignore_errors, int):
|
||||||
@ -77,16 +91,12 @@ def __call__(self, *args, **kwargs):
|
|||||||
cmd_line = ' '.join(cmd)
|
cmd_line = ' '.join(cmd)
|
||||||
tty.debug(cmd_line)
|
tty.debug(cmd_line)
|
||||||
|
|
||||||
close_error = False
|
|
||||||
try:
|
try:
|
||||||
if error is None:
|
|
||||||
error = open(os.devnull, 'w')
|
|
||||||
close_error = True
|
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
cmd,
|
cmd,
|
||||||
|
stdin=input,
|
||||||
stderr=error,
|
stderr=error,
|
||||||
stdout=subprocess.PIPE if return_output else sys.stdout)
|
stdout=subprocess.PIPE if return_output else output)
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
self.returncode = proc.returncode
|
self.returncode = proc.returncode
|
||||||
|
|
||||||
@ -110,8 +120,9 @@ def __call__(self, *args, **kwargs):
|
|||||||
% (proc.returncode, cmd_line))
|
% (proc.returncode, cmd_line))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if close_error:
|
if ostream: output.close()
|
||||||
error.close()
|
if estream: error.close()
|
||||||
|
if istream: input.close()
|
||||||
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
Loading…
Reference in New Issue
Block a user