def make_schema_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 schema collection 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_schema_products() record_count = len(products) if record_count <= 0: raise ValueError(f"{collection_lidvid} has no schema 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_schema_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": "Schema", } ) .toxml() .encode() ) except Exception as e: raise LabelError(collection_lidvid) from e return pretty_and_verify(label, verify)
def make_schema_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_schema_products() inventory_lines: List[str] = [ f"S,{product.lidvid}\r\n" for product in products ] res: str = "".join(inventory_lines) return res.encode()