11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22from __future__ import print_function
3- import subprocess
43import os
54
6-
75# Import DEVNULL for py3 or py3
86try:
97 from subprocess import DEVNULL
1210
1311# Check availability of some system tools
1412# Exceptions are raised if not found
15- __is_gzip_found = False
16- for test_cmd in (["gzip", "-V"], ["7z"]):
17- try:
18- subprocess.call(test_cmd, stdout=DEVNULL, stderr=DEVNULL)
19- except OSError:
20- pass
21- else:
22- __is_gzip_found = test_cmd[0]
23-
24-
25- if __is_gzip_found == 'gzip':
26- def _unzip_cmd(filename):
27- return ["gzip", "-d", "{0}".format(filename)]
28- elif __is_gzip_found == '7z':
29- def _unzip_cmd(filename):
30- return ["7z", "x",
31- "{0}".format(filename),
32- "-o{0}".format(os.path.split(filename)[0])]
33- else:
34- print("gzip was not found on your system! You should solve this issue for "
35- "astroquery.eso to be at its best!\n"
36- "On POSIX system: make sure gzip is installed and in your path!"
37- "On Windows: same for 7-zip (http://www.7-zip.org)!")
3813
3914
4015def gunzip(filename):
@@ -50,9 +25,17 @@ def gunzip(filename):
5025 Name of the decompressed file (or input filename if gzip is not
5126 available).
5227 """
28+ import shutil
29+ import gzip
30+
31+ # system-wide 'gzip' was removed, Python gzip used instead.
32+ # See #1538 : https://github.com/astropy/astroquery/issues/1538
33+
5334 # ".fz" denotes RICE rather than gzip compression
54- if __is_gzip_found and not filename.endswith('.fz'):
55- subprocess.call(_unzip_cmd(filename), stdout=DEVNULL, stderr=DEVNULL)
35+ if not filename.endswith('.fz'):
36+ with gzip.open(filename, 'rb') as f_in:
37+ with open(filename.rsplit(".", 1)[0], 'wb') as f_out:
38+ shutil.copyfileobj(f_in, f_out)
5639 return filename.rsplit(".", 1)[0]
5740 else:
5841 return filename
0 commit comments