[elbe-devel] [PATCH 3/8] Move iso options to its own file

Torben Hohn torben.hohn at linutronix.de
Fri Aug 9 10:47:49 CEST 2019


From: Olivier Dion <dion at linutronix.de>

The xmlpreprocess.py used to import from the cdroms.py the iso options
related functions.  This dependency was a problem for the initvm.

Putting the iso options related stuff in its own file allow us to
break remove this dependency.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/cdroms.py        | 43 +------------------------------------------
 elbepack/isooptions.py    | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 elbepack/xmlpreprocess.py |  2 +-
 3 files changed, 48 insertions(+), 43 deletions(-)
 create mode 100644 elbepack/isooptions.py

diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index 9d3c1aaca..3ba67f7bf 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -17,52 +17,11 @@ from elbepack.repomanager import CdromInitRepo
 from elbepack.aptpkgutils import XMLPackage
 from elbepack.filesystem import Filesystem, hostfs
 from elbepack.shellhelper import CommandError
+from elbepack.isooptions import get_iso_options
 
 CDROM_SIZE = 640 * 1000 * 1000
 
 
-# https://wiki.osdev.org/ISO_9660
-iso_options = {
-    "sysid":     ("-sysid",      32, "Specifies the system ID",              "strA"),
-    "volid":     ("-V",          32, "Specifies the volume ID",              "strD"),
-    "volset":    ("-volset",    128, "Specifies the volume set ID",          "strD"),
-    "publisher": ("-publisher", 128, "Specifies the publisher ID",           "strA"),
-    "preparer":  ("-p",         128, "Specifies the preparer ID",            "strA"),
-    "app":       ("-A",         128, "Specifies the application ID",         "strA"),
-    "copyright": ("-copyright",  38, "Specifies copyright filename on disc", "strD"),
-    "abstract":  ("-abstract",   36, "Specifies the abstract filename",      "strD"),
-    "biblio":    ("-biblio",     37, "Specifies the bibliographic filename", "strD"),
-}
-
-encoding = {
-    "strA":"""ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_!"%&'()*+,-./:;<=>? """,
-    "strD":"""ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"""
-}
-def iso_option_valid(opt_name, text):
-    if opt_name not in iso_options:
-        return False
-    str_type = encoding[iso_options[opt_name][3]]
-    if len(text) > iso_options[opt_name][1]:
-        return len(text) - iso_options[opt_name][1]
-    for c in text:
-        if c not in str_type:
-            return c
-    return True
-
-def get_iso_options(log, xml):
-    options = []
-    src_opts = xml.node("target/src-opts")
-    if src_opts is None:
-        return ""
-    for node in src_opts:
-        if node.tag not in iso_options:
-            continue
-        option = iso_options[node.tag]
-        log.printo("Adding option %s\n%s" % (node.tag, option[2]))
-        text = node.et.text[:option[1]]
-        options.append('%s "%s"' % (option[0], text.replace('"', '\\"')))
-    return " ".join(options)
-
 def mk_source_cdrom(
         rfs,
         arch,
diff --git a/elbepack/isooptions.py b/elbepack/isooptions.py
new file mode 100644
index 000000000..beab6ce65
--- /dev/null
+++ b/elbepack/isooptions.py
@@ -0,0 +1,46 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2019 Olivier Dion <dion at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# https://wiki.osdev.org/ISO_9660
+iso_options = {
+    "sysid":     ("-sysid",      32, "Specifies the system ID",              "strA"),
+    "volid":     ("-V",          32, "Specifies the volume ID",              "strD"),
+    "volset":    ("-volset",    128, "Specifies the volume set ID",          "strD"),
+    "publisher": ("-publisher", 128, "Specifies the publisher ID",           "strA"),
+    "preparer":  ("-p",         128, "Specifies the preparer ID",            "strA"),
+    "app":       ("-A",         128, "Specifies the application ID",         "strA"),
+    "copyright": ("-copyright",  38, "Specifies copyright filename on disc", "strD"),
+    "abstract":  ("-abstract",   36, "Specifies the abstract filename",      "strD"),
+    "biblio":    ("-biblio",     37, "Specifies the bibliographic filename", "strD"),
+}
+
+encoding = {
+    "strA":"""ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_!"%&'()*+,-./:;<=>? """,
+    "strD":"""ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"""
+}
+def iso_option_valid(opt_name, text):
+    if opt_name not in iso_options:
+        return False
+    str_type = encoding[iso_options[opt_name][3]]
+    if len(text) > iso_options[opt_name][1]:
+        return len(text) - iso_options[opt_name][1]
+    for c in text:
+        if c not in str_type:
+            return c
+    return True
+
+def get_iso_options(log, xml):
+    options = []
+    src_opts = xml.node("target/src-opts")
+    if src_opts is None:
+        return ""
+    for node in src_opts:
+        if node.tag not in iso_options:
+            continue
+        option = iso_options[node.tag]
+        log.printo("Adding option %s\n%s" % (node.tag, option[2]))
+        text = node.et.text[:option[1]]
+        options.append('%s "%s"' % (option[0], text.replace('"', '\\"')))
+    return " ".join(options)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 1cb6007ed..adf897e5c 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -19,7 +19,7 @@ from lxml.etree import XMLParser, parse
 from elbepack.archivedir import ArchivedirError, combinearchivedir
 from elbepack.directories import elbe_exe
 from elbepack.shellhelper import command_out_stderr, CommandError
-from elbepack.cdroms import iso_option_valid
+from elbepack.isooptions import iso_option_valid
 
 
 # list of sections that are allowed to exists multiple times before
-- 
2.11.0




More information about the elbe-devel mailing list