[elbe-devel] [PATCH v6] elbepack: use custom Origin class

Eduard Krein eduard.krein at linutronix.de
Mon Jun 24 13:04:15 CEST 2024


Instead of using a string of three attributes use a custom Origin class
which contains the necessary attributes and more and can be used more flexible.

Signed-off-by: Eduard Krein <eduard.krein at linutronix.de>
---
 elbepack/aptpkgutils.py | 11 ++++++++++-
 elbepack/dump.py        |  5 +++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
index c4b7b591..4120c918 100644
--- a/elbepack/aptpkgutils.py
+++ b/elbepack/aptpkgutils.py
@@ -3,6 +3,7 @@
 # SPDX-FileCopyrightText: 2005-2009 Canonical
 # SPDX-FileCopyrightText: 2014, 2017 Linutronix GmbH
 
+import dataclasses
 import os
 
 import apt
@@ -36,6 +37,14 @@ _apt_hash_mapping = {
 }
 
 
+ at dataclasses.dataclass
+class Origin:
+    origin: str
+    codename: str
+    site: str
+    component: str
+
+
 def _apt_pkg_hashes(pkg):
     r = {}
 
@@ -92,7 +101,7 @@ def pkgstate(pkg):
 def pkgorigin(pkg):
     if pkg.installed:
         o = pkg.installed.origins[0]
-        origin = f'{o.site} {o.codename} {o.component}'
+        origin = Origin(origin=o.origin, codename=o.codename, site=o.site, component=o.component)
     else:
         origin = None
 
diff --git a/elbepack/dump.py b/elbepack/dump.py
index 814b7330..90522123 100644
--- a/elbepack/dump.py
+++ b/elbepack/dump.py
@@ -202,7 +202,7 @@ def elbe_report(xml, buildenv, cache, targetfs):
 
     groups = collections.defaultdict(list)
     for p in instpkgs:
-        o, _, _ = p.origin.split(' ')
+        o = p.origin.site
         if o.endswith('.debian.org'):
             # Group upstream packages together.
             o = 'Debian'
@@ -217,7 +217,8 @@ def elbe_report(xml, buildenv, cache, targetfs):
         report.info('')
 
         for p in pkgs:
-            report.info('|%s|%s|%s', p.name, p.installed_version, p.origin)
+            report.info('|%s|%s|%s', p.name, p.installed_version,
+                        f'{p.origin.site} {p.origin.codename} {p.origin.component}')
 
     index = cache.get_fileindex(removeprefix='/usr')
     mt_index = targetfs.mtime_snap()
-- 
2.39.2



More information about the elbe-devel mailing list