Exemplo n.º 1
0
def make_context_collection_label(
    bundle_db: BundleDB,
    info: Citation_Information,
    collection_lidvid: str,
    bundle_lidvid: str,
    verify: bool,
    mod_date: str,
) -> bytes:
    """
    Create the label text for the ccontext ollection having this LIDVID using
    the bundle database.  If verify is True, verify the label against
    its XML and Schematron schemas.  Raise an exception if either
    fails.
    """
    # TODO this is sloppy; is there a better way?
    products = bundle_db.get_context_products()
    record_count = len(products)
    if record_count <= 0:
        raise ValueError(f"{collection_lidvid} has no context products.")

    collection_lid = lidvid_to_lid(collection_lidvid)
    collection_vid = lidvid_to_vid(collection_lidvid)
    collection: Collection = bundle_db.get_collection(collection_lidvid)

    proposal_id = bundle_db.get_bundle(bundle_lidvid).proposal_id
    instruments = ",".join(bundle_db.get_instruments_of_the_bundle()).upper()
    title: NodeBuilder = make_context_collection_title(
        {
            "instrument": instruments,
            "proposal_id": str(proposal_id),
        }
    )

    inventory_name = get_collection_inventory_name(bundle_db, collection_lidvid)

    try:
        label = (
            make_label(
                {
                    "collection_lid": collection_lid,
                    "collection_vid": collection_vid,
                    "record_count": record_count,
                    "title": title,
                    "mod_date": mod_date,
                    "proposal_id": str(proposal_id),
                    "Citation_Information": make_citation_information(info),
                    "inventory_name": inventory_name,
                    "Context_Area": combine_nodes_into_fragment([]),
                    "Reference_List": combine_nodes_into_fragment([]),
                    "collection_type": "Context",
                }
            )
            .toxml()
            .encode()
        )
    except Exception as e:
        raise LabelError(collection_lidvid) from e

    return pretty_and_verify(label, verify)
Exemplo n.º 2
0
def make_context_collection_inventory(bundle_db: BundleDB,
                                      collection_lidvid: str) -> bytes:
    """
    Create the inventory text for the collection having this LIDVID
    using the bundle database.
    """
    products = bundle_db.get_context_products()
    inventory_lines: List[str] = [
        f"S,{product.lidvid}\r\n" for product in products
    ]
    res: str = "".join(inventory_lines)
    return res.encode()