From c4b126e216dfe8251ec55074be78188fcc3fcea8 Mon Sep 17 00:00:00 2001 From: Philip Lorenz Date: Thu, 16 May 2024 09:24:39 +0200 Subject: [PATCH] package_manager: Share more common DEB / IPK code Avoid code duplication by making `extract` a shared method (and retrieving the package manager specific input via an abstract method). Additionally, follow Python conventions and prefix class internal methods with "_" to indicate that they shouldn't be called externally. Signed-off-by: Philip Lorenz Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- meta/lib/oe/package_manager/common_deb_ipk.py | 16 ++++++++++++---- meta/lib/oe/package_manager/deb/__init__.py | 19 ++----------------- meta/lib/oe/package_manager/ipk/__init__.py | 15 +-------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/meta/lib/oe/package_manager/common_deb_ipk.py b/meta/lib/oe/package_manager/common_deb_ipk.py index c91a4b45650..6a1e28ee6f9 100644 --- a/meta/lib/oe/package_manager/common_deb_ipk.py +++ b/meta/lib/oe/package_manager/common_deb_ipk.py @@ -20,9 +20,15 @@ class OpkgDpkgPM(PackageManager): """ super(OpkgDpkgPM, self).__init__(d, target_rootfs) - def package_info(self, pkg, cmd): + def package_info(self, pkg): """ Returns a dictionary with the package info. + """ + raise NotImplementedError + + def _common_package_info(self, cmd): + """ + "Returns a dictionary with the package info. This method extracts the common parts for Opkg and Dpkg """ @@ -36,14 +42,16 @@ class OpkgDpkgPM(PackageManager): return opkg_query(proc.stdout) - def extract(self, pkg, pkg_info): + def extract(self, pkg): """ Returns the path to a tmpdir where resides the contents of a package. Deleting the tmpdir is responsability of the caller. - - This method extracts the common parts for Opkg and Dpkg """ + pkg_info = self.package_info(pkg) + if not pkg_info: + bb.fatal("Unable to get information for package '%s' while " + "trying to extract the package." % pkg) ar_cmd = bb.utils.which(os.getenv("PATH"), "ar") tar_cmd = bb.utils.which(os.getenv("PATH"), "tar") diff --git a/meta/lib/oe/package_manager/deb/__init__.py b/meta/lib/oe/package_manager/deb/__init__.py index a96e56b2ada..e09e81e4901 100644 --- a/meta/lib/oe/package_manager/deb/__init__.py +++ b/meta/lib/oe/package_manager/deb/__init__.py @@ -7,7 +7,7 @@ import re import subprocess from oe.package_manager import * -from oe.package_manager import OpkgDpkgPM +from oe.package_manager.common_deb_ipk import OpkgDpkgPM class DpkgIndexer(Indexer): def _create_configs(self): @@ -431,7 +431,7 @@ class DpkgPM(OpkgDpkgPM): Returns a dictionary with the package info. """ cmd = "%s show %s" % (self.apt_cache_cmd, pkg) - pkg_info = super(DpkgPM, self).package_info(pkg, cmd) + pkg_info = self._common_package_info(cmd) pkg_arch = pkg_info[pkg]["pkgarch"] pkg_filename = pkg_info[pkg]["filename"] @@ -439,18 +439,3 @@ class DpkgPM(OpkgDpkgPM): os.path.join(self.deploy_dir, pkg_arch, pkg_filename) return pkg_info - - def extract(self, pkg): - """ - Returns the path to a tmpdir where resides the contents of a package. - - Deleting the tmpdir is responsability of the caller. - """ - pkg_info = self.package_info(pkg) - if not pkg_info: - bb.fatal("Unable to get information for package '%s' while " - "trying to extract the package." % pkg) - - tmp_dir = super(DpkgPM, self).extract(pkg, pkg_info) - - return tmp_dir diff --git a/meta/lib/oe/package_manager/ipk/__init__.py b/meta/lib/oe/package_manager/ipk/__init__.py index 23536294b0b..3d998e52ff1 100644 --- a/meta/lib/oe/package_manager/ipk/__init__.py +++ b/meta/lib/oe/package_manager/ipk/__init__.py @@ -416,7 +416,7 @@ class OpkgPM(OpkgDpkgPM): Returns a dictionary with the package info. """ cmd = "%s %s info %s" % (self.opkg_cmd, self.opkg_args, pkg) - pkg_info = super(OpkgPM, self).package_info(pkg, cmd) + pkg_info = self._common_package_info(cmd) pkg_arch = pkg_info[pkg]["arch"] pkg_filename = pkg_info[pkg]["filename"] @@ -424,16 +424,3 @@ class OpkgPM(OpkgDpkgPM): os.path.join(self.deploy_dir, pkg_arch, pkg_filename) return pkg_info - - def extract(self, pkg): - """ - Returns the path to a tmpdir where resides the contents of a package. - - Deleting the tmpdir is responsability of the caller. - """ - pkg_info = self.package_info(pkg) - if not pkg_info: - bb.fatal("Unable to get information for package '%s' while " - "trying to extract the package." % pkg) - - return super(OpkgPM, self).extract(pkg, pkg_info) -- 2.47.3