[elbe-devel] [PATCH 1/5] rpcaptcache: Add get_corresponding_source_packages
Olivier Dion
dion at linutronix.de
Wed May 20 04:26:59 CEST 2020
The method constructs a set of source packages from a list of binary
packages. This former includes the sources of the binaries, but also
the built-using sources.
A list of unique tuples of the form (src_name, src_version) is
returned.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/rpcaptcache.py | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
index 5a1bb01a..14c3f654 100644
--- a/elbepack/rpcaptcache.py
+++ b/elbepack/rpcaptcache.py
@@ -16,7 +16,7 @@ import time
from multiprocessing.util import Finalize
from multiprocessing.managers import BaseManager
-from apt_pkg import config, version_compare
+from apt_pkg import config, version_compare, TagFile
from apt import Cache
from elbepack.aptprogress import (ElbeAcquireProgress, ElbeInstallProgress,
@@ -289,6 +289,36 @@ class RPCAPTCache(InChRootObject):
self.cache[p]) for p in sorted(
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)
+
def compare_versions(self, ver1, ver2):
return version_compare(ver1, ver2)
--
2.26.2
More information about the elbe-devel
mailing list