diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2021-04-28 17:00:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-28 17:00:58 +0200 |
commit | 5b12568c4f17fb9914be9e903eff3aad007049ef (patch) | |
tree | df2b27d70195f7ba3adf8b805df89fa1c8f79151 /lib | |
parent | 5cb5aac57e10c0a5005501c153e1f7df387f62df (diff) | |
download | spack-5b12568c4f17fb9914be9e903eff3aad007049ef.tar.gz spack-5b12568c4f17fb9914be9e903eff3aad007049ef.tar.bz2 spack-5b12568c4f17fb9914be9e903eff3aad007049ef.tar.xz spack-5b12568c4f17fb9914be9e903eff3aad007049ef.zip |
Make Spack able to apply gz compressed remote patches (#22823)
Modified ncbi-rmblastn to retrieve patches from remote
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/fetch_strategy.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/util/compression.py | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index ff41c759ea..b5ce8495e3 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -467,6 +467,8 @@ class URLFetchStrategy(FetchStrategy): 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) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index 2f190e94e1..a1a0e1d6f3 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -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 |