Make Spack able to apply gz compressed remote patches (#22823)

Modified ncbi-rmblastn to retrieve patches from remote
This commit is contained in:
Massimiliano Culpo
2021-04-28 17:00:58 +02:00
committed by GitHub
parent 5cb5aac57e
commit 5b12568c4f
5 changed files with 31 additions and 556 deletions

View File

@@ -467,6 +467,8 @@ def expand(self):
tarball_container = os.path.join(self.stage.path,
"spack-expanded-archive")
# Below we assume that the command to decompress expand the
# archive in the current working directory
mkdirp(tarball_container)
with working_dir(tarball_container):
decompress(self.archive_file)

View File

@@ -22,6 +22,22 @@ def allowed_archive(path):
return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES)
def _gunzip(archive_file):
"""Like gunzip, but extracts in the current working directory
instead of in-place.
Args:
archive_file (str): absolute path of the file to be decompressed
"""
import gzip
decompressed_file = os.path.basename(archive_file.strip('.gz'))
working_dir = os.getcwd()
destination_abspath = os.path.join(working_dir, decompressed_file)
with gzip.open(archive_file, "rb") as f_in:
with open(destination_abspath, "wb") as f_out:
f_out.write(f_in.read())
def decompressor_for(path, extension=None):
"""Get the appropriate decompressor for a path."""
if ((extension and re.match(r'\.?zip$', extension)) or
@@ -30,8 +46,7 @@ def decompressor_for(path, extension=None):
unzip.add_default_arg('-q')
return unzip
if extension and re.match(r'gz', extension):
gunzip = which('gunzip', required=True)
return gunzip
return _gunzip
if extension and re.match(r'bz2', extension):
bunzip2 = which('bunzip2', required=True)
return bunzip2