Code Duplication    Length = 33-35 lines in 2 locations

hansel/cli/cli.py 2 locations

@@ 86-120 (lines=35) @@
83
84
85
86
@cli.command(context_settings=CONTEXT_SETTINGS)
87
@click.argument('src_crumb', type=CrumbPath(), callback=check_not_none)
88
@click.argument('dst_crumb', type=CrumbPath(), callback=check_not_none)
89
@click.option('-q', '--quiet', is_flag=True, flag_value=True,
90
              help='Flag to remove verbose.')
91
@click.option('-e', '--exist_ok', is_flag=True, flag_value=True,
92
              help='Flag to allow overwriting destination path.')
93
@click.option('-i', '--ignore', type=str, multiple=True,
94
              help='A global ignore fnmatch expression for the listing. '
95
                   'You can add as many of this argument as you want. '
96
                   'Example: ".*" or "*~"')
97
def link(src_crumb, dst_crumb, link, quiet, ignore, exist_ok):
98
    """Uses hansel.Crumb to link one file tree to another file tree. The
99
    structure of the destination tree can be modified.
100
    Only the leaf nodes will be linked, the folder structure above will be
101
    created.
102
103
    Examples: \n
104
    crumb link "/data/hansel/cobre/{sid}/{session}/{img}" "/data/hansel/cobre2/{sid}/{img}" \n
105
    crumb link "cobre/{sid}/{session}/{img:anat*}" "cobre_anat/{sid}/{img}" \n
106
    """
107
    from .. import crumb_copy
108
109
    if ignore:
110
        src_crumb._ignore = ignore
111
        dst_crumb._ignore = ignore
112
113
    if not src_crumb.ls():
114
        click.echo('Could not find any file that matched {}.'.format(src_crumb))
115
        exit(-1)
116
117
    crumb_copy(src_crumb, dst_crumb,
118
               make_links=True,
119
               exist_ok=exist_ok,
120
               verbose=(not quiet))
121
122
123
@cli.command(context_settings=CONTEXT_SETTINGS)
@@ 50-82 (lines=33) @@
47
    echo_list(lst)
48
49
50
@cli.command(context_settings=CONTEXT_SETTINGS)
51
@click.argument('src_crumb', type=CrumbPath(), callback=check_not_none)
52
@click.argument('dst_crumb', type=CrumbPath(), callback=check_not_none)
53
@click.option('-q', '--quiet', is_flag=True, flag_value=True,
54
              help='Flag to remove verbose.')
55
@click.option('-e', '--exist_ok', is_flag=True, flag_value=True,
56
              help='Flag to allow overwriting destination path.')
57
@click.option('-i', '--ignore', type=str, multiple=True,
58
              help='A global ignore fnmatch expression for the listing. '
59
                   'You can add as many of this argument as you want. '
60
                   'Example: ".*" or "*~"')
61
def copy(src_crumb, dst_crumb, link, quiet, ignore, exist_ok):
62
    """Uses hansel.Crumb to copy one file tree to another file tree. The
63
    structure of the destination tree can be modified.
64
65
    Examples: \n
66
    crumb copy "/data/hansel/cobre/{sid}/{session}/{img}" "/data/hansel/cobre2/{sid}/{img}" \n
67
    crumb copy "cobre/{sid}/{session}/{img:anat*}" "cobre_anat/{sid}/{img}" \n
68
    """
69
    from .. import crumb_copy
70
71
    if ignore:
72
        src_crumb._ignore = ignore
73
        dst_crumb._ignore = ignore
74
75
    if not src_crumb.ls():
76
        click.echo('Could not find any file that matched {}.'.format(src_crumb))
77
        exit(-1)
78
79
    crumb_copy(src_crumb, dst_crumb,
80
               make_links=False,
81
               exist_ok=exist_ok,
82
               verbose=(not quiet))
83
84
85