Ejemplo n.º 1
0
def run_fork(args):
    patchfns.chdir_to_base_dir()
    top_patch = patchfns.find_top_patch()
    if not top_patch:
        return cmd_result.ERROR
    new_patch = args.arg_new_name if args.arg_new_name else patchfns.next_filename(top_patch)
    new_patch_file = patchfns.patch_file_name(new_patch)
    new_patch_dir = os.path.join(patchfns.QUILT_PC, new_patch)
    if patchfns.patch_in_series(new_patch) or os.path.isdir(new_patch_dir) or os.path.exists(new_patch_file):
        output.error('Patch %s exists already, please choose a new name\n' % patchfns.print_patch(new_patch))
        return cmd_result.ERROR | cmd_result.SUGGEST_RENAME
    is_ok = patchfns.rename_in_db(top_patch, new_patch)
    is_ok = is_ok if not is_ok else patchfns.rename_in_series(top_patch, new_patch)
    if is_ok:
        top_patch_dir = os.path.join(patchfns.QUILT_PC, top_patch)
        try:
            os.rename(top_patch_dir, new_patch_dir)
        except OSError:
            is_ok = False
    if is_ok:
        top_patch_file = patchfns.patch_file_name(top_patch)
        if os.path.exists(top_patch_file):
            try:
                shutil.copy2(top_patch_file, new_patch_file)
            except Exception:
                is_ok = False
    if not is_ok:
        output.write('Fork of patch %s to patch %s failed\n' % (patchfns.print_patch(top_patch), patchfns.print_patch(new_patch)))
    else:
        output.error('Fork of patch %s created as %s\n' % (patchfns.print_patch(top_patch), patchfns.print_patch(new_patch)))
    return cmd_result.OK if is_ok else cmd_result.ERROR
Ejemplo n.º 2
0
def run_rename(args):
    patchfns.chdir_to_base_dir()
    patch = patchfns.find_patch_in_series(args.opt_patch)
    if not patch:
        return cmd_result.ERROR
    new_patch = patchfns.patch_name_base(args.new_name)
    new_patch_exists = patchfns.patch_in_series(new_patch)
    new_patch_exists = True if new_patch_exists else os.path.isdir(os.path.join(patchfns.QUILT_PC, new_patch))
    new_patch_exists = True if new_patch_exists else os.path.exists(patchfns.patch_file_name(new_patch))
    if new_patch_exists:
        output.error('Patch %s exists already, please choose a different name\n' % patchfns.print_patch(new_patch))
        return cmd_result.ERROR
    is_ok = True
    if patchfns.is_applied(patch):
        is_ok = patchfns.rename_in_db(patch, new_patch)
        if is_ok:
            is_ok = move_file(os.path.join(patchfns.QUILT_PC, patch), os.path.join(patchfns.QUILT_PC, new_patch))
    if is_ok:
        is_ok = patchfns.rename_in_series(patch, new_patch)
        if is_ok and os.path.exists(patchfns.patch_file_name(patch)):
            is_ok = move_file(patchfns.patch_file_name(patch), patchfns.patch_file_name(new_patch))
    if is_ok:
        output.write('Patch %s renamed to %s\n' % (patchfns.print_patch(patch), patchfns.print_patch(new_patch)))
        return cmd_result.OK
    else:
        output.error('Renaming of patch %s to %s failed\n' % (patchfns.print_patch(patch), patchfns.print_patch(new_patch)))
        return cmd_result.ERROR