Esempio n. 1
0
        opt.create, opt.list, opt.extract, opt.start_extract,
        opt.finish_extract, opt.edit
    ]
])
if action_count > 1:
    o.fatal("bup: only one action permitted: --create --list --extract --edit")
if action_count == 0:
    o.fatal("bup: no action specified")

if opt.create:
    if len(remainder) < 1:
        o.fatal("no paths specified for create")
    output_file = open_output(opt.file)
    metadata.save_tree(output_file,
                       remainder,
                       recurse=opt.recurse,
                       write_paths=opt.paths,
                       save_symlinks=opt.symlinks,
                       xdev=opt.xdev)
elif opt.list:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --list")
    src = open_input(opt.file)
    metadata.display_archive(src)
elif opt.start_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --start-extract")
    src = open_input(opt.file)
    metadata.start_extract(src, create_symlinks=opt.symlinks)
elif opt.finish_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --finish-extract")
Esempio n. 2
0
File: meta-cmd.py Progetto: 3v/bup
action_count = sum([bool(x) for x in [opt.create, opt.list, opt.extract,
                                      opt.start_extract, opt.finish_extract,
                                      opt.edit]])
if action_count > 1:
    o.fatal("bup: only one action permitted: --create --list --extract --edit")
if action_count == 0:
    o.fatal("bup: no action specified")

if opt.create:
    if len(remainder) < 1:
        o.fatal("no paths specified for create")
    output_file = open_output(opt.file)
    metadata.save_tree(output_file,
                       remainder,
                       recurse=opt.recurse,
                       write_paths=opt.paths,
                       save_symlinks=opt.symlinks,
                       xdev=opt.xdev)
elif opt.list:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --list")
    src = open_input(opt.file)
    metadata.display_archive(src)
elif opt.start_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --start-extract")
    src = open_input(opt.file)
    metadata.start_extract(src, create_symlinks=opt.symlinks)
elif opt.finish_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --finish-extract")
Esempio n. 3
0
        opt.create, opt.list, opt.extract, opt.start_extract,
        opt.finish_extract, opt.edit
    ]
])
if action_count > 1:
    o.fatal("bup: only one action permitted: --create --list --extract --edit")
if action_count == 0:
    o.fatal("bup: no action specified")

if opt.create:
    if len(remainder) < 1:
        o.fatal("no paths specified for create")
    output_file = open_output(opt.file)
    metadata.save_tree(output_file, [argv_bytes(r) for r in remainder],
                       recurse=opt.recurse,
                       write_paths=opt.paths,
                       save_symlinks=opt.symlinks,
                       xdev=opt.xdev)
elif opt.list:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --list")
    src = open_input(opt.file)
    metadata.display_archive(src, open_output(b'-'))
elif opt.start_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --start-extract")
    src = open_input(opt.file)
    metadata.start_extract(src, create_symlinks=opt.symlinks)
elif opt.finish_extract:
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --finish-extract")
Esempio n. 4
0
def main(argv):

    o = options.Options(optspec)
    opt, flags, remainder = o.parse_bytes(
        [b'--paths', b'--symlinks', b'--recurse'] + argv[1:])

    opt.verbose = opt.verbose or 0
    opt.quiet = opt.quiet or 0
    metadata.verbose = opt.verbose - opt.quiet
    opt.file = argv_bytes(opt.file) if opt.file else None

    action_count = sum([
        bool(x) for x in [
            opt.create, opt.list, opt.extract, opt.start_extract,
            opt.finish_extract, opt.edit
        ]
    ])
    if action_count > 1:
        o.fatal(
            "bup: only one action permitted: --create --list --extract --edit")
    if action_count == 0:
        o.fatal("bup: no action specified")

    if opt.create:
        if len(remainder) < 1:
            o.fatal("no paths specified for create")
        output_file = open_output(opt.file)
        metadata.save_tree(output_file, [argv_bytes(r) for r in remainder],
                           recurse=opt.recurse,
                           write_paths=opt.paths,
                           save_symlinks=opt.symlinks,
                           xdev=opt.xdev)
    elif opt.list:
        if len(remainder) > 0:
            o.fatal("cannot specify paths for --list")
        src = open_input(opt.file)
        metadata.display_archive(src, open_output(b'-'))
    elif opt.start_extract:
        if len(remainder) > 0:
            o.fatal("cannot specify paths for --start-extract")
        src = open_input(opt.file)
        metadata.start_extract(src, create_symlinks=opt.symlinks)
    elif opt.finish_extract:
        if len(remainder) > 0:
            o.fatal("cannot specify paths for --finish-extract")
        src = open_input(opt.file)
        metadata.finish_extract(src, restore_numeric_ids=opt.numeric_ids)
    elif opt.extract:
        if len(remainder) > 0:
            o.fatal("cannot specify paths for --extract")
        src = open_input(opt.file)
        metadata.extract(src,
                         restore_numeric_ids=opt.numeric_ids,
                         create_symlinks=opt.symlinks)
    elif opt.edit:
        if len(remainder) < 1:
            o.fatal("no paths specified for edit")
        output_file = open_output(opt.file)

        unset_user = False  # True if --unset-user was the last relevant option.
        unset_group = False  # True if --unset-group was the last relevant option.
        for flag in flags:
            if flag[0] == '--set-user':
                unset_user = False
            elif flag[0] == '--unset-user':
                unset_user = True
            elif flag[0] == '--set-group':
                unset_group = False
            elif flag[0] == '--unset-group':
                unset_group = True

        for path in remainder:
            f = open(argv_bytes(path), 'rb')
            try:
                for m in metadata._ArchiveIterator(f):
                    if opt.set_uid is not None:
                        try:
                            m.uid = int(opt.set_uid)
                        except ValueError:
                            o.fatal("uid must be an integer")

                    if opt.set_gid is not None:
                        try:
                            m.gid = int(opt.set_gid)
                        except ValueError:
                            o.fatal("gid must be an integer")

                    if unset_user:
                        m.user = b''
                    elif opt.set_user is not None:
                        m.user = argv_bytes(opt.set_user)

                    if unset_group:
                        m.group = b''
                    elif opt.set_group is not None:
                        m.group = argv_bytes(opt.set_group)

                    m.write(output_file)
            finally:
                f.close()

    if saved_errors:
        log('WARNING: %d errors encountered.\n' % len(saved_errors))
        sys.exit(1)
    else:
        sys.exit(0)
Esempio n. 5
0
    elif flag == '--quiet' or flag == '-q':
        metadata.verbose = 0

if not action:
    o.fatal("no action specified")

if action == 'create':
    if len(remainder) < 1:
        o.fatal("no paths specified for create")
    if target_filename != '-':
        output_file = open(target_filename, 'w')
    else:
        output_file = sys.stdout
    metadata.save_tree(output_file,
                       remainder,
                       recurse=should_recurse,
                       write_paths=include_paths,
                       save_symlinks=handle_symlinks,
                       xdev=xdev)

elif action == 'list':
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --list")
    if target_filename != '-':
        src = open(target_filename, 'r')
    else:
        src = sys.stdin
    metadata.display_archive(src)

elif action == 'start-extract':
    if len(remainder) > 0:
        o.fatal("cannot specify paths for --start-extract")