Skip to content
Snippets Groups Projects
Commit 1f0342a7 authored by pascal.mouquet_ird.fr's avatar pascal.mouquet_ird.fr
Browse files

Merge branch 'remove-products' into 'master'

update functions to remove l1c and l2a products

See merge request espace-dev/sen2chain!4
parents 3e2df5a9 8c6ae1d6
No related branches found
No related tags found
No related merge requests found
Pipeline #685 failed
...@@ -250,8 +250,20 @@ class L1cProduct(Product): ...@@ -250,8 +250,20 @@ class L1cProduct(Product):
self.user_ql = ql_path self.user_ql = ql_path
return 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 # METADATA
@property @property
def product_start_time(self): def product_start_time(self):
return self._get_metadata_value(key="PRODUCT_START_TIME") return self._get_metadata_value(key="PRODUCT_START_TIME")
...@@ -796,6 +808,17 @@ class L2aProduct(Product): ...@@ -796,6 +808,17 @@ class L2aProduct(Product):
sen2chain_processing_version = sen2chain_processing_version, sen2chain_processing_version = sen2chain_processing_version,
sen2cor_version = sen2cor_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 @property
def sen2chain_version(self): def sen2chain_version(self):
......
...@@ -1114,41 +1114,30 @@ class Tile: ...@@ -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]: 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) IndiceProduct(identifier = indice.identifier)
def remove_l1c(self): def remove_l1c(self,
product_list: list = [],
):
""" """
Remove l1c files Remove l1c files
""" """
for product in self.l1c: if not product_list:
l1c = L1cProduct(product.identifier) product_list = [product.identifier for product in self.l1c]
if l1c.path.is_symlink(): for identifier in product_list:
l1c_path = os.readlink(str(l1c.path)) l1c = L1cProduct(identifier)
logger.info("Removing: {}".format(l1c_path)) l1c.remove()
shutil.rmtree(l1c_path) logger.info("Removed: {} products".format(len(product_list)))
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))
def remove_l2a(self, def remove_l2a(self,
identifier_list: list = []): product_list: list = [],
):
""" """
Remove l2a files Remove l2a files
""" """
if not identifier_list: if not product_list:
identifier_list = [product.identifier for product in self.l2a] product_list = [product.identifier for product in self.l2a]
for identifier in identifier_list: for identifier in product_list:
l2a = L2aProduct(identifier) l2a = L2aProduct(identifier)
if l2a.path.is_symlink(): l2a.remove()
l2a_path = os.readlink(str(l2a.path)) logger.info("Removed: {} products".format(len(product_list)))
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)))
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