Skip to content

FIX/TEST: Gunzip cleanup and test #2564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,32 @@ class GunzipOutputSpec(TraitedSpec):

class Gunzip(BaseInterface):
"""Gunzip wrapper

>>> from nipype.algorithms.misc import Gunzip
>>> gunzip = Gunzip(in_file='tpms_msk.nii.gz')
>>> res = gunzip.run()
>>> res.outputs.out_file # doctest: +ELLIPSIS
'.../tpms_msk.nii'

.. testcleanup::

>>> os.unlink('tpms_msk.nii')
"""
input_spec = GunzipInputSpec
output_spec = GunzipOutputSpec

def _gen_output_file_name(self):
_, base, ext = split_filename(self.inputs.in_file)
if ext[-2:].lower() == ".gz":
if ext[-3:].lower() == ".gz":
ext = ext[:-3]
return os.path.abspath(base + ext[:-3])
return os.path.abspath(base + ext)

def _run_interface(self, runtime):
import gzip
import shutil
with gzip.open(self.inputs.in_file, 'rb') as in_file:
with open(self._gen_output_file_name(), 'wb') as out_file:
out_file.write(in_file.read())
shutil.copyfileobj(in_file, out_file)
return runtime

def _list_outputs(self):
Expand Down