Code Duplication    Length = 32-34 lines in 2 locations

hansel/cli/cli.py 2 locations

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