Browse Source

Corrections schémas

omassot 6 years ago
parent
commit
b30ca529d9
6 changed files with 27 additions and 15 deletions
  1. 1 1
      core/checking.py
  2. 1 1
      core/constants.py
  3. 1 0
      core/mncheck.py
  4. 7 1
      schemas/mn1_rec.py
  5. 6 3
      schemas/mn2_rec.py
  6. 11 9
      ui/dlg_main.py

+ 1 - 1
core/checking.py

@@ -87,7 +87,7 @@ class TestResult():
         
     def handle_exception(self, exc_info):
         typ, value, trace = exc_info
-        self.log_exception("Une erreur inconnue s'est produite", 
+        self.log_exception("Une erreur s'est produite: {}".format(typ.__name__), 
                           {"exc_info": "{}\n{}\n{}".format(typ.__name__, value, ''.join(traceback.format_tb(trace)))})
 
 class Comlink():

+ 1 - 1
core/constants.py

@@ -6,7 +6,7 @@
 '''
 from path import Path
 
-VERSION = "0.7.4"
+VERSION = "0.7.5"
 
 MAIN = Path(__file__).parent.parent.abspath()
 

+ 1 - 0
core/mncheck.py

@@ -56,6 +56,7 @@ class QgsModel():
                   4: "MULTI-POINT", 5:"MULTI-LIGNE", 6:"MULTI-POLYGONE"}
     
     layername = ""
+    required = True
     geom_type = 0
     bounding_box = (0,0,1,1)
     schema = {}

+ 7 - 1
schemas/mn1_rec.py

@@ -175,6 +175,7 @@ class Tranchee(QgsModel):
         
 class Zapbo(QgsModel):
     layername = "zapbo_geo"
+    required = False
     geom_type = QgsModel.GEOM_POLYGON
     crs = CRS
     bounding_box = (XMIN,YMIN,XMAX,YMAX)
@@ -199,6 +200,8 @@ class Mn1Checker(BaseChecker):
         for model in models:
             model.layer = next((l for l in QgsProject.instance().mapLayers().values() \
                           if l.name().lower() == model.layername.lower()), None)
+            if not model.layer:
+                continue
             self.dataset[model] = [model(f) for f in model.layer.getFeatures()]
         
         self.arteres = self.dataset.get(Artere, [])
@@ -235,7 +238,10 @@ class Mn1Checker(BaseChecker):
         """
         for model in models:
             if model.layer is None:
-                self.log_error("Couche manquante", model=model)
+                if model.required:
+                    self.log_critical("Couche manquante", model=model)
+                else:
+                    self.log_error("Couche manquante", model=model)
                 continue
             
             if model.pk:

+ 6 - 3
schemas/mn2_rec.py

@@ -153,7 +153,7 @@ class Noeud(QgsModel):
               'NO_Y': {'empty': True, 'validator': is_float}, 
               'NO_PRO': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'PRIVE', 'ENEDIS', 'AUTRE', 'NUL']}, 
               'NO_GEST': {'type': 'string', 'maxlength': 20, 'empty': False, 'allowed': ['MANCHE NUMERIQUE', 'MANCHE TELECOM', 'COLLECTIVITE', 'ORANGE', 'ERDF', 'ENEDIS', 'MANCHE FIBRE', 'PRIVE', 'AUTRE', 'NUL']}, 
-              'NO_HAUT': {'validator': is_float}, 
+              'NO_HAUT': {'empty': True, 'validator': is_float}, 
               'NO_DATE_IN': {'empty': True, 'validator': is_modern_french_date}, 
               'NO_REF_PLA': {'type': 'string', 'maxlength': 100}, 
               'NO_SRC_GEO': {'type': 'string', 'maxlength': 50}, 
@@ -199,6 +199,7 @@ class Zapbo(QgsModel):
     crs = CRS
     bounding_box = (XMIN,YMIN,XMAX,YMAX)
     pk = "ID_ZAPBO"
+    required = False
     schema = {'ID_ZAPBO': {'type': 'string', 'empty': False, 'maxlength': 30, 'contains_any_of': ['PBO', 'BPE', 'PEC']}, 
               'COMMENTAIR': {'type': 'string', 'maxlength': 254, 'empty': True}, 
               'STATUT': {'type': 'string', 'empty': False, 'allowed': STATUTS}}
@@ -220,6 +221,8 @@ class Mn2Checker(BaseChecker):
         for model in models:
             model.layer = next((l for l in QgsProject.instance().mapLayers().values() \
                           if l.name().lower() == model.layername.lower()), None)
+            if not model.layer:
+                continue
             self.dataset[model] = [model(f) for f in model.layer.getFeatures()]
         
         self.arteres = self.dataset.get(Artere, [])
@@ -256,12 +259,12 @@ class Mn2Checker(BaseChecker):
         """
         for model in models:
             if model.layer is None:
-                self.log_critical("Couche manquante", model=model)
+                self.log_error("Couche manquante", model=model)
                 continue
             
             if model.pk:
                 if not model.pk.lower() in [f.name().lower() for f in model.layer.fields()]:
-                    self.log_critical(f"Clef primaire manquante ({model.pk})", model=model)
+                    self.log_error(f"Clef primaire manquante ({model.pk})", model=model)
                     continue
         
     def test_scr(self):

+ 11 - 9
ui/dlg_main.py

@@ -117,8 +117,7 @@ class DlgMain(QtWidgets.QDialog):
         
         schema = mncheck.get_schema(schema_name)
         
-        expected = [model.layername for model in schema.models]
-        logger.info("Expected layers: %s", str(expected))
+        logger.info("Expected layers: %s", str([model.layername for model in schema.models]))
 
         found = [layer.name().lower() for layer in QgsProject.instance().mapLayers().values()]
         logger.info("Found layers: %s", str(found))
@@ -127,17 +126,20 @@ class DlgMain(QtWidgets.QDialog):
 
         self.ui.tree_report.clear()
 
-        for layername in expected:
+        for model in schema.models:
             
             item = QTreeWidgetItem()
             
-            if layername.lower() in found:
+            if model.layername.lower() in found:
                 item.setIcon(0, QIcon(QPixmap(RSCDIR / "ok_16.png")))
-                item.setText(1, layername)
+                item.setText(1, model.layername)
             else:
-                item.setIcon(0, QIcon(QPixmap(RSCDIR / "error_16.png")))
-                item.setText(1, f"{layername}: La couche est introuvable")
-                self.ui.btn_run.setEnabled(False)
+                item.setText(1, f"{model.layername}: La couche est introuvable")
+                if model.required:
+                    item.setIcon(0, QIcon(QPixmap(RSCDIR / "error_16.png")))
+                    self.ui.btn_run.setEnabled(False)
+                else:
+                    item.setIcon(0, QIcon(QPixmap(RSCDIR / "warning_16.png")))
                 
             self.ui.tree_report.addTopLevelItem(item)
 
@@ -197,7 +199,7 @@ class DlgMain(QtWidgets.QDialog):
                 
             elif result.status == checking.ERROR:
                 topitem.setIcon(0, QIcon(QPixmap(RSCDIR / "warning_16.png")))
-                topitem.setText(1, f"{result.title} [Erreur inconnue]")
+                topitem.setText(1, f"{result.title} [Erreur]")
                 
             else:
                 topitem.setText(1, f"{result.title} [Erreur: aucun résultat]")