+ _setup_defaults(config, config_path)
+
+ # For now the validator just works with the default functions,
+ # but in the future if we want to add additional validation/configuration
+ # functions we'd add them to validator.functions here.
+ #
+ # See also:
+ # http://www.voidspace.org.uk/python/validate.html#adding-functions
+ validator = Validator()
+ validation_result = config.validate(validator, preserve_errors=True)
+
+ return config, validation_result
+
+
+REPORT_HEADER = """\
+There were validation problems loading this config file:
+--------------------------------------------------------
+"""
+
+
+def generate_validation_report(config, validation_result):
+ """
+ Generate a report if necessary of problems while validating.
+
+ Returns:
+ Either a string describing for a user the problems validating
+ this config or None if there are no problems.
+ """
+ report = []
+
+ # Organize the report
+ for entry in flatten_errors(config, validation_result):
+ # each entry is a tuple
+ section_list, key, error = entry
+
+ if key is not None:
+ section_list.append(key)
+ else:
+ section_list.append(u'[missing section]')
+
+ section_string = u':'.join(section_list)