[elbe-devel] [PATCH 4/5] Preprocess ISO images options XML tags

dion at linutronix.de dion at linutronix.de
Tue Jul 9 17:04:05 CEST 2019


From: Olivier Dion <dion at linutronix.de>

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/xmlpreprocess.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 304b1b37..f7611939 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -20,6 +20,7 @@ from elbepack.archivedir import ArchivedirError, combinearchivedir
 from elbepack.directories import elbe_exe
 from elbepack.shellhelper import command_out_stderr, CommandError
 from elbepack.validate import error_log_to_strings
+from elbepack.cdroms import iso_option_valid
 
 # list of sections that are allowed to exists multiple times before
 # preprocess and that childrens are merge into one section during preprocess
@@ -43,6 +44,28 @@ def preprocess_pgp_key(xml):
         except urllib2.HTTPError as E:
             raise XMLPreprocessError("Invalid PGP Key URL in <key> tag: %s" % keyurl)
 
+def preprocess_iso_option(xml):
+
+    src_opts = xml.find(".//target/src-opts")
+    strict = "strict" in src_opts.attrib and src_opts.attrib["strict"] == "true"
+    for opt in src_opts.iterfind("./*"):
+        valid = iso_option_valid(opt.tag, opt.text)
+        if valid is True:
+            continue
+
+        tag = '<%s>%s</%s>' % (opt.tag, opt.text, opt.tag)
+
+        if valid is False:
+            violation = "Invalid ISO option %s" % tag
+        elif isinstance(valid, int):
+            violation = "Option %s will be truncated by %d characters" % (tag, valid)
+        elif isinstance(valid, str):
+            violation = ("Character '%c' (%d) in ISO option %s violated ISO-9660" %
+                         (valid, ord(valid[0]), tag))
+        if strict:
+            raise XMLPreprocessError(violation)
+        print("[WARN] %s" % violation)
+
 def xmlpreprocess(fname, output, variants=None):
 
     # pylint: disable=too-many-locals
@@ -113,6 +136,8 @@ def xmlpreprocess(fname, output, variants=None):
         # Change public PGP url key to raw key
         preprocess_pgp_key(xml)
 
+        preprocess_iso_option(xml)
+
         if schema.validate(xml):
             # if validation succedes write xml file
             xml.write(
-- 
2.11.0




More information about the elbe-devel mailing list