[elbe-devel] [PATCH 3/9] elbepack: avoid warnings in etree.find()

Thomas Weißschuh thomas.weissschuh at linutronix.de
Fri Jun 21 14:22:46 CEST 2024


The previous arguments were triggering warnings like the following:

    This search incorrectly ignores the root element, and will be fixed in a future version.
    If you rely on the current behaviour, change it to './target/debootstrap/include'

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/archivedir.py    | 2 +-
 elbepack/initvmaction.py  | 2 +-
 elbepack/validate.py      | 6 +++---
 elbepack/xmlpreprocess.py | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/elbepack/archivedir.py b/elbepack/archivedir.py
index 718cf9ac8f46..b04490c050a6 100644
--- a/elbepack/archivedir.py
+++ b/elbepack/archivedir.py
@@ -131,7 +131,7 @@ def _combinearchivedir(xml, xpath, use_volume):
 
 
 def combinearchivedir(xml):
-    if xml.find('//archivedir') is None:
+    if xml.find('.//archivedir') is None:
         return xml
 
     _combinearchivedir(xml, 'archivedir', False)
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index a3eed12b550c..bf520c4250d4 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -218,7 +218,7 @@ class StartAction(InitVMAction):
             return
 
         xml = etree(io.StringIO(self.initvm.XMLDesc()))
-        disk = xml.et.find('/devices/disk')
+        disk = xml.et.find('.//devices/disk')
 
         for source in disk.findall('.//source'):
             flags = os.O_RDWR if source.getparent() is disk else os.O_RDONLY
diff --git a/elbepack/validate.py b/elbepack/validate.py
index 68ca2f5c50c6..d578ecc126dd 100644
--- a/elbepack/validate.py
+++ b/elbepack/validate.py
@@ -64,17 +64,17 @@ def validate_xml_content(xml):
     #
     # If apt-transport-https or ca-certificates is included in bootstrap,
     # we are probably fine
-    bootstrap_include = xml.findtext('/target/debootstrap/include', '')
+    bootstrap_include = xml.findtext('./target/debootstrap/include', '')
     if ('apt-transport-https' not in bootstrap_include
        and 'ca-certificates' not in bootstrap_include):
 
         # Check if primary mirror is using https
-        primary_proto = xml.findtext('/project/mirror/primary_proto', '')
+        primary_proto = xml.findtext('./project/mirror/primary_proto', '')
         is_primary_proto_https = (primary_proto.lower() == 'https')
 
         # Check if any additional mirror is using https
         has_https_urls = False
-        for url in xml.findall('/project/mirror/url-list/url'):
+        for url in xml.findall('./project/mirror/url-list/url'):
             b = url.findtext('binary', '').lower()
             s = url.findtext('source', '').lower()
             if b.startswith('https') or s.startswith('https'):
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 1392ebbd70ba..f1c4c52d12bb 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -146,7 +146,7 @@ def preprocess_pkg_pinning(xml):
     """Do search and replace on pkg attributes, replacing 'pin' with 'release-name'."""
 
     errors = False
-    for pkg in xml.iterfind('//target/pkg-list/pkg'):
+    for pkg in xml.iterfind('.//target/pkg-list/pkg'):
         if 'pin' in pkg.attrib:
             if 'release-name' in pkg.attrib:
                 logging.error(
@@ -180,7 +180,7 @@ def preprocess_pkg_pinning(xml):
 def preprocess_check_script(xml, basedir):
     """Inline check scripts"""
 
-    for script in xml.iterfind('//check-image-list/check-script'):
+    for script in xml.iterfind('.//check-image-list/check-script'):
         location = script.attrib.pop('location', None)
         if location is None:
             continue

-- 
2.45.2



More information about the elbe-devel mailing list