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

ENH: new remove_ext script, minor adjustments to imrm

parent e430a1bc
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ with warnings.catch_warnings():
import fsl.data.image as fslimage
usage = """Usage: {} <list of image names to remove>
usage = """Usage: imrm <list of image names to remove>
NB: filenames can be basenames or not
""".strip()
......@@ -36,14 +36,13 @@ def main(argv=None):
"""Removes all images which are specified on the command line. """
if argv is None:
argv = sys.argv
argv = sys.argv[1:]
if len(argv) < 2:
exe = op.abspath(argv[0])
print(usage.format(exe))
if len(argv) < 1:
print(usage)
return 1
prefixes = [fslpath.removeExt(p, ALLOWED_EXTENSIONS) for p in argv[1:]]
prefixes = [fslpath.removeExt(p, ALLOWED_EXTENSIONS) for p in argv]
for prefix, ext in it.product(prefixes, ALLOWED_EXTENSIONS):
......
#!/usr/bin/env python
#
# remove_ext.py - Remove file extensions from NIFTI image paths
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import sys
import warnings
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: remove_ext <list of image paths to remove extension from>
""".strip()
ALLOWED_EXTENSIONS = fslimage.ALLOWED_EXTENSIONS + ['.mnc', '.mnc.gz']
"""List of file extensions that are removed by ``remove_ext``. """
def main(argv=None):
"""Removes file extensions from all paths which are specified on the
command line.
"""
if argv is None:
argv = sys.argv[1:]
if len(argv) < 1:
print(usage)
return 1
removed = []
for path in argv:
removed.append(fslpath.removeExt(path, ALLOWED_EXTENSIONS))
print(' '.join(removed))
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