Skip to content
Snippets Groups Projects
Commit 040b1bde authored by Janet Goldstein's avatar Janet Goldstein
Browse files

WS-601: Removed unnecessary kludges in manifest and ingestion artifacts creation.

parent 02d1c38d
No related branches found
No related tags found
1 merge request!392WS-601: ancillary products are now added to EVLA CAL manifest
Pipeline #2388 passed
This commit is part of merge request !392. Comments created here will be created in the context of that merge request.
......@@ -188,22 +188,25 @@ class IngestionManifestBuilder:
input_group=self._build_input_group(),
output_group=self._build_evla_cal_output_group(),
)
artifacts_tar = self.write_ingestion_artifacts_tar()
# We can't create the ingestion artifacts tar quite yet,
# because it will contain the yet-to-be-written manifest itself
# (required for ingestion, evidently)
artifacts_file = self.staging_source_dir / self._build_artifacts_filename()
artifacts_ap = AncillaryProduct(
AncillaryProductType.INGESTION_ARTIFACTS, filename=artifacts_tar.name
AncillaryProductType.INGESTION_ARTIFACTS, filename=str(artifacts_file)
)
if not manifest.output_group.ancillary_products:
manifest.output_group.ancillary_products = []
weblog = self.staging_source_dir / WEBLOG_FILENAME
if not weblog.exists():
weblog.touch()
weblog_ap = AncillaryProduct(
type=AncillaryProductType.PIPELINE_WEBLOG_TYPE, filename=WEBLOG_FILENAME
)
manifest.output_group.ancillary_products.append(weblog_ap)
manifest.output_group.ancillary_products.append(artifacts_ap)
manifest_file = manifest.write()
self.write_ingestion_artifacts_tar(artifacts_file)
return manifest, manifest_file
......@@ -225,11 +228,12 @@ class IngestionManifestBuilder:
manifest_file = manifest.write()
artifacts_tar = self.write_ingestion_artifacts_tar()
artifacts_file = self.staging_source_dir / self._build_artifacts_filename()
artifacts_ap = AncillaryProduct(
type=AncillaryProductType.INGESTION_ARTIFACTS, filename=artifacts_tar.name
type=AncillaryProductType.INGESTION_ARTIFACTS, filename=str(artifacts_file)
)
manifest.output_group.ancillary_products.append(artifacts_ap)
self.write_ingestion_artifacts_tar(artifacts_file)
return manifest, manifest_file
......@@ -277,7 +281,7 @@ class IngestionManifestBuilder:
return OutputGroup(science_products=science_products, ancillary_products=ancillary_products)
@staticmethod
def build_artifacts_filename() -> str:
def _build_artifacts_filename() -> str:
"""
Build unique manifest filename in standard format.
......@@ -287,7 +291,7 @@ class IngestionManifestBuilder:
timestamp = format_timestamp(current_time)
return f"{INGESTION_ARTIFACTS_NAME}{timestamp}{TARFILE_EXT}"
def write_ingestion_artifacts_tar(self) -> tarfile.TarFile:
def write_ingestion_artifacts_tar(self, artifacts_path: Path) -> tarfile.TarFile:
"""
Take the list of files and build a tar for inclusion into the archive.
This happens in the staging area for ingestion.
......@@ -296,17 +300,15 @@ class IngestionManifestBuilder:
:return: a .tar archive of the ingestion artifacts
"""
ing_tar = self.staging_source_dir / self.build_artifacts_filename()
with tarfile.open(ing_tar, "w") as ingestion_artifacts_tar:
with tarfile.open(artifacts_path, "w") as ingestion_artifacts_tar:
for file in self.files_found:
if self.sp_type == ScienceProductType.IMAGE:
ingestion_artifacts_tar.add(file)
# include the manifest, which won't exist quite yet; make a dummy
mf_file = self.staging_source_dir / MANIFEST_FILENAME
if not mf_file.exists():
mf_file.touch()
ingestion_artifacts_tar.add(mf_file)
# The manifest file itself is considered an ingestion artifact.
# (It's turtles all the way down.)
manifest_file = self.staging_source_dir / MANIFEST_FILENAME
ingestion_artifacts_tar.add(manifest_file)
return ingestion_artifacts_tar
......
......@@ -119,21 +119,9 @@ class ManifestParameters(ManifestComponentIF):
):
self.telescope = telescope
# TODO this is kludgy; find a way to do this elegantly (or, better yet, not at all)
if isinstance(reingest, bool):
self.reingest = reingest
else:
self.reingest = True if self.reingest else False
if isinstance(ngas_ingest, bool):
self.ngas_ingest = ngas_ingest
else:
self.ngas_ingest = True if self.ngas_ingest else False
if isinstance(calibrate, bool):
self.calibrate = calibrate
else:
self.calibrate = True if self.calibrate else False
self.reingest = reingest
self.ngas_ingest = ngas_ingest
self.calibrate = calibrate
self.staging_source_dir = staging_source_dir
self.additional_metadata = additional_metadata
......@@ -155,7 +143,8 @@ class ManifestParameters(ManifestComponentIF):
def to_json(self) -> JSON:
json_dict = {
ParamsKey.TELESCOPE.value: self.telescope.value,
# TODO de-kludgify
# The ingestion manifest must have "true" and "false"
# rather than "True" and "False"
ParamsKey.REINGEST.value: "true" if self.reingest else "false",
ParamsKey.NGAS_INGEST.value: "true" if self.ngas_ingest else "false",
ParamsKey.CALIBRATE.value: "true" if self.calibrate else "false",
......@@ -243,7 +232,10 @@ class OutputScienceProduct(ManifestComponentIF):
return False
def __str__(self):
return f"{Path(self.filename).name}: {self.type.value}, {len(self.ancillary_products)} ancillary products"
return (
f"{Path(self.filename).name}: {self.type.value}, "
f"{len(self.ancillary_products)} ancillary products"
)
def to_json(self) -> JSON:
json_dict = {"type": self.type.value, "filename": self.filename}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment