Exemplo n.º 1
0
def clean_bag(bag_dir):
    if not is_bag(bag_dir.path):
        LOGGER.warning(_("%s is not a bag. Not cleaning."), bag_dir.path)
        return

    bag = bagit.Bag(bag_dir.path)
    if bag.compare_manifests_with_fs()[1]:
        for payload_file in bag.compare_manifests_with_fs()[1]:
            if grabbags.utils.is_system_file(payload_file):
                LOGGER.info("Removing {}".format(bag_dir.path))
                os.remove(payload_file)
            else:
                LOGGER.warning("Not removing {}".format(bag_dir.path))
Exemplo n.º 2
0
def make_bag(bag_dir, args):
    if is_bag(bag_dir.path):
        LOGGER.warning(_("%s is already a bag. Skipped."), bag_dir.path)
        return

    if args.no_system_files is True:
        LOGGER.info(_("Cleaning %s of system files"), bag_dir.path)
        grabbags.utils.remove_system_files(root=bag_dir.path)

    bag = bagit.make_bag(bag_dir.path,
                         bag_info=args.bag_info,
                         processes=args.processes,
                         checksums=args.checksums)
    successes.append(bag_dir.path)
    LOGGER.info(_("Bagged %s"), bag.path)
Exemplo n.º 3
0
def clean_bag(bag_dir):
    if not is_bag(bag_dir.path):
        LOGGER.warning(_("%s is not a bag. Not cleaning."), bag_dir.path)
        return

    bag = bagit.Bag(bag_dir.path)
    if bag.compare_manifests_with_fs()[1]:
        for payload_file in bag.compare_manifests_with_fs()[1]:
            if grabbags.utils.is_system_file(payload_file):
                LOGGER.info("Removing system files from {}".format(
                    bag_dir.path))
                os.remove(os.path.join(bag_dir.path, payload_file))
            else:
                LOGGER.warning(
                    "Found file not in manifest: {}".format(payload_file))
    else:
        LOGGER.info("No system files located in {}".format(bag_dir.path))
Exemplo n.º 4
0
def make_bag(bag_dir: "os.DirEntry[str]", args):
    if len(os.listdir(bag_dir.path)) == 0:
        LOGGER.warning(_("%s is an empty directory. Skipped."), bag_dir.path)
        return

    if is_bag(bag_dir.path):
        LOGGER.warning(_("%s is already a bag. Skipped."), bag_dir.path)
        return

    if args.no_system_files is True:
        LOGGER.info(_("Cleaning %s of system files"), bag_dir.path)
        grabbags.utils.remove_system_files(root=bag_dir.path)

    bag = bagit.make_bag(bag_dir.path,
                         bag_info=args.bag_info,
                         processes=args.processes,
                         checksums=args.checksums)
    successes.append(bag_dir.path)
    LOGGER.info(_("Bagged %s"), bag.path)
Exemplo n.º 5
0
def validate_bag(bag_dir, args):
    if not is_bag(bag_dir.path):
        LOGGER.warn(_("%s is not a bag. Skipped."), bag_dir.path)
        return

    bag = bagit.Bag(bag_dir.path)
    # validate throws a BagError or BagValidationError
    bag.validate(
        processes=args.processes,
        fast=args.fast,
        completeness_only=args.no_checksums,
    )
    if args.fast:
        LOGGER.info(_("%s valid according to Payload-Oxum"), bag_dir.path)
    elif args.no_checksums:
        LOGGER.info(_("%s valid according to Payload-Oxum and file manifest"),
                    bag_dir.path)
    else:
        LOGGER.info(_("%s is valid"), bag_dir.path)