diff options
author | Philip Lorenz <philip.lorenz@bmw.de> | 2024-05-16 09:24:38 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-28 09:38:23 +0100 |
commit | f7e9eb03d2d9b69514a902692e5539a1b7661c1f (patch) | |
tree | f47ee9cc8bb803040c0eb9218f75f6c2043089dd /meta/lib/oe/package_manager/common_deb_ipk.py | |
parent | b2a59134dcbf0a8fffa76076bc578ecd5791c968 (diff) | |
download | poky-f7e9eb03d2d9b69514a902692e5539a1b7661c1f.tar.gz |
package_manager: Move OpkgDpkgPM into common module
The OpkgDpkgPM class was introduced to share common functionality
between the Opkg and Debian package manager implementations. However,
for unknown reasons , the refactoring done in
5bc67f55028407de78ac09f97f9a47b165ae8760 duplicated the common class
into the deb and ipk modules. Undo this part of the change by moving the
common base class into a newly created module.
The two variants did not diverge a lot (next to the payload name
generalization, the Debian variant missed
17e2eaed036e1da8e7cb42cb3de51b9523ba54ec) and as such no regressions
should be expected.
(From OE-Core rev: c7830c5879f6fa68fa9f47ee59b7bf7f2d276c81)
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/oe/package_manager/common_deb_ipk.py')
-rw-r--r-- | meta/lib/oe/package_manager/common_deb_ipk.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/meta/lib/oe/package_manager/common_deb_ipk.py b/meta/lib/oe/package_manager/common_deb_ipk.py new file mode 100644 index 0000000000..c91a4b4565 --- /dev/null +++ b/meta/lib/oe/package_manager/common_deb_ipk.py | |||
@@ -0,0 +1,89 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: GPL-2.0-only | ||
5 | # | ||
6 | |||
7 | import glob | ||
8 | import os | ||
9 | import subprocess | ||
10 | import tempfile | ||
11 | |||
12 | import bb | ||
13 | |||
14 | from oe.package_manager import opkg_query, PackageManager | ||
15 | |||
16 | class OpkgDpkgPM(PackageManager): | ||
17 | def __init__(self, d, target_rootfs): | ||
18 | """ | ||
19 | This is an abstract class. Do not instantiate this directly. | ||
20 | """ | ||
21 | super(OpkgDpkgPM, self).__init__(d, target_rootfs) | ||
22 | |||
23 | def package_info(self, pkg, cmd): | ||
24 | """ | ||
25 | Returns a dictionary with the package info. | ||
26 | |||
27 | This method extracts the common parts for Opkg and Dpkg | ||
28 | """ | ||
29 | |||
30 | proc = subprocess.run(cmd, capture_output=True, encoding="utf-8", shell=True) | ||
31 | if proc.returncode: | ||
32 | bb.fatal("Unable to list available packages. Command '%s' " | ||
33 | "returned %d:\n%s" % (cmd, proc.returncode, proc.stderr)) | ||
34 | elif proc.stderr: | ||
35 | bb.note("Command '%s' returned stderr: %s" % (cmd, proc.stderr)) | ||
36 | |||
37 | return opkg_query(proc.stdout) | ||
38 | |||
39 | def extract(self, pkg, pkg_info): | ||
40 | """ | ||
41 | Returns the path to a tmpdir where resides the contents of a package. | ||
42 | |||
43 | Deleting the tmpdir is responsability of the caller. | ||
44 | |||
45 | This method extracts the common parts for Opkg and Dpkg | ||
46 | """ | ||
47 | |||
48 | ar_cmd = bb.utils.which(os.getenv("PATH"), "ar") | ||
49 | tar_cmd = bb.utils.which(os.getenv("PATH"), "tar") | ||
50 | pkg_path = pkg_info[pkg]["filepath"] | ||
51 | |||
52 | if not os.path.isfile(pkg_path): | ||
53 | bb.fatal("Unable to extract package for '%s'." | ||
54 | "File %s doesn't exists" % (pkg, pkg_path)) | ||
55 | |||
56 | tmp_dir = tempfile.mkdtemp() | ||
57 | current_dir = os.getcwd() | ||
58 | os.chdir(tmp_dir) | ||
59 | |||
60 | try: | ||
61 | cmd = [ar_cmd, 'x', pkg_path] | ||
62 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
63 | data_tar = glob.glob("data.tar.*") | ||
64 | if len(data_tar) != 1: | ||
65 | bb.fatal("Unable to extract %s package. Failed to identify " | ||
66 | "data tarball (found tarballs '%s').", | ||
67 | pkg_path, data_tar) | ||
68 | data_tar = data_tar[0] | ||
69 | cmd = [tar_cmd, 'xf', data_tar] | ||
70 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
71 | except subprocess.CalledProcessError as e: | ||
72 | bb.utils.remove(tmp_dir, recurse=True) | ||
73 | bb.fatal("Unable to extract %s package. Command '%s' " | ||
74 | "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8"))) | ||
75 | except OSError as e: | ||
76 | bb.utils.remove(tmp_dir, recurse=True) | ||
77 | bb.fatal("Unable to extract %s package. Command '%s' " | ||
78 | "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename)) | ||
79 | |||
80 | bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) | ||
81 | bb.utils.remove(os.path.join(tmp_dir, "debian-binary")) | ||
82 | bb.utils.remove(os.path.join(tmp_dir, "control.tar.gz")) | ||
83 | bb.utils.remove(os.path.join(tmp_dir, data_tar)) | ||
84 | os.chdir(current_dir) | ||
85 | |||
86 | return tmp_dir | ||
87 | |||
88 | def _handle_intercept_failure(self, registered_pkgs): | ||
89 | self.mark_packages("unpacked", registered_pkgs.split()) | ||