1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
from __future__ import print_function
3
- import subprocess
4
3
import os
5
4
6
-
7
5
# Import DEVNULL for py3 or py3
8
6
try :
9
7
from subprocess import DEVNULL
12
10
13
11
# Check availability of some system tools
14
12
# 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)!" )
38
13
39
14
40
15
def gunzip (filename ):
@@ -50,9 +25,17 @@ def gunzip(filename):
50
25
Name of the decompressed file (or input filename if gzip is not
51
26
available).
52
27
"""
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
+
53
34
# ".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 )
56
39
return filename .rsplit ("." , 1 )[0 ]
57
40
else :
58
41
return filename
0 commit comments