From d98b484b8ceddfc764fba2651dc1c6bcfb2dd91c Mon Sep 17 00:00:00 2001
From: Fabian Schindler <fabian.schindler.strauss@gmail.com>
Date: Tue, 9 Feb 2021 10:12:32 +0100
Subject: [PATCH] Fixing Sentinel-2 registration schema

---
 core/registrar/scheme.py | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/core/registrar/scheme.py b/core/registrar/scheme.py
index 959c3f22..4df6e5c3 100644
--- a/core/registrar/scheme.py
+++ b/core/registrar/scheme.py
@@ -12,6 +12,7 @@ from .exceptions import RegistrationError
 
 logger = logging.getLogger(__name__)
 
+
 class RegistrationScheme:
     def get_context(self) -> List[Context]:
         raise NotImplementedError
@@ -36,8 +37,7 @@ def parse_footprint(value):
 
 
 class Sentinel2RegistrationScheme(RegistrationScheme):
-    name = 'sentinel-2-l2a'
-
+    name = 'sentinel-2'
 
     MTD_SCHEMAS = {
         'MSIL1C': {
@@ -94,19 +94,19 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
     def get_context(self, source: Source, path: str) -> List[Context]:
         try:
             metadata_file = join(path, 'MTD_MSIL2A.xml')
-            mtd_schema = MTD_SCHEMAS['MSIL2A']
-            mtd_namespaces = MTD_NAMESPACES['MSIL2A']
-            mtd_tl_schema = MTD_TL_SCHEMAS['MSIL2A']
-            mtd_tl_namespaces = MTD_TL_NAMESPACES['MSIL2A']
+            tree = read_xml(source, metadata_file)
+            mtd_schema = self.MTD_SCHEMAS['MSIL2A']
+            mtd_namespaces = self.MTD_NAMESPACES['MSIL2A']
+            mtd_tl_schema = self.MTD_TL_SCHEMAS['MSIL2A']
+            mtd_tl_namespaces = self.MTD_TL_NAMESPACES['MSIL2A']
 
-        except:
+        except Exception:
             metadata_file = join(path, 'MTD_MSIL1C.xml')
-            mtd_schema = MTD_SCHEMAS['MSIL1C']
-            mtd_namespaces = MTD_NAMESPACES['MSIL1C']
-            mtd_tl_schema = MTD_TL_SCHEMAS['MSIL1C']
-            mtd_tl_namespaces = MTD_TL_NAMESPACES['MSIL1C']
-
-        tree = read_xml(source, metadata_file)
+            tree = read_xml(source, metadata_file)
+            mtd_schema = self.MTD_SCHEMAS['MSIL1C']
+            mtd_namespaces = self.MTD_NAMESPACES['MSIL1C']
+            mtd_tl_schema = self.MTD_TL_SCHEMAS['MSIL1C']
+            mtd_tl_namespaces = self.MTD_TL_NAMESPACES['MSIL1C']
 
         # get product metadata
         metadata = parse_metadata_schema(tree, mtd_schema, mtd_namespaces)
@@ -204,7 +204,9 @@ class GSCRegistrationScheme(RegistrationScheme):
         metadata_file = gsc_filenames[0]
 
         tree = read_xml(source, metadata_file)
-        metadata = parse_metadata_schema(tree, self.GSC_SCHEMA, tree.getroot().nsmap)
+        metadata = parse_metadata_schema(
+            tree, self.GSC_SCHEMA, tree.getroot().nsmap
+        )
 
         tiff_files = {
             metadata['type']: source.list_files(path, ['*.tif', '*.TIF'])
@@ -294,6 +296,7 @@ REGISTRATION_SCHEMES = {
     'stac-item': STACCollectionScheme,
 }
 
+
 def get_scheme(config: dict, path: str) -> RegistrationScheme:
     cfg_schemes = config['schemes']
 
@@ -305,10 +308,11 @@ def get_scheme(config: dict, path: str) -> RegistrationScheme:
             break
     else:
         # no source found
-        raise RegistrationError(f'Could not find a suitable scheme for the path {path}')
+        raise RegistrationError(
+            f'Could not find a suitable scheme for the path {path}'
+        )
 
     return REGISTRATION_SCHEMES[cfg_scheme['type']](
         *cfg_scheme.get('args', []),
         **cfg_scheme.get('kwargs', {}),
     )
-
-- 
GitLab