diff --git a/sen2chain/products.py b/sen2chain/products.py index 1ae304788868c4993e8e9908e1f3654bfac9b713..594b30ad05a60d8c262ad462c14703e790efebe5 100755 --- a/sen2chain/products.py +++ b/sen2chain/products.py @@ -250,8 +250,20 @@ class L1cProduct(Product): self.user_ql = ql_path return ql_path + + def remove(self): + if self.path.is_symlink(): + l1c_path = os.readlink(str(self.path)) + logger.info("Removing: {}".format(l1c_path)) + shutil.rmtree(l1c_path) + logger.info("Removing symlink: {}".format(self.path)) + self.path.unlink() + else: + #~ l1c_path = os.readlink(str(l1c.path)) + logger.info("Removing: {}".format(self.path)) + shutil.rmtree(str(self.path)) + # METADATA - @property def product_start_time(self): return self._get_metadata_value(key="PRODUCT_START_TIME") @@ -796,6 +808,17 @@ class L2aProduct(Product): sen2chain_processing_version = sen2chain_processing_version, sen2cor_version = sen2cor_version) + def remove(self): + if self.path.is_symlink(): + l2a_path = os.readlink(str(self.path)) + logger.info("Removing: {}".format(l2a_path)) + shutil.rmtree(l2a_path) + logger.info("Removing symlink: {}".format(self.path)) + self.path.unlink() + else: + logger.info("Removing: {}".format(self.path)) + shutil.rmtree(str(self.path)) + logger.info("Removing: {}".format(self.path)) @property def sen2chain_version(self): diff --git a/sen2chain/tiles.py b/sen2chain/tiles.py index 6c4499ceade1fda09330230e53363baa286c06a2..e0053c56c636d338d30ca87aa71e2a0dd36c94b3 100644 --- a/sen2chain/tiles.py +++ b/sen2chain/tiles.py @@ -1114,41 +1114,30 @@ class Tile: for indice in [val for sublist in [getattr(self, i) for i in [p for p in self.paths["indices"]]] for val in sublist]: IndiceProduct(identifier = indice.identifier) - def remove_l1c(self): + def remove_l1c(self, + product_list: list = [], + ): """ Remove l1c files """ - for product in self.l1c: - l1c = L1cProduct(product.identifier) - if l1c.path.is_symlink(): - l1c_path = os.readlink(str(l1c.path)) - logger.info("Removing: {}".format(l1c_path)) - shutil.rmtree(l1c_path) - logger.info("Removing symlink: {}".format(l1c.path)) - l1c.path.unlink() - else: - #~ l1c_path = os.readlink(str(l1c.path)) - logger.info("Removing: {}".format(l1c.path)) - shutil.rmtree(str(l1c.path)) + if not product_list: + product_list = [product.identifier for product in self.l1c] + for identifier in product_list: + l1c = L1cProduct(identifier) + l1c.remove() + logger.info("Removed: {} products".format(len(product_list))) + def remove_l2a(self, - identifier_list: list = []): + product_list: list = [], + ): """ Remove l2a files """ - if not identifier_list: - identifier_list = [product.identifier for product in self.l2a] - for identifier in identifier_list: + if not product_list: + product_list = [product.identifier for product in self.l2a] + for identifier in product_list: l2a = L2aProduct(identifier) - if l2a.path.is_symlink(): - l2a_path = os.readlink(str(l2a.path)) - logger.info("Removing: {}".format(l2a_path)) - shutil.rmtree(l2a_path) - logger.info("Removing symlink: {}".format(l2a.path)) - l2a.path.unlink() - else: - logger.info("Removing: {}".format(l2a.path)) - shutil.rmtree(str(l2a.path)) - logger.info("Removing: {}".format(l2a.path)) - logger.info("Removed: {} products".format(len(identifier_list))) + l2a.remove() + logger.info("Removed: {} products".format(len(product_list)))