def inmeta_to_string()

in gnm_deliverables/inmeta.py [0:0]


def inmeta_to_string(asset:DeliverableAsset, platform:str)->str:
    content = make_doc(asset, platform)

    if content is None:
        logger.error("Could not make content doc?")
        raise RuntimeError("Could not make content doc")

    if asset.online_item_id:
        safe_filename = asset.online_item_id
    elif asset.nearline_item_id:
        safe_filename = asset.nearline_item_id
    else:
        safe_filename = re.sub(r'\s+',"_", asset.filename)

    if safe_filename == "":
        logger.error("Could not determine a filename for asset {0} - no online id, nearline id or filename available!".format(asset.id))
        raise ValueError("Could not determine a filename")

    xml_content = ET.tostring(content, "UTF-8")
    if isinstance(xml_content, bytes):
        return xml_content.decode("UTF-8")
    else:
        return xml_content