Browse Source

Add docstrings to modules

omassot 7 years ago
parent
commit
a3cbca2375
8 changed files with 37 additions and 48 deletions
  1. 9 3
      core/QgsLogHandler.py
  2. 2 25
      core/cerberus_.py
  3. 3 1
      core/constants.py
  4. 3 2
      core/logconf.py
  5. 1 1
      core/logging.yaml
  6. 4 15
      main.py
  7. 5 0
      schemas/mn1_rec.py
  8. 10 1
      schemas/mn2_rec.py

+ 9 - 3
core/QHandler.py → core/QgsLogHandler.py

@@ -1,5 +1,7 @@
 '''
 
+    Logging handler for QGis
+
 @author: olivier.massot, 2018
 '''
 import logging
@@ -14,10 +16,14 @@ _to_qgis_level = {logging.DEBUG: 0,
                   logging.NOTSET: 4}
 
 
-class QHandler(logging.Handler):
+class QgsLogHandler(logging.Handler):
     
     _qgs_iface = None
 
+    @classmethod
+    def connect_to_iface(cls, iface):
+        cls._qgs_iface = iface
+
     def emit(self, record):
         try:
             msg = self.format(record)
@@ -25,8 +31,8 @@ class QHandler(logging.Handler):
             
             QgsMessageLog.logMessage(msg, "Mnheck", _to_qgis_level[level])
             
-            if QHandler._qgs_iface and record.levelno >= logging.WARNING:
-                QHandler._qgs_iface.messageBar().pushMessage("MnCheck", msg, level=_to_qgis_level[level])
+            if self._qgs_iface and record.levelno >= logging.WARNING:
+                self._qgs_iface.messageBar().pushMessage("MnCheck", msg, level=_to_qgis_level[level])
             
         except (KeyboardInterrupt, SystemExit):
             raise

+ 2 - 25
core/cerberus_.py

@@ -1,5 +1,7 @@
 '''
 
+    Extend the cerberus library with more validation methods and french translations
+
 @author: olivier.massot, 2018
 '''
 from datetime import datetime
@@ -79,31 +81,6 @@ class ExtendedValidator(cerberus.validator.Validator):
                 else:
                     self._error(field, "Valeur non-autorisée: {}".format(item))
 
-class GeoValidator(ExtendedValidator):
-    
-    def _validate_inside_box(self, bounding_box, field, value):
-        """ Contrôle l'inclusion de la bounding box de l'entité dans la box donneé
-
-        The rule's arguments are validated against this schema:
-        {'type': 'list'}
-        """
-#         geom_type, bounding_box = geom
-#         
-#         if value.geom_type != geom_type:
-#             self._error(field, "Le type de géométrie est {} (attendu: {})".format(value.geom_name, gis_.GEOM_NAMES[geom_type]))
-    
-        xmin, ymin, xmax, ymax = bounding_box
-        
-        try:
-            x1, y1, x2, y2 = value.bounding_box
-            
-            if any(x < xmin or x > xmax for x in (x1, x2)) or \
-               any(y < ymin or y > ymax for y in (y1, y2)):
-                self._error(field, "Certaines coordonnées hors de l'emprise autorisée")
-        except AttributeError:
-            pass
-
-
 def _translate_messages(message):
     message = message.replace("string", "texte")
     message = message.replace("integer", "nombre entier")

+ 3 - 1
core/constants.py

@@ -1,6 +1,8 @@
 '''
 
-@author: OMASSOT
+    Parameters for the curent project
+
+@author: olivier.massot, 2018
 '''
 from path import Path
 

+ 3 - 2
core/logconf.py

@@ -1,7 +1,8 @@
 '''
-Created on 6 juil. 2017
+    
+    Set up the logging
 
-@author: olivier.massot
+@author: olivier.massot, 2018
 '''
 import logging.config
 import sys

+ 1 - 1
core/logging.yaml

@@ -12,7 +12,7 @@ formatters:
         
 handlers:
     qgis:
-        class: core.QHandler.QHandler
+        class: core.QgsLogHandler.QgsLogHandler
         level: DEBUG
         formatter: message_only
         

+ 4 - 15
main.py

@@ -1,25 +1,14 @@
-# -*- coding: utf-8 -*-
 """
 /***************************************************************************
  MnCheck
                                  A QGIS plugin
  Contrôle des données FTTH format MN
- Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
+
                               -------------------
-        begin                : 2018-12-07
-        git sha              : $Format:%H$
-        copyright            : (C) 2018 by Manche Numérique 2019
+        copyright            : (C) 2019 by Manche Numérique
         email                : olivier.massot@manchenumerique.fr
  ***************************************************************************/
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
 """
 import logging
 
@@ -27,7 +16,7 @@ from PyQt5.QtGui import QIcon
 from PyQt5.QtWidgets import QAction
 
 from core import logconf
-from core.QHandler import QHandler
+from core.QgsLogHandler import QgsLogHandler
 from core.constants import MAIN
 from ui.dlg_main import DlgMain
 
@@ -75,7 +64,7 @@ class MnCheck:
     def initGui(self):
         """Create the menu entries and toolbar icons inside the QGIS GUI."""
         
-        QHandler._qgs_iface = self.iface
+        QgsLogHandler.connect_to_iface(self.iface)
         
         self.add_action(MAIN / 'icon.png', 
                         text='MnCheck', 

+ 5 - 0
schemas/mn1_rec.py

@@ -1,5 +1,7 @@
 '''
 
+    Schéma de validation des données MN1
+
 @author: olivier.massot, 2018
 '''
 
@@ -14,6 +16,9 @@ from core.validator import QgsModel, BaseValidator
 
 logger = logging.getLogger("mncheck")
 
+
+SCHEMA_NAME = "Schéma MN v1 REC"
+
 XMIN, XMAX, YMIN, YMAX = 1341999, 1429750, 8147750, 8294000
 CRS = 'EPSG:3949' # Coordinate Reference System
 

+ 10 - 1
schemas/mn2_rec.py

@@ -1,14 +1,23 @@
 '''
 
+    Schéma de validation des données MN2
+
 @author: olivier.massot, 2018
 '''
+import logging
 from qgis.core import QgsGeometry
 
 from core.cerberus_ import is_float, is_multi_int, is_int, \
     is_modern_french_date
-from core.validator import QgsModel, BaseValidator
 from core.validation_errors import UniqueError, RelationError, \
     DuplicatedGeom, MissingItem, DimensionError, TechnicalValidationError
+from core.validator import QgsModel, BaseValidator
+
+
+logger = logging.getLogger("mncheck")
+
+
+SCHEMA_NAME = "Schéma MN v2 REC"
 
 
 STATUTS = ['EN ETUDE', 'EN REALISATION', 'EN SERVICE', 'HORS SERVICE']