diff --git a/sen2chain/config.py b/sen2chain/config.py index 53a639b940626d25c40617a92f19a6438b2d6c7a..b6ca55c9dce9a3d522903a90e8aa1f82156ddf3b 100644 --- a/sen2chain/config.py +++ b/sen2chain/config.py @@ -44,6 +44,7 @@ class Config: "l1c_path": "", "l1c_archive_path": "/ARCHIVE_SENTINEL-PROD/S2_L1C_ARCHIVE", "l2a_path": "", + "l2a_archive_path": "/ARCHIVE_SENTINEL-PROD/S2_L2A_ARCHIVE", "indices_path": "", "time_series_path": "", "monthly_summaries_path": ""} diff --git a/sen2chain/tiles.py b/sen2chain/tiles.py index 1f358d618dfa1d92efe8625081b9a056bc1b3e81..a796a429d4fcf3b5ec483972b877f017fb706606 100644 --- a/sen2chain/tiles.py +++ b/sen2chain/tiles.py @@ -333,11 +333,19 @@ class Tile: #~ logger.info("Product: local / archived / total".format(human_size(getFolderSize(str(self.paths['l1c']))))) local = getFolderSize(str(self.paths["l1c"])) total = getFolderSize(str(self.paths["l1c"]), True) - logger.info("l1c: {} (l: {} / a: {})".format(human_size(total), + logger.info("l1c: {} (local: {} / archived: {})".format(human_size(total), human_size(local), human_size(total-local), )) - logger.info("l2a: {}".format(human_size(getFolderSize(str(self.paths["l2a"]), True)))) + + #~ logger.info("l2a: {}".format(human_size(getFolderSize(str(self.paths["l2a"]), True)))) + local = getFolderSize(str(self.paths["l2a"])) + total = getFolderSize(str(self.paths["l2a"]), True) + logger.info("l2a: {} (local: {} / archived: {})".format(human_size(total), + human_size(local), + human_size(total-local), + )) + for indice, path in self._paths["indices"].items(): logger.info("{}: {}".format(indice, human_size(getFolderSize(str(path), True)))) @@ -516,4 +524,33 @@ class Tile: if not count: logger.info("No L1C products to archive") + def archive_l2a(self): + """ + Check and move l1c products to archive folder + """ + + if (self.clean_lib()['identified_problems']-self.clean_lib()['removed_problems']) == 0: + logger.info("No tile error processing l2a archive") + + l2a_archive_path = Path(Config().get("l2a_archive_path")) + + prod_list = self.l2a + + if prod_list: + count = 0 + for prod in prod_list: + l2a = L2aProduct(prod.identifier) + if not l2a.path.is_symlink(): + count += 1 + move_path = l2a_archive_path / l2a.tile / l2a.path.name + logger.info("archiving {}".format(l2a.identifier)) + move_path.parent.mkdir(exist_ok=True) + shutil.move(str(l2a.path), str(move_path.parent)) + l2a.path.symlink_to(move_path, target_is_directory = True) + logger.info("{} products archived".format(count)) + else: + logger.info("No L2A products, nothing to archive") + else: + logger.info("Error(s) in l2a product(s) please correct them running clean_lib(remove=True) before archiving") +