Ejemplo n.º 1
0
def run_edit(args):
    patchfns.chdir_to_base_dir()
    if patchfns.pyquilt_command('add %s' % ' '.join(args.filelist)) not in [0, 2]:
        return cmd_result.ERROR
    efilelist = args.filelist if not patchfns.SUBDIR else [os.path.join(patchfns.SUBDIR, fnm) for fnm in args.filelist]
    os.environ['LANG'] = patchfns.ORIGINAL_LANG
    result = shell.run_cmd('%s %s' % (os.getenv('EDITOR'), ' '.join(efilelist)))
    output.error(result.stderr)
    output.write(result.stdout)
    status = cmd_result.OK if result.eflags == 0 else cmd_result.ERROR
    for filename in args.filelist:
        efname = filename if not patchfns.SUBDIR else os.path.join(patchfns.SUBDIR, filename)
        if not os.path.exists(efname):
            patchfns.pyquilt_command('revert %s' % filename)
            status = cmd_result.ERROR
    return status
Ejemplo n.º 2
0
def run_delete(args):
    patchfns.chdir_to_base_dir()
    if args.patch:
        patch = patchfns.find_patch(args.patch)
        if not patch:
            return cmd_result.ERROR
    else:
        patch = patchfns.top_patch()
    if args.opt_next:
        patch =patchfns.patch_after(patch)
        if not patch:
            output.error('No next patch\n')
            return cmd_result.ERROR
    if not patch:
        patchfns.find_top_patch()
        return cmd_result.ERROR
    if patchfns.is_applied(patch):
        if patch != patchfns.top_patch():
            output.error('Patch %s is currently applied\n' % patchfns.print_patch(patch))
            return cmd_result.ERROR
        if patchfns.pyquilt_command('pop -qf') != cmd_result.OK:
            return cmd_result.ERROR
    if patchfns.remove_from_series(patch):
        output.write('Removed patch %s\n' % patchfns.print_patch(patch))
    else:
        output.error('Failed to remove patch %s\n' % patchfns.print_patch(patch))
        return cmd_result.ERROR
    patch_file = patchfns.patch_file_name(patch)
    if args.opt_remove and os.path.exists(patch_file):
        if args.opt_backup:
            try:
                os.rename(patch_file, patch_file + '~')
            except IOError:
                output.error('Failed to backup patch file %s\n' % patch_file)
                return cmd_result.ERROR
        else:
            try:
                os.remove(patch_file)
            except IOError:
                output.error('Failed to remove patch file %s\n' % patch_file)
                return cmd_result.ERROR
    return cmd_result.OK