changeset 2022:2bab30fa0309

make storage validation easy to switch between strict and warn mode
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 02 Mar 2013 23:40:17 +0100
parents 36d51bad06b3
children 8300781142e5
files MoinMoin/storage/middleware/indexing.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 23:27:40 2013 +0100
+++ b/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 23:40:17 2013 +0100
@@ -91,6 +91,10 @@
 WHOOSH_FILESTORAGE = 'FileStorage'
 INDEXES = [LATEST_REVS, ALL_REVS, ]
 
+VALIDATION_HANDLING_STRICT = 'strict'
+VALIDATION_HANDLING_WARN = 'warn'
+VALIDATION_HANDLING = VALIDATION_HANDLING_WARN
+
 
 def get_names(meta):
     """
@@ -1051,12 +1055,12 @@
             Schema = ContentMetaSchema
         m = Schema(meta)
         valid = m.validate(state)
-        # TODO: currently we just log validation results. in the end we should
-        # reject invalid stuff in some comfortable way.
         if not valid:
             logging.warning("metadata validation failed, see below")
             for e in m.children:
                 logging.warning("{0}, {1}".format(e.valid, e))
+            if VALIDATION_HANDLING == VALIDATION_HANDLING_STRICT:
+                raise ValueError('metadata validation failed and strict handling requested, see the log for details')
 
         # we do not have anything in m that is not defined in the schema,
         # e.g. userdefined meta keys or stuff we do not validate. thus, we