summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Justen <jordan.l.justen@intel.com>2015-08-02 00:44:44 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-08-12 13:10:31 -0700
commit98b9352ae06c56911fb336a0264e5200ac630d83 (patch)
tree0cb94e47485faeb9697448583632fd1e391add4c
parentd958bc8d0ebb669525f743e998dc71f9c48e8480 (diff)
xz: Use --help when detecting xz presence
If xz is present, and the piglit command's output is redirected, then xz will think its output is redirected. This will cause xz to try to read data from stdin to compress. Instead we can run xz with --help to cause it to print help information if the xz executable is present, and prevent xz from trying to compress data from stdin. Since we don't want to see 'xz --help' output from piglit, we now need to redirect both stdout and stderr to /dev/null. This allows us to pipe the output of piglit summary when using the shell xz compressor. v2 (Dylan): - send both stdout and stderr directly to /dev/null - Fix xz detection in the xz shell path. Signed-off-by: Jordan Justen <jordan.l.justen@intel.com> Signed-off-by: Dylan Baker <baker.dylan.c@gmail.com>
-rw-r--r--framework/backends/compression.py153
1 files changed, 76 insertions, 77 deletions
diff --git a/framework/backends/compression.py b/framework/backends/compression.py
index 88bde2a63..7ca6c0c81 100644
--- a/framework/backends/compression.py
+++ b/framework/backends/compression.py
@@ -95,85 +95,84 @@ try:
except ImportError:
try:
with open(os.devnull, 'w') as d:
- subprocess.check_call(['xz'], stderr=d)
- except subprocess.CalledProcessError as e:
- if e.returncode == 1:
- import contextlib
- try:
- import cStringIO as StringIO
- except ImportError:
- import StringIO
-
- @contextlib.contextmanager
- def _compress_xz(filename):
- """Emulates an open function in write mode for xz.
-
- Python 2.x doesn't support xz, but it's dang useful. This
- function calls out to the shell and tries to use xz from the
- environment to get xz compression.
-
- This obviously won't work without a working xz binary.
-
- This function tries to emulate the default values of the lzma
- module in python3 as much as possible
-
- """
- if filename.endswith('.xz'):
- filename = filename[:-3]
-
- with open(filename, 'w') as f:
- yield f
-
- try:
- with open(os.devnull, 'w') as null:
- subprocess.check_call(
- ['xz', '--compress', '-9', '--force', filename],
- stderr=null)
- except OSError as e:
- if e.errno == errno.ENOENT:
- raise exceptions.PiglitFatalError(
- 'No xz binary available')
- raise
-
- @contextlib.contextmanager
- def _decompress_xz(filename):
- """Eumlates an option function in read mode for xz.
-
- See the comment in _compress_xz for more information.
-
- This function tries to emulate the lzma module as much as
- possible
-
- """
- if not filename.endswith('.xz'):
- filename = '{}.xz'.format(filename)
-
- try:
- with open(os.devnull, 'w') as null:
- string = subprocess.check_output(
- ['xz', '--decompress', '--stdout', filename],
- stderr=null)
- except OSError as e:
- if e.errno == errno.ENOENT:
- raise exceptions.PiglitFatalError(
- 'No xz binary available')
- raise
-
- # We need a file-like object, so the contents must be placed in
- # a StringIO object.
- io = StringIO.StringIO()
- io.write(string)
- io.seek(0)
-
- yield io
-
- io.close()
-
- COMPRESSORS['xz'] = _compress_xz
- DECOMPRESSORS['xz'] = _decompress_xz
- COMPRESSION_SUFFIXES += ['.xz']
+ subprocess.check_call(['xz', '--help'], stdout=d, stderr=d)
except OSError:
pass
+ else:
+ import contextlib
+ try:
+ import cStringIO as StringIO
+ except ImportError:
+ import StringIO
+
+ @contextlib.contextmanager
+ def _compress_xz(filename):
+ """Emulates an open function in write mode for xz.
+
+ Python 2.x doesn't support xz, but it's dang useful. This
+ function calls out to the shell and tries to use xz from the
+ environment to get xz compression.
+
+ This obviously won't work without a working xz binary.
+
+ This function tries to emulate the default values of the lzma
+ module in python3 as much as possible
+
+ """
+ if filename.endswith('.xz'):
+ filename = filename[:-3]
+
+ with open(filename, 'w') as f:
+ yield f
+
+ try:
+ with open(os.devnull, 'w') as null:
+ subprocess.check_call(
+ ['xz', '--compress', '-9', '--force', filename],
+ stderr=null)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ raise exceptions.PiglitFatalError(
+ 'No xz binary available')
+ raise
+
+ @contextlib.contextmanager
+ def _decompress_xz(filename):
+ """Eumlates an option function in read mode for xz.
+
+ See the comment in _compress_xz for more information.
+
+ This function tries to emulate the lzma module as much as
+ possible
+
+ """
+ if not filename.endswith('.xz'):
+ filename = '{}.xz'.format(filename)
+
+ try:
+ with open(os.devnull, 'w') as null:
+ string = subprocess.check_output(
+ ['xz', '--decompress', '--stdout', filename],
+ stderr=null)
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ raise exceptions.PiglitFatalError(
+ 'No xz binary available')
+ raise
+
+ # We need a file-like object, so the contents must be placed in
+ # a StringIO object.
+ io = StringIO.StringIO()
+ io.write(string)
+ io.seek(0)
+
+ yield io
+
+ io.close()
+
+ COMPRESSORS['xz'] = _compress_xz
+ DECOMPRESSORS['xz'] = _decompress_xz
+ COMPRESSION_SUFFIXES += ['.xz']
def get_mode():