remove call to system-wide gunzip. Use python version instead. Fixes
@@ -3,7 +3,6 @@ from __future__ import print_function
import subprocess
import os
-
# Import DEVNULL for py3 or py3
try:
from subprocess import DEVNULL
@@ -12,30 +11,6 @@ except ImportError:
# Check availability of some system tools
# Exceptions are raised if not found
-__is_gzip_found = False
-for test_cmd in (["gzip", "-V"], ["7z"]):
- try:
- subprocess.call(test_cmd, stdout=DEVNULL, stderr=DEVNULL)
- except OSError:
- pass
- else:
- __is_gzip_found = test_cmd[0]
-
-
-if __is_gzip_found == 'gzip':
- def _unzip_cmd(filename):
- return ["gzip", "-d", "{0}".format(filename)]
-elif __is_gzip_found == '7z':
- def _unzip_cmd(filename):
- return ["7z", "x",
- "{0}".format(filename),
- "-o{0}".format(os.path.split(filename)[0])]
-else:
- print("gzip was not found on your system! You should solve this issue for "
- "astroquery.eso to be at its best!\n"
- "On POSIX system: make sure gzip is installed and in your path!"
- "On Windows: same for 7-zip (http://www.7-zip.org)!")
-
def gunzip(filename):
""" Decompress a file with gzip.
@@ -50,9 +25,16 @@ def gunzip(filename):
Name of the decompressed file (or input filename if gzip is not
available).
"""
- # ".fz" denotes RICE rather than gzip compression
- if __is_gzip_found and not filename.endswith('.fz'):
- subprocess.call(_unzip_cmd(filename), stdout=DEVNULL, stderr=DEVNULL)
+ import shutil
+ import gzip
+
+ # @EP 09/01/20: system-wide 'gzip' was removed, Python gzip used instead.
+ # See #1538 : https://github.com/astropy/astroquery/issues/1538
+
+ if not filename.endswith('.fz'):
+ with gzip.open(filename, 'rb') as f_in:
+ with open(filename.rsplit(".", 1)[0], 'wb') as f_out:
+ shutil.copyfileobj(f_in, f_out)
return filename.rsplit(".", 1)[0]
else:
return filename
