Example #1
0
def run_add(args):
    patchfns.chdir_to_base_dir()
    patch = patchfns.find_applied_patch(args.opt_patch)
    if not patch:
        return 1
    patch_dir = os.path.join(patchfns.QUILT_PC, patch)
    status = 0
    for filename in args.filelist:
        filename = patchfns.filename_rel_base(filename)
        if not patchfns.in_valid_dir(filename):
            status = 1
            continue
        if patchfns.file_in_patch(patch, filename):
            output.error('File %s is already in patch %s\n' % (filename, patchfns.print_patch(patch)))
            status = 2 if status != 1 else 1
        next_patch = patchfns.next_patch_for_file(patch, filename)
        if next_patch is not None:
            output.error('File %s modified by patch %s\n' % (filename, patchfns.print_patch(next_patch)))
            status = 1
            continue
        if os.path.islink(filename):
            output.error('Cannot add symbolic link %s\n' % filename)
            status = 1
            continue
        if not backup.backup(patch_dir, [filename]):
            output.error('Failed to back up file %s\n' % filename)
            status = 1
            continue
        if os.path.exists(filename):
            # The original tree may be read-only.
            os.chmod(filename, os.stat(filename).st_mode|stat.S_IWUSR)
        output.write('File %s added to patch %s\n' % (filename, patchfns.print_patch(patch)))
    return status
Example #2
0
def run_snapshot(args):
    patchfns.chdir_to_base_dir()
    snap_subdir = '.snap'
    snap_subdir_path = os.path.join(patchfns.QUILT_PC, snap_subdir)
    if os.path.exists(snap_subdir_path):
        shutil.rmtree(snap_subdir_path)
    if args.opt_remove:
        return cmd_result.OK
    os.makedirs(snap_subdir_path)
    files = []
    for patch in patchfns.applied_patches():
        files += patchfns.files_in_patch(patch)
    # Use set functionality to remove duplicates
    result = backup.backup(snap_subdir_path, set(files))
    return cmd_result.OK if result else cmd_result.ERROR