Exemple #1
0
def copy(src, trg, src_short=None, trg_short=None):
    if not src_short: src_short = src
    if not trg_short: trg_short = trg
    # ask first (if set)
    if ARG.ASKCOPY and not confirm('Copy '+src+' to '+trg_short+'?'):
        write('ignored %s' % src_short)
        return 0
    # check if target dir tree exists
    trg_tree = '/'.join(trg.split('/')[:-1])
    if not os.path.exists(trg_tree) and not create_dir(trg_tree):
        return 0
    # get items matching pattern, set counter
    src_items = glob.glob(src)
    counter = 0
    # copy each matched item
    for src_item in src_items:
        counter += copy_item(src_item, trg, trg_short=trg_short)
    return counter
Exemple #2
0
def remove(path, path_short=None, isdir=False):
    # set shortened path if not given
    if not path_short: path_short = path
    # remove file, but ask first (if set)
    if not ARG.ASKREMOVE or confirm('Remove '+path_short+'?'):
        # create arg list
        args = ['rm']
        if isdir: args.append('-r')
        args.append(path)
        # combine into command, execute
        cmd = ' '.join(args)
        retcode, output = file_op(cmd)
        # check return code
        if retcode == 0:
            write('removed '+path_short)
        else:
            write('failed: '+cmd)
            write(output)
        return (retcode == 0)
    return False