def add_delivery_report_to_hk( self, delivery_report_file: Path, hk_api: HousekeeperAPI, case_id: str, analysis_date: datetime, ) -> Optional[housekeeper.store.models.File]: """ Add a delivery report to a analysis bundle for a case in Housekeeper If there is already a delivery report for the bundle doesn't add to it If successful the method returns a pointer to the new file in Housekeeper """ delivery_report_tag_name = "delivery-report" version_obj = hk_api.version(case_id, analysis_date) is_bundle_missing_delivery_report = False try: self.get_delivery_report_from_hk(hk_api=hk_api, case_id=case_id) except FileNotFoundError: is_bundle_missing_delivery_report = True if is_bundle_missing_delivery_report: file_obj = hk_api.add_file( delivery_report_file.name, version_obj, delivery_report_tag_name ) hk_api.include_file(file_obj, version_obj) hk_api.add_commit(file_obj) return file_obj return None
def ensure_hk_bundle( store: HousekeeperAPI, bundle_data: dict, include: bool = False ) -> hk_models.Bundle: """Utility function to add a bundle of information to a housekeeper api""" bundle_exists = False for bundle in store.bundles(): if bundle.name != bundle_data["name"]: continue bundle_exists = True _bundle = bundle break if not bundle_exists: _bundle, _version = store.add_bundle(bundle_data) store.add_commit(_bundle, _version) if include: store.include(_version) return _bundle