From 734232466ff52ebe25a81bd51bcc2144c95325ec Mon Sep 17 00:00:00 2001
From: Impact <pascal.mouquet@ird.fr>
Date: Mon, 16 Nov 2020 10:10:14 +0400
Subject: [PATCH] new remove_l2a() function to remove all tile's l2a products
 from l2a and archive folders

---
 sen2chain/tiles.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sen2chain/tiles.py b/sen2chain/tiles.py
index 5a4a7f8..e5be5ce 100644
--- a/sen2chain/tiles.py
+++ b/sen2chain/tiles.py
@@ -10,6 +10,7 @@ import fiona
 import shutil
 from PIL import Image
 import distutils
+import os
 
 from pathlib import Path
 from collections import namedtuple
@@ -976,5 +977,15 @@ 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_l2a(self):
+        """
+        Remove l2a files
+        """
+        for product in self.l2a:
+            l2a = L2aProduct(product.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()
-- 
GitLab