Skip to content

Commit

Permalink
add crumb_copy script
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavio committed Sep 1, 2016
1 parent 7959cfe commit 10aa50e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions scripts/crumb_copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!python
"""Uses hansel.Crumb to copy one file tree to another file tree. The
structure of the destination tree can be modified.
Examples:
crumb_copy --link /data/hansel/cobre/{sid}/{session}/{img} /data/hansel/cobre2/{sid}/{img}
crumb_copy cobre/{sid}/{session}/{img:anat*} cobre_anat/{sid}/{img}
"""

def call_crumb_copy(src, dst, **kwargs):
""" Make a Crumb out of `src` and `dst` and call `hansel.crumb_copy`
with these and the extra kwargs parameters."""
from hansel import Crumb, crumb_copy

src_cr = Crumb(src)
dst_cr = Crumb(dst)

crumb_copy(src_cr, dst_cr, **kwargs)


if __name__ == "__main__":
import sys
from argparse import ArgumentParser, RawTextHelpFormatter

defstr = ' (default %(default)s)'
parser = ArgumentParser(prog='crumb_copy',
description=__doc__,
formatter_class=RawTextHelpFormatter)

parser.add_argument('src', metavar='<source crumb path>', type=str,
help='The source crumb path.')
parser.add_argument('dst', metavar='<dest crumb path>', type=str,
help='The destination crumb path')
parser.add_argument('--link', dest='link', default=False, action='store_true',
help='Flag to indicate to whether make links instead of copying.')
parser.add_argument('--quiet', dest='quiet', default=False, action='store_true',
help='Flag to remove verbose.')
parser.add_argument('--exist_ok', dest='exist_ok', default=False, action='store_true',
help='Flag to allow overwriting destination path.')

args = parser.parse_args()

if len(sys.argv) == 1:
parser.print_help()
exit(0)

call_crumb_copy(args.src, args.dst,
make_links=args.link,
exist_ok=args.exist_ok,
verbose=(not args.quiet))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def read(*filenames, **kwargs):

install_requires=['six'],

scripts=[],
scripts=['scripts/crumb_copy'],

long_description=read('README.rst', 'CHANGES.rst'),

Expand Down

0 comments on commit 10aa50e

Please sign in to comment.