diff options
author | Philip Lorenz <philip.lorenz@bmw.de> | 2024-05-16 09:24:39 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-28 09:38:23 +0100 |
commit | e51697ef90c850c7c07feb9f6040a19a41d77c2b (patch) | |
tree | dc44f9fbf71bf9c0a2ceefceb4dca172c520fc13 /meta/lib | |
parent | f7e9eb03d2d9b69514a902692e5539a1b7661c1f (diff) | |
download | poky-e51697ef90c850c7c07feb9f6040a19a41d77c2b.tar.gz |
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.
(From OE-Core rev: c4b126e216dfe8251ec55074be78188fcc3fcea8)
Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/package_manager/common_deb_ipk.py | 16 | ||||
-rw-r--r-- | meta/lib/oe/package_manager/deb/__init__.py | 19 | ||||
-rw-r--r-- | 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 c91a4b4565..6a1e28ee6f 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): | |||
20 | """ | 20 | """ |
21 | super(OpkgDpkgPM, self).__init__(d, target_rootfs) | 21 | super(OpkgDpkgPM, self).__init__(d, target_rootfs) |
22 | 22 | ||
23 | def package_info(self, pkg, cmd): | 23 | def package_info(self, pkg): |
24 | """ | 24 | """ |
25 | Returns a dictionary with the package info. | 25 | Returns a dictionary with the package info. |
26 | """ | ||
27 | raise NotImplementedError | ||
28 | |||
29 | def _common_package_info(self, cmd): | ||
30 | """ | ||
31 | "Returns a dictionary with the package info. | ||
26 | 32 | ||
27 | This method extracts the common parts for Opkg and Dpkg | 33 | This method extracts the common parts for Opkg and Dpkg |
28 | """ | 34 | """ |
@@ -36,14 +42,16 @@ class OpkgDpkgPM(PackageManager): | |||
36 | 42 | ||
37 | return opkg_query(proc.stdout) | 43 | return opkg_query(proc.stdout) |
38 | 44 | ||
39 | def extract(self, pkg, pkg_info): | 45 | def extract(self, pkg): |
40 | """ | 46 | """ |
41 | Returns the path to a tmpdir where resides the contents of a package. | 47 | Returns the path to a tmpdir where resides the contents of a package. |
42 | 48 | ||
43 | Deleting the tmpdir is responsability of the caller. | 49 | Deleting the tmpdir is responsability of the caller. |
44 | |||
45 | This method extracts the common parts for Opkg and Dpkg | ||
46 | """ | 50 | """ |
51 | pkg_info = self.package_info(pkg) | ||
52 | if not pkg_info: | ||
53 | bb.fatal("Unable to get information for package '%s' while " | ||
54 | "trying to extract the package." % pkg) | ||
47 | 55 | ||
48 | ar_cmd = bb.utils.which(os.getenv("PATH"), "ar") | 56 | ar_cmd = bb.utils.which(os.getenv("PATH"), "ar") |
49 | tar_cmd = bb.utils.which(os.getenv("PATH"), "tar") | 57 | 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 a96e56b2ad..e09e81e490 100644 --- a/meta/lib/oe/package_manager/deb/__init__.py +++ b/meta/lib/oe/package_manager/deb/__init__.py | |||
@@ -7,7 +7,7 @@ | |||
7 | import re | 7 | import re |
8 | import subprocess | 8 | import subprocess |
9 | from oe.package_manager import * | 9 | from oe.package_manager import * |
10 | from oe.package_manager import OpkgDpkgPM | 10 | from oe.package_manager.common_deb_ipk import OpkgDpkgPM |
11 | 11 | ||
12 | class DpkgIndexer(Indexer): | 12 | class DpkgIndexer(Indexer): |
13 | def _create_configs(self): | 13 | def _create_configs(self): |
@@ -431,7 +431,7 @@ class DpkgPM(OpkgDpkgPM): | |||
431 | Returns a dictionary with the package info. | 431 | Returns a dictionary with the package info. |
432 | """ | 432 | """ |
433 | cmd = "%s show %s" % (self.apt_cache_cmd, pkg) | 433 | cmd = "%s show %s" % (self.apt_cache_cmd, pkg) |
434 | pkg_info = super(DpkgPM, self).package_info(pkg, cmd) | 434 | pkg_info = self._common_package_info(cmd) |
435 | 435 | ||
436 | pkg_arch = pkg_info[pkg]["pkgarch"] | 436 | pkg_arch = pkg_info[pkg]["pkgarch"] |
437 | pkg_filename = pkg_info[pkg]["filename"] | 437 | pkg_filename = pkg_info[pkg]["filename"] |
@@ -439,18 +439,3 @@ class DpkgPM(OpkgDpkgPM): | |||
439 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) | 439 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) |
440 | 440 | ||
441 | return pkg_info | 441 | return pkg_info |
442 | |||
443 | def extract(self, pkg): | ||
444 | """ | ||
445 | Returns the path to a tmpdir where resides the contents of a package. | ||
446 | |||
447 | Deleting the tmpdir is responsability of the caller. | ||
448 | """ | ||
449 | pkg_info = self.package_info(pkg) | ||
450 | if not pkg_info: | ||
451 | bb.fatal("Unable to get information for package '%s' while " | ||
452 | "trying to extract the package." % pkg) | ||
453 | |||
454 | tmp_dir = super(DpkgPM, self).extract(pkg, pkg_info) | ||
455 | |||
456 | return tmp_dir | ||
diff --git a/meta/lib/oe/package_manager/ipk/__init__.py b/meta/lib/oe/package_manager/ipk/__init__.py index 23536294b0..3d998e52ff 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): | |||
416 | Returns a dictionary with the package info. | 416 | Returns a dictionary with the package info. |
417 | """ | 417 | """ |
418 | cmd = "%s %s info %s" % (self.opkg_cmd, self.opkg_args, pkg) | 418 | cmd = "%s %s info %s" % (self.opkg_cmd, self.opkg_args, pkg) |
419 | pkg_info = super(OpkgPM, self).package_info(pkg, cmd) | 419 | pkg_info = self._common_package_info(cmd) |
420 | 420 | ||
421 | pkg_arch = pkg_info[pkg]["arch"] | 421 | pkg_arch = pkg_info[pkg]["arch"] |
422 | pkg_filename = pkg_info[pkg]["filename"] | 422 | pkg_filename = pkg_info[pkg]["filename"] |
@@ -424,16 +424,3 @@ class OpkgPM(OpkgDpkgPM): | |||
424 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) | 424 | os.path.join(self.deploy_dir, pkg_arch, pkg_filename) |
425 | 425 | ||
426 | return pkg_info | 426 | return pkg_info |
427 | |||
428 | def extract(self, pkg): | ||
429 | """ | ||
430 | Returns the path to a tmpdir where resides the contents of a package. | ||
431 | |||
432 | Deleting the tmpdir is responsability of the caller. | ||
433 | """ | ||
434 | pkg_info = self.package_info(pkg) | ||
435 | if not pkg_info: | ||
436 | bb.fatal("Unable to get information for package '%s' while " | ||
437 | "trying to extract the package." % pkg) | ||
438 | |||
439 | return super(OpkgPM, self).extract(pkg, pkg_info) | ||