[elbe-devel] [PATCH 1/2] elbepack: unify parsing of Built-Using strings

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Apr 24 10:29:49 CEST 2024


While at it also add some tests for it.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/aptpkgutils.py          | 30 +++++++++++++++++++++---------
 elbepack/commands/check-build.py |  9 +++------
 elbepack/tests/test_doctest.py   |  8 ++++++--
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
index d1382298e171..567e3f288364 100644
--- a/elbepack/aptpkgutils.py
+++ b/elbepack/aptpkgutils.py
@@ -151,6 +151,25 @@ def fetch_source(name, version, destdir, progress=None):
     return os.path.abspath(dsc)
 
 
+def parse_built_using(value):
+    """
+    >>> list(parse_built_using(None))
+    []
+
+    >>> list(parse_built_using('grub2 (= 1.99-9), loadlin (= 1.6e-1)'))
+    [('grub2', '1.99-9'), ('loadlin', '1.6e-1')]
+    """
+
+    if value is None:
+        return
+
+    built_using_lst = value.split(', ')
+    for built_using in built_using_lst:
+        name, version = built_using.split(' ', 1)
+        version = version.strip('(= )')
+        yield name, version
+
+
 def get_corresponding_source_packages(cache, pkg_lst=None):
 
     if pkg_lst is None:
@@ -166,15 +185,8 @@ def get_corresponding_source_packages(cache, pkg_lst=None):
 
         src_set.add((version.source_name, version.source_version))
 
-        built_using = version.record.get('Built-Using')
-        if built_using is None:
-            continue
-
-        built_using_lst = built_using.split(', ')
-        for built_using in built_using_lst:
-            name, version = built_using.split(' ', 1)
-            version = version.strip('(= )')
-            src_set.add((name, version))
+        for name, ver in parse_built_using(version.record.get('Built-Using')):
+            src_set.add((name, ver))
 
     return list(src_set)
 
diff --git a/elbepack/commands/check-build.py b/elbepack/commands/check-build.py
index 91dcc057b7b3..94e007ea8b6a 100644
--- a/elbepack/commands/check-build.py
+++ b/elbepack/commands/check-build.py
@@ -14,6 +14,7 @@ import traceback
 import pexpect
 
 from elbepack import qemu_firmware
+from elbepack.aptpkgutils import parse_built_using
 from elbepack.directories import run_elbe
 from elbepack.filesystem import TmpdirFilesystem
 from elbepack.log import elbe_logging
@@ -312,13 +313,9 @@ class CheckCdroms(CheckBase):
                         # seperated by a comma
                         elif line.startswith('Built-Using:'):
 
-                            built_using = line.split('Built-Using:')[1].strip(' ').split(',')
-
-                            for src in built_using:
-
-                                name, version = src.strip(' ').split(' ', 1)
-                                version = version.strip('(= )')
+                            built_using = line.split('Built-Using:')[1].strip(' ')
 
+                            for name, version in parse_built_using(built_using):
                                 # TODO - This is not component aware!
                                 if name in sources:
                                     if version not in sources[name]:
diff --git a/elbepack/tests/test_doctest.py b/elbepack/tests/test_doctest.py
index ac09e8c456e1..14bda9aaa740 100644
--- a/elbepack/tests/test_doctest.py
+++ b/elbepack/tests/test_doctest.py
@@ -4,12 +4,16 @@
 
 import doctest
 
+import pytest
+
+import elbepack.aptpkgutils as aptpkgutils
 import elbepack.filesystem as filesystem
 import elbepack.shellhelper as shellhelper
 
 
-def test_shellhelper():
-    fail, _ = doctest.testmod(shellhelper)
+ at pytest.mark.parametrize('mod', [shellhelper, aptpkgutils])
+def test(mod):
+    fail, _ = doctest.testmod(mod)
     assert fail == 0
 
 

-- 
2.44.0



More information about the elbe-devel mailing list