From 750ef59c911a0350c6f3fdb81a166fde97d6457a Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Wed, 7 Aug 2024 10:48:28 -0500 Subject: [PATCH] - This will allow input to not fail if at least 1 input granule produces a .dmrpp file. --- dmrpp_generator/main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dmrpp_generator/main.py b/dmrpp_generator/main.py index bcbcb1b..91d3588 100644 --- a/dmrpp_generator/main.py +++ b/dmrpp_generator/main.py @@ -107,6 +107,8 @@ def process(self): collection_files = collection.get('files', []) buckets = self.config.get('buckets') granules = self.input['granules'] + + output_generated = False for granule in granules: dmrpp_files = [] for file_ in granule['files']: @@ -119,6 +121,9 @@ def process(self): input_file_path = file_.get('filename', f's3://{file_["bucket"]}/{file_["key"]}') output_file_paths = self.dmrpp_generate(input_file=input_file_path, dmrpp_meta=self.dmrpp_meta) + if not output_generated and len(output_file_paths) > 0: + output_generated = True + for output_file_path in output_file_paths: if output_file_path: output_file_basename = os.path.basename(output_file_path) @@ -131,17 +136,16 @@ def process(self): } dmrpp_files.append(dmrpp_file) self.upload_file_to_s3(output_file_path, f's3://{dmrpp_file["bucket"]}/{dmrpp_file["key"]}') + + if len(dmrpp_files) == 0: + self.logger_to_cw.warning(f'No dmrpp files were produced for {granule}') - if len(dmrpp_files) == 0: - message = f'No dmrpp files were produced for {granule}' - if self.verify_output: - raise Exception(message) - else: - self.logger_to_cw.warning(message) - self.strip_old_dmrpp_files(granule) granule['files'] += dmrpp_files + if self.verify_output and not output_generated: + raise Exception('No dmrpp files were produced and verify_output was enabled.') + return self.input @staticmethod