[elbe-devel] [PATCH 2/4] elbepack: avoid modifying global XML_CATALOG_FILES

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Feb 28 13:48:39 CET 2024


The environment files is effectively a global variable.
Avoid the need to modify it by passing around explicit schema locations.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/directories.py   | 18 ++++++++----------
 elbepack/validate.py      |  4 +++-
 elbepack/xmlpreprocess.py |  4 ++--
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/elbepack/directories.py b/elbepack/directories.py
index b7c53af6f544..f3168ee3da23 100644
--- a/elbepack/directories.py
+++ b/elbepack/directories.py
@@ -20,21 +20,19 @@ def init_directories(elbe_relpath):
     elbe_exe = os.path.abspath(os.path.realpath(elbe_relpath))
     elbe_dir = os.path.dirname(elbe_exe)
 
-    if not elbe_exe.startswith('/usr/bin/'):
-
-        # Set XML catalog if elbe is run from source
-        xmlcat = os.path.join(elbe_dir, 'schema/catalog.xml')
-        if os.environ.get('XML_CATALOG_FILES') is None:
-            os.environ['XML_CATALOG_FILES'] = xmlcat
-        else:
-            os.environ['XML_CATALOG_FILES'] += ' '
-            os.environ['XML_CATALOG_FILES'] += xmlcat
-
 
 def get_cmdlist():
     return [x for _, x, _ in iter_modules(elbepack.commands.__path__)]
 
 
+def xml_schema_file(url):
+    if elbe_exe.startswith('/usr/bin'):
+        # schema is installed system-wide and registered in catalog
+        return url
+
+    return os.path.join(elbe_dir, 'schema', os.path.basename(url))
+
+
 pack_dir = elbepack.__path__[0]
 
 init_template_dir = os.path.join(pack_dir, 'init')
diff --git a/elbepack/validate.py b/elbepack/validate.py
index 32f2ab70e35e..fc8ec05173a4 100644
--- a/elbepack/validate.py
+++ b/elbepack/validate.py
@@ -8,6 +8,8 @@ import sys
 from lxml import etree
 from lxml.etree import XMLParser, parse
 
+from elbepack.directories import xml_schema_file
+
 
 def error_log_to_strings(error_log):
     errors = []
@@ -39,7 +41,7 @@ def validate_xml(fname):
 
     schema_file = 'https://www.linutronix.de/projects/Elbe/dbsfed.xsd'
     parser = XMLParser(huge_tree=True)
-    schema_tree = etree.parse(schema_file)
+    schema_tree = etree.parse(xml_schema_file(schema_file))
     schema = etree.XMLSchema(schema_tree)
 
     try:
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 7c860a464ee4..fd8b06cc9b4e 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -15,7 +15,7 @@ from urllib.request import urlopen
 
 from elbepack.archivedir import ArchivedirError, combinearchivedir
 from elbepack.config import cfg
-from elbepack.directories import elbe_exe
+from elbepack.directories import elbe_exe, xml_schema_file
 from elbepack.isooptions import iso_option_valid
 from elbepack.shellhelper import CommandError, command_out_stderr
 from elbepack.validate import error_log_to_strings
@@ -317,7 +317,7 @@ def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None, gz
 
     schema_file = 'https://www.linutronix.de/projects/Elbe/dbsfed.xsd'
     parser = XMLParser(huge_tree=True)
-    schema_tree = etree.parse(schema_file)
+    schema_tree = etree.parse(xml_schema_file(schema_file))
     schema = etree.XMLSchema(schema_tree)
 
     try:
-- 
2.44.0



More information about the elbe-devel mailing list