summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2015-07-23 17:01:33 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2015-07-23 17:01:55 -0700
commit1e2f421faa62455033ea6c3db941221723da3599 (patch)
tree1e5ffd75112a75cc3a31e20a3d5540516f3f1f16 /lib
parent6ad5210216f07dc2119f5d000ff7ed43d407e623 (diff)
downloadspack-1e2f421faa62455033ea6c3db941221723da3599.tar.gz
spack-1e2f421faa62455033ea6c3db941221723da3599.tar.bz2
spack-1e2f421faa62455033ea6c3db941221723da3599.tar.xz
spack-1e2f421faa62455033ea6c3db941221723da3599.zip
Fix Python 2.6 compatibility issue.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/find.py2
-rw-r--r--lib/spack/spack/util/executable.py27
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py
index a0232d2f12..3c993990b1 100644
--- a/lib/spack/spack/cmd/find.py
+++ b/lib/spack/spack/cmd/find.py
@@ -92,7 +92,7 @@ def display_specs(specs, **kwargs):
# Print one spec per line along with prefix path
width = max(len(s) for s in abbreviated)
width += 2
- format = " %-{}s%s".format(width)
+ format = " %%-%ds%%s" % width
for abbrv, spec in zip(abbreviated, specs):
if hashes:
diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py
index 67e8cddd98..d1dfb62ffb 100644
--- a/lib/spack/spack/util/executable.py
+++ b/lib/spack/spack/util/executable.py
@@ -34,6 +34,7 @@ import llnl.util.tty as tty
import spack
import spack.error
+
class Executable(object):
"""Class representing a program that can be run on the command line."""
def __init__(self, name):
@@ -58,7 +59,20 @@ class Executable(object):
return_output = kwargs.get("return_output", False)
fail_on_error = kwargs.get("fail_on_error", True)
ignore_errors = kwargs.get("ignore_errors", ())
+
+ output = kwargs.get("output", sys.stdout)
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 isinstance(ignore_errors, int):
@@ -77,16 +91,12 @@ class Executable(object):
cmd_line = ' '.join(cmd)
tty.debug(cmd_line)
- close_error = False
try:
- if error is None:
- error = open(os.devnull, 'w')
- close_error = True
-
proc = subprocess.Popen(
cmd,
+ stdin=input,
stderr=error,
- stdout=subprocess.PIPE if return_output else sys.stdout)
+ stdout=subprocess.PIPE if return_output else output)
out, err = proc.communicate()
self.returncode = proc.returncode
@@ -110,8 +120,9 @@ class Executable(object):
% (proc.returncode, cmd_line))
finally:
- if close_error:
- error.close()
+ if ostream: output.close()
+ if estream: error.close()
+ if istream: input.close()
def __eq__(self, other):