diff --git a/bin/imcp b/bin/imcp new file mode 100755 index 0000000000000000000000000000000000000000..bef56cc742801db86c5498bdefe115be59b71ea7 --- /dev/null +++ b/bin/imcp @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# +# immv.py - Copy image files. +# +# Author: Paul McCarthy <paulmc@fmrib.ox.ac.uk> +# + + +from __future__ import print_function + +import os.path as op +import sys +import fsl.utils.path as fslpath + + +SUPPORTED_EXTENSIONS = [ + '.nii', '.nii.gz', + '.hdr', '.hdr.gz', + '.img', '.img.gz', + '.mnc', '.mnc.gz' +] + + +FILE_GROUPS = [ + ('.img', '.hdr'), + ('.img.gz', '.hdr.gz') +] + + +usage = """Usage: + imcp <file1> <file2> + imcp <file1> <directory> + imcp <file1> <file2> ... <fileN> <directory> + +Copy images from <file1> to <file2>, or copy all <file>s to <directory> + +NB: filenames can be basenames or include an extension. + +Recognised file extensions: {} +""".format(', '.join(SUPPORTED_EXTENSIONS)) + + +def main(): + """Parses CLI arguments (see the usage string), and calls the + fsl.utils.path.imcp function on each input. + """ + + if len(sys.argv) < 2: + print(usage) + sys.exit(1) + + srcs = sys.argv[1:-1] + dest = sys.argv[ -1] + + if len(srcs) > 1 and not op.isdir(dest): + print(usage) + sys.exit(1) + + for src in srcs: + try: + fslpath.imcp(src, + dest, + allowedExts=SUPPORTED_EXTENSIONS, + fileGroups=FILE_GROUPS) + + except Exception as e: + print(e) + break + + +if __name__ == '__main__': + main() diff --git a/bin/immv b/bin/immv new file mode 100755 index 0000000000000000000000000000000000000000..6054693e4fd89245584185c562b70db3fb41610a --- /dev/null +++ b/bin/immv @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# +# immv.py - Move image files. +# +# Author: Paul McCarthy <paulmc@fmrib.ox.ac.uk> +# + + +from __future__ import print_function + +import os.path as op +import sys +import fsl.utils.path as fslpath + + +SUPPORTED_EXTENSIONS = [ + '.nii', '.nii.gz', + '.hdr', '.hdr.gz', + '.img', '.img.gz', + '.mnc', '.mnc.gz' +] + + + +FILE_GROUPS = [ + ('.img', '.hdr'), + ('.img.gz', '.hdr.gz') +] + + +usage = """Usage: + immv <file1> <file2> + immv <file1> <directory> + immv <file1> <file2> ... <fileN> <directory> + +Moves images from <file1> to <file2>, or move all <file>s to <directory> + +NB: filenames can be basenames or include an extension. + +Recognised file extensions: {} +""".format(', '.join(SUPPORTED_EXTENSIONS)) + + +def main(): + """Parses CLI arguments (see the usage string), and calls the + fsl.utils.path.immv function on each input. + """ + + if len(sys.argv) < 2: + print(usage) + sys.exit(1) + + srcs = sys.argv[1:-1] + dest = sys.argv[ -1] + + if len(srcs) > 1 and not op.isdir(dest): + print(usage) + sys.exit(1) + + for src in srcs: + try: + fslpath.immv(src, + dest, + allowedExts=SUPPORTED_EXTENSIONS, + fileGroups=FILE_GROUPS) + + except Exception as e: + print(e) + break + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 932946572238283e11f053536c54e262598ff9b6..0b8573d8c295b629c51ad6d466d5db78d50b8941 100644 --- a/setup.py +++ b/setup.py @@ -59,4 +59,9 @@ setup( setup_requires=['pytest-runner'], tests_require=['pytest', 'pytest-runner'], test_suite='tests', + + scripts=[ + op.join('bin', 'imcp'), + op.join('bin', 'immv'), + ] )