|
|
@@ -48,6 +48,14 @@ class ReportField():
|
|
|
def valid(self):
|
|
|
return self._valid
|
|
|
|
|
|
+ def to_dict(self):
|
|
|
+ return {
|
|
|
+ "name": self.name,
|
|
|
+ "value": self.value,
|
|
|
+ "error": self._error,
|
|
|
+ "valid": self._valid
|
|
|
+ }
|
|
|
+
|
|
|
class ReportRecord():
|
|
|
def __init__(self, index):
|
|
|
self.index = index
|
|
|
@@ -77,6 +85,14 @@ class ReportRecord():
|
|
|
self._valid=False
|
|
|
self._fields.append(field)
|
|
|
|
|
|
+ def to_dict(self):
|
|
|
+ return {
|
|
|
+ "index": self.index,
|
|
|
+ "valid": self._valid,
|
|
|
+ "errors": self._errors,
|
|
|
+ "fields": [f.to_dict() for f in self._fields]
|
|
|
+ }
|
|
|
+
|
|
|
class ReportFile():
|
|
|
def __init__(self, file):
|
|
|
self.file = file
|
|
|
@@ -106,7 +122,15 @@ class ReportFile():
|
|
|
self._valid=False
|
|
|
logger.error("Fichier %s - %s", self.file, error)
|
|
|
self._errors.append(error)
|
|
|
-
|
|
|
+
|
|
|
+ def to_dict(self):
|
|
|
+ return {
|
|
|
+ "file": self.file,
|
|
|
+ "headers": self.headers,
|
|
|
+ "valid": self.valid,
|
|
|
+ "errors": self._errors,
|
|
|
+ "records": [r.to_dict() for r in self._records]
|
|
|
+ }
|
|
|
|
|
|
class Report():
|
|
|
def __init__(self, title, report_files=[]):
|
|
|
@@ -117,8 +141,15 @@ class Report():
|
|
|
def valid(self):
|
|
|
return all([r.valid for r in self.report_files])
|
|
|
|
|
|
+ def to_dict(self):
|
|
|
+ return {
|
|
|
+ "title": self.title,
|
|
|
+ "report_files": [rf.to_dict() for rf in self.report_files],
|
|
|
+ "valid": self.valid
|
|
|
+ }
|
|
|
+
|
|
|
def to_json(self):
|
|
|
- return json.dumps(self)
|
|
|
+ return json.dumps(self.to_dict())
|
|
|
|
|
|
def check(subject, checker):
|
|
|
""" prends un dossier ou une archive en entier et vérifie son contenu selon les règles données par le fichier de config """
|
|
|
@@ -300,9 +331,12 @@ def check_folder(folder, checker):
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
logger.disabled = False
|
|
|
- subject = MAIN / "work" / "SCOPELEC_CAP_097AP0_REC_180829_OK.zip"
|
|
|
+ subject = MAIN / "work" / "STURNO_192AP0_REC_COMPLEMENT_180822_OK.zip"
|
|
|
checker = MAIN / "checkers" / "netgeo_v2-2_doe.yaml"
|
|
|
|
|
|
report = check(subject, checker)
|
|
|
-
|
|
|
- logger.info("-- Fin --")
|
|
|
+
|
|
|
+ with open(MAIN / "report.json", "w+") as fp:
|
|
|
+ json.dump(report.to_dict(), fp)
|
|
|
+
|
|
|
+ logger.info("-- Fin --")
|