[elbe-devel] [PATCH 12/14] elbepack: split corresponding_source_packages into utility function
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Wed Feb 28 11:39:05 CET 2024
This makes it usable from fetch_initvm_pkgs.py.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/aptpkgutils.py | 31 +++++++++++++++++++++++++++++
elbepack/rpcaptcache.py | 43 +++++++++--------------------------------
2 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
index a0992de3e2e2..37cf8489e3d5 100644
--- a/elbepack/aptpkgutils.py
+++ b/elbepack/aptpkgutils.py
@@ -203,6 +203,37 @@ def fetch_source(name, version, destdir, progress=None):
return os.path.abspath(dsc)
+def get_corresponding_source_packages(cache, pkg_lst=None):
+
+ if pkg_lst is None:
+ pkg_lst = {p.name for p in cache if p.is_installed}
+
+ src_set = set()
+
+ with apt_pkg.TagFile('/var/lib/dpkg/status') as tagfile:
+ for section in tagfile:
+
+ pkg = section['Package']
+
+ if pkg not in pkg_lst:
+ continue
+
+ tmp = cache[pkg].installed or cache[pkg].candidate
+
+ src_set.add((tmp.source_name, tmp.source_version))
+
+ if 'Built-Using' not in section:
+ continue
+
+ built_using_lst = section['Built-Using'].split(', ')
+ for built_using in built_using_lst:
+ name, version = built_using.split(' ', 1)
+ version = version.strip('(= )')
+ src_set.add((name, version))
+
+ return list(src_set)
+
+
class PackageBase:
def __init__(self, name,
diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
index 66519669838e..3ed460353ff0 100644
--- a/elbepack/rpcaptcache.py
+++ b/elbepack/rpcaptcache.py
@@ -11,13 +11,15 @@ from multiprocessing.util import Finalize
from apt import Cache
-from apt_pkg import (
- TagFile,
- config,
- version_compare,
+from apt_pkg import config, version_compare
+
+from elbepack.aptpkgutils import (
+ APTPackage,
+ fetch_binary,
+ fetch_source,
+ get_corresponding_source_packages,
+ getalldeps,
)
-
-from elbepack.aptpkgutils import APTPackage, fetch_binary, fetch_source, getalldeps
from elbepack.aptprogress import (
ElbeAcquireProgress,
ElbeInstallProgress,
@@ -318,34 +320,7 @@ class RPCAPTCache(InChRootObject):
self.cache.keys()) if pkgname in p.lower()]
def get_corresponding_source_packages(self, pkg_lst=None):
-
- if pkg_lst is None:
- pkg_lst = {p.name for p in self.cache if p.is_installed}
-
- src_set = set()
-
- with TagFile('/var/lib/dpkg/status') as tagfile:
- for section in tagfile:
-
- pkg = section['Package']
-
- if pkg not in pkg_lst:
- continue
-
- tmp = self.cache[pkg].installed or self.cache[pkg].candidate
-
- src_set.add((tmp.source_name, tmp.source_version))
-
- if 'Built-Using' not in section:
- continue
-
- built_using_lst = section['Built-Using'].split(', ')
- for built_using in built_using_lst:
- name, version = built_using.split(' ', 1)
- version = version.strip('(= )')
- src_set.add((name, version))
-
- return list(src_set)
+ return get_corresponding_source_packages(self.cache, pkg_lst)
@staticmethod
def compare_versions(self, ver1, ver2):
--
2.44.0
More information about the elbe-devel
mailing list