Commit f879120a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

ENH: New imrm script. fsl.scripts package is pkgutils, so can be used by other

parent 54507efa
......@@ -5,5 +5,12 @@
# Author: Paul McCarthy <>
"""The ``fsl.scripts`` package contains all of the executable scripts provided
by ``fslpy``.
by ``fslpy``, and other python-based FSL packages.
.. note:: The ``fsl.scripts`` namespace is a ``pkgutil``-style *namespace
package* - it can be used across different projects - see for
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # noqa
#!/usr/bin/env python
# - Remove image files.
# Author: Paul McCarthy <>
"""This module defines the ``imrm`` application, for removing NIFTI image
from __future__ import print_function
import itertools as it
import os.path as op
import os
import sys
import warnings
import contextlib
import fsl.utils.path as fslpath
# See for explanation
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
import as fslimage
usage = """Usage: {} <list of image names to remove>
NB: filenames can be basenames or not
ALLOWED_EXTENSIONS = fslimage.ALLOWED_EXTENSIONS + ['.mnc', '.mnc.gz']
"""List of file extensions that are removed by ``imrm``. """
def main(argv=None):
"""Removes all images which are specified on the command line. """
if argv is None:
argv = sys.argv
if len(argv) < 2:
exe = op.abspath(argv[0])
return 1
prefixes = [fslpath.removeExt(p, ALLOWED_EXTENSIONS) for p in argv[1:]]
for prefix, ext in it.product(prefixes, ALLOWED_EXTENSIONS):
path = f'{prefix}{ext}'
if op.exists(path):
return 0
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment