olivier.massot 7 anni fa
parent
commit
82c42ae69c
6 ha cambiato i file con 175 aggiunte e 1 eliminazioni
  1. 2 1
      .gitignore
  2. 37 0
      core/gis.py
  3. 39 0
      core/validation.py
  4. 68 0
      core/validation_errors.py
  5. 29 0
      validators/netgeo_2_2_doe.py
  6. 0 0
      validators/netgeo_v2-2_doe.yaml

+ 2 - 1
.gitignore

@@ -7,4 +7,5 @@ htmlcov/
 *.log
 *.log.1
 /work/*
-tmp*
+tmp*
+~$*

+ 37 - 0
core/gis.py

@@ -0,0 +1,37 @@
+'''
+
+@author: olivier.massot, sept. 2018
+'''
+import shapefile
+
+SHAPES = {1:"Point", 3:"Polyligne", 5:"Polygone"}
+
+class ShapeError(IOError): pass
+
+class ShapeFile():
+    shapes = {1: "POINT", 3:"POLYLIGNE", 5:"POLYGONE"}
+    
+    def __enter__(self, path_):
+        if not path_.isfile():
+            raise FileNotFoundError("Fichier introuvable")
+     
+        try:
+            self.sf = shapefile.Reader(path_)
+        except shapefile.ShapefileException:
+            raise ShapeError("Fichier Shape illisible")
+        
+        try:
+            _ = self.shapes[self.sf.shapeType]
+        except KeyError:
+            raise ShapeError("Type de géométrie non reconnue")
+
+        return self
+    
+    def fields(self):
+        return [f[0] for f in self.sf.fields if f[0] != 'DeletionFlag']
+        
+    def records(self):
+        return self.sf.shapeRecords()
+        
+    def __exit__(self):
+        del self.sf

+ 39 - 0
core/validation.py

@@ -0,0 +1,39 @@
+'''
+
+
+    @author: olivier.massot, sept. 2018
+'''
+import zipfile
+
+from path import Path, TempDir
+
+class ValidationReport():
+    def __init__(self, title = ""):
+        self.title = title
+        self.errors = {}
+        self.valid = True
+        
+class BaseValidator():
+    
+    @classmethod
+    def submit(cls, subject):    
+        """ prends un dossier ou une archive en entrée et vérifie son contenu  """
+        subject = Path(subject)
+        
+        if subject.isfile():
+            with TempDir() as dirname:
+                zip_ref = zipfile.ZipFile(subject, 'r')
+                zip_ref.extractall(dirname)
+                zip_ref.close()
+                if Path(dirname / subject.stem).isdir(): # cas où l'archive contient un dossier qui lui-même contient les fichiers
+                    dirname /= subject.stem
+                return cls._submit_folder(dirname)
+            
+        elif subject.isdir():
+            return cls._submit_folder(subject)
+        else:
+            raise FileNotFoundError(f"Impossible de trouver le fichier ou répertoire: {subject}")
+
+    @classmethod
+    def _submit_folder(cls, folder):
+        raise NotImplementedError()

+ 68 - 0
core/validation_errors.py

@@ -0,0 +1,68 @@
+'''
+
+@author: olivier.massot, 2018
+'''
+
+VALIDATION_ERROR_LEVELS = {10: "MINEURE", 20: "ATTENTION", 30: "ERREUR", 40: "CRITIQUE"}
+
+MINOR = 10
+WARNING = 20
+ERROR = 30
+CRITICAL = 40
+
+
+
+class BaseValidationError():
+    name = ""
+    level = 0
+    def __init__(self, message):
+        self.message = message
+        
+        
+#### Erreurs Critiques
+
+class MissingFile():
+    level = CRITICAL
+    name = "Fichier Manquant"
+    
+class UnreadableFile():
+    level = CRITICAL
+    name = "Fichier Illisible"
+
+class WrongSrid():
+    level = CRITICAL
+    name = "Mauvais SRID"
+
+class FieldTypeError():
+    level = CRITICAL
+    name = "Le champs n'a pas le bon type de donnée"
+    
+#### Erreurs
+
+class OutOfBoxCoordinates():
+    level = ERROR
+    name = "Coordonnées hors de la zone autorisée"
+
+class FormatError():
+    level = ERROR
+    name = "Le champs n'a pas le bon format"
+
+class MissingValueError():
+    level = ERROR
+    name = "Le champs doit être renseigné"
+    
+class FieldValueError():
+    level = ERROR
+    name = "La valeur du champs est invalide"
+
+#### Avertissements
+
+
+
+
+
+
+#### Erreurs mineures
+
+
+

+ 29 - 0
validators/netgeo_2_2_doe.py

@@ -0,0 +1,29 @@
+'''
+
+    Controle les données d'un dossier ou d'une archive contenant des données au format Netgeo 2.2
+
+    Python 3.7+
+
+    @author: olivier.massot, sept. 2018
+'''
+from core.validation import BaseValidator
+
+NAME = "Netgeo v2.2 DOE"
+
+INPUT_FILES = ["artere_geo.shp", "cable_geo.shp", "equipement_passif.shp", "noeud_geo.shp", "tranchee_geo.shp", "zapbo_geo.shp"]
+
+
+    
+class Netgeo22Validator(BaseValidator):
+    
+    @classmethod
+    def _submit_folder(cls, folder):
+        print(folder)
+
+    
+if __name__ == "__main__":
+    from core.constants import MAIN
+    subject = MAIN / "work" / "STURNO_192AP0_REC_COMPLEMENT_180822_OK.zip"
+    report = Netgeo22Validator.submit(subject)
+
+

+ 0 - 0
checkers/netgeo_v2-2_doe.yaml → validators/netgeo_v2-2_doe.yaml