Beispiel #1
0
def make_document_product_label(
    bundle_db: BundleDB,
    info: Citation_Information,
    document_product_lidvid: str,
    bundle_lidvid: str,
    verify: bool,
    publication_date: Optional[str] = None,
) -> bytes:
    """
    Create the label text for the document product in the bundle
    having this :class:`~pdart.pds4.lidvid` using the database
    connection.  If verify is True, verify the label against its XML
    and Schematron schemas.  Raise an exception if either fails.
    """
    bundle = bundle_db.get_bundle(bundle_lidvid)
    proposal_id = bundle.proposal_id
    investigation_lidvid = (
        f"urn:nasa:pds:context:investigation:individual.hst_{proposal_id:05}::1.0"
    )
    title = f"Summary of the observation plan for HST proposal {proposal_id}"

    product_lid = lidvid_to_lid(document_product_lidvid)
    product_vid = lidvid_to_vid(document_product_lidvid)
    publication_date = publication_date or date.today().isoformat()

    product_files: List[File] = bundle_db.get_product_files(document_product_lidvid)
    document_file_basenames = [file.basename for file in product_files]

    try:
        label = (
            make_label(
                {
                    "investigation_lidvid": investigation_lidvid,
                    "product_lid": product_lid,
                    "product_vid": product_vid,
                    "title": title,
                    "publication_date": publication_date,
                    "Citation_Information": make_doc_citation_information(info),
                    "Document_Edition": make_document_edition(
                        "0.0", document_file_basenames
                    ),
                }
            )
            .toxml()
            .encode()
        )
    except Exception as e:
        raise LabelError(document_product_lidvid) from e

    return pretty_and_verify(label, verify)
Beispiel #2
0
def make_checksum_manifest(
    bundle_db: BundleDB, bundle_lidvid: str, lidvid_to_dirpath: _LTD
) -> str:
    files: List[File] = []

    bundle = bundle_db.get_bundle(bundle_lidvid)
    bundle_lidvid = str(bundle.lidvid)
    label_pairs = [
        make_bundle_label_pair(
            bundle_db.get_bundle_label(bundle_lidvid), lidvid_to_dirpath
        )
    ]

    for collection in bundle_db.get_bundle_collections(bundle_lidvid):
        collection_lidvid = str(collection.lidvid)
        label_pairs.append(
            make_collection_label_pair(
                bundle_db.get_collection_label(collection_lidvid), lidvid_to_dirpath
            )
        )
        label_pairs.append(
            make_collection_inventory_pair(
                bundle_db.get_collection_inventory(collection_lidvid),
                lidvid_to_dirpath,
            )
        )
        for product in bundle_db.get_collection_products(collection_lidvid):
            product_lidvid = str(product.lidvid)
            label_pairs.append(
                make_product_label_pair(
                    bundle_db.get_product_label(product_lidvid), lidvid_to_dirpath
                )
            )
            files.extend(bundle_db.get_product_files(product_lidvid))

    for product_label in bundle_db.get_context_product_labels():
        label_pairs.append(make_context_product_pair(product_label, lidvid_to_dirpath))

    file_pairs = [make_checksum_pair(file, lidvid_to_dirpath) for file in files]

    sorted_pairs = sorted(file_pairs + label_pairs)
    return "".join(f"{hash}  {path}\n" for (path, hash) in sorted_pairs)