[elbe-devel] [PATCH 1/2] validate: isolate the error_log_to_string() function

Torben Hohn torben.hohn at linutronix.de
Thu May 16 14:30:34 CEST 2019


the logic, that adds messages to the schema validation log needs to be
used in elbe preprocess too. elbe preproces is the point, where validation
errors will show up.

To allow the reuse of this code, at that point, isolate it into a separat
function.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/validate.py | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/elbepack/validate.py b/elbepack/validate.py
index 868603628..c1e5c771b 100644
--- a/elbepack/validate.py
+++ b/elbepack/validate.py
@@ -12,6 +12,28 @@ from lxml import etree
 from lxml.etree import XMLParser, parse
 
 
+def error_log_to_strings(error_log):
+    errors = []
+    uses_xinclude = False
+    uses_norecommend = False
+
+    for err in error_log:
+        errors.append("%s:%d error %s" % (err.filename, err.line, err.message))
+        if "http://www.w3.org/2003/XInclude" in err.message:
+            uses_xinclude = True
+        if "norecommend" in err.message:
+            uses_norecommend = True
+
+    if uses_xinclude:
+        errors.append("\nThere are XIncludes in the XML file. "
+                      "Run 'elbe preprocess' first!\n")
+    if uses_norecommend:
+        errors.append("\nThe XML file uses <norecommend />. "
+                      "This function was broken all the time and did the "
+                      "opposite. If you want to retain the original "
+                      "behaviour, please specify <install-recommends /> !\n")
+    return errors
+
 def validate_xml(fname):
     if os.path.getsize(fname) > (1 << 30):
         return ["%s is greater than 1 GiB. "
@@ -34,27 +56,7 @@ def validate_xml(fname):
                 str(sys.exc_info()[1])]
 
     # We have errors, return them in string form...
-    errors = []
-    uses_xinclude = False
-    uses_norecommend = False
-
-    for err in schema.error_log:
-        errors.append("%s:%d error %s" % (err.filename, err.line, err.message))
-        if "http://www.w3.org/2003/XInclude" in err.message:
-            uses_xinclude = True
-        if "norecommend" in err.message:
-            uses_norecommend = True
-
-    if uses_xinclude:
-        errors.append("\nThere are XIncludes in the XML file. "
-                      "Run 'elbe preprocess' first!\n")
-    if uses_norecommend:
-        errors.append("\nThe XML file uses <norecommend />. "
-                      "This function was broken all the time and did the "
-                      "opposite. If you want to retain the original "
-                      "behaviour, please specify <install-recommends /> !\n")
-
-    return errors
+    return error_log_to_strings(schema.error_log)
 
 
 def validate_xml_content(xml):
-- 
2.11.0




More information about the elbe-devel mailing list