Commit 5d644d61 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Wrapper scripts around immv/imcp functions.

parent 66786d0d
#!/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()
#!/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()
......@@ -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'),
]
)
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