Skip to content
Snippets Groups Projects
Commit f879120a authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

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

projects
parent 54507efa
No related branches found
No related tags found
No related merge requests found
......@@ -5,5 +5,12 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""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
https://packaging.python.org/guides/packaging-namespace-packages/ for
details.
"""
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # noqa
#!/usr/bin/env python
#
# imrm.py - Remove image files.
#
# Author: Paul McCarthy <paulmc@fmrib.ox.ac.uk>
#
"""This module defines the ``imrm`` application, for removing NIFTI image
files.
"""
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 atlasq.py for explanation
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
import fsl.data.image as fslimage
usage = """Usage: {} <list of image names to remove>
NB: filenames can be basenames or not
""".strip()
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])
print(usage.format(exe))
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):
os.remove(path)
return 0
if __name__ == '__main__':
sys.exit(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment