[elbe-devel] [PATCH 1/3] Revert "Validation should preprocess the XML files"

Torben Hohn torben.hohn at linutronix.de
Fri Aug 9 13:02:00 CEST 2019


This reverts commit 6e48dd58ffc47500ce0a63d876482adb63565f55.

calling the preprocessor in the actual validation code is not wanted.
it shall not run inside the initvm.

#229 is about elbe validate, which is elbepack/commands/validate.py

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/validate.py      | 44 ++++++++++++++++++++++++++++++--------------
 elbepack/xmlpreprocess.py | 28 +++-------------------------
 2 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/elbepack/validate.py b/elbepack/validate.py
index d2c60c408..c1e5c771b 100644
--- a/elbepack/validate.py
+++ b/elbepack/validate.py
@@ -11,9 +11,28 @@ import sys
 from lxml import etree
 from lxml.etree import XMLParser, parse
 
-from elbepack.shellhelper import CommandError
-from elbepack.xmlpreprocess import PreprocessWrapper, error_log_to_strings
 
+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):
@@ -26,18 +45,15 @@ def validate_xml(fname):
     schema = etree.XMLSchema(schema_tree)
 
     try:
-        with PreprocessWrapper(fname) as xml_p:
-            xml = parse(xml_p.preproc, parser=parser)
-            try:
-                if schema.validate(xml):
-                    return validate_xml_content(xml)
-            except etree.XMLSyntaxError:
-                return ["XML Parse error\n" + str(sys.exc_info()[1])]
-            except BaseException:
-                return ["Unknown Exception during validation\n" +
-                        str(sys.exc_info()[1])]
-    except CommandError as E:
-        return ["Fail preprocessor\n%r" % E]
+        xml = parse(fname, parser=parser)
+
+        if schema.validate(xml):
+            return validate_xml_content(xml)
+    except etree.XMLSyntaxError:
+        return ["XML Parse error\n" + str(sys.exc_info()[1])]
+    except BaseException:
+        return ["Unknown Exception during validation\n" +
+                str(sys.exc_info()[1])]
 
     # We have errors, return them in string form...
     return error_log_to_strings(schema.error_log)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index adf897e5c..22ec2c7dd 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -20,7 +20,7 @@ from elbepack.archivedir import ArchivedirError, combinearchivedir
 from elbepack.directories import elbe_exe
 from elbepack.shellhelper import command_out_stderr, CommandError
 from elbepack.isooptions import iso_option_valid
-
+from elbepack.validate import error_log_to_strings
 
 # list of sections that are allowed to exists multiple times before
 # preprocess and that childrens are merge into one section during preprocess
@@ -165,12 +165,12 @@ def xmlpreprocess(fname, output, variants=None):
 
 
 class PreprocessWrapper(object):    # pylint: disable=too-few-public-methods
-    def __init__(self, xmlfile, opt=None):
+    def __init__(self, xmlfile, opt):
         self.xmlfile = xmlfile
         self.outxml = None
         self.options = ""
 
-        if opt and opt.variant:
+        if opt.variant:
             self.options += ' --variants "%s"' % opt.variant
 
     def __enter__(self):
@@ -206,25 +206,3 @@ class PreprocessWrapper(object):    # pylint: disable=too-few-public-methods
     @property
     def preproc(self):
         return self.outxml.name
-
-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
-- 
2.11.0




More information about the elbe-devel mailing list