summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorPhilip Lorenz <philip.lorenz@bmw.de>2024-05-16 09:24:38 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-05-28 09:38:23 +0100
commitf7e9eb03d2d9b69514a902692e5539a1b7661c1f (patch)
treef47ee9cc8bb803040c0eb9218f75f6c2043089dd /meta/lib
parentb2a59134dcbf0a8fffa76076bc578ecd5791c968 (diff)
downloadpoky-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')
-rw-r--r--meta/lib/oe/package_manager/common_deb_ipk.py89
-rw-r--r--meta/lib/oe/package_manager/deb/__init__.py68
-rw-r--r--meta/lib/oe/package_manager/ipk/__init__.py78
3 files changed, 91 insertions, 144 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
7import glob
8import os
9import subprocess
10import tempfile
11
12import bb
13
14from oe.package_manager import opkg_query, PackageManager
15
16class 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())
diff --git a/meta/lib/oe/package_manager/deb/__init__.py b/meta/lib/oe/package_manager/deb/__init__.py
index 0c23c884c1..a96e56b2ad 100644
--- a/meta/lib/oe/package_manager/deb/__init__.py
+++ b/meta/lib/oe/package_manager/deb/__init__.py
@@ -7,6 +7,7 @@
7import re 7import re
8import subprocess 8import subprocess
9from oe.package_manager import * 9from oe.package_manager import *
10from oe.package_manager import OpkgDpkgPM
10 11
11class DpkgIndexer(Indexer): 12class DpkgIndexer(Indexer):
12 def _create_configs(self): 13 def _create_configs(self):
@@ -111,72 +112,6 @@ class PMPkgsList(PkgsList):
111 112
112 return opkg_query(cmd_output) 113 return opkg_query(cmd_output)
113 114
114class OpkgDpkgPM(PackageManager):
115 def __init__(self, d, target_rootfs):
116 """
117 This is an abstract class. Do not instantiate this directly.
118 """
119 super(OpkgDpkgPM, self).__init__(d, target_rootfs)
120
121 def package_info(self, pkg, cmd):
122 """
123 Returns a dictionary with the package info.
124
125 This method extracts the common parts for Opkg and Dpkg
126 """
127
128 try:
129 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).decode("utf-8")
130 except subprocess.CalledProcessError as e:
131 bb.fatal("Unable to list available packages. Command '%s' "
132 "returned %d:\n%s" % (cmd, e.returncode, e.output.decode("utf-8")))
133 return opkg_query(output)
134
135 def extract(self, pkg, pkg_info):
136 """
137 Returns the path to a tmpdir where resides the contents of a package.
138
139 Deleting the tmpdir is responsability of the caller.
140
141 This method extracts the common parts for Opkg and Dpkg
142 """
143
144 ar_cmd = bb.utils.which(os.getenv("PATH"), "ar")
145 tar_cmd = bb.utils.which(os.getenv("PATH"), "tar")
146 pkg_path = pkg_info[pkg]["filepath"]
147
148 if not os.path.isfile(pkg_path):
149 bb.fatal("Unable to extract package for '%s'."
150 "File %s doesn't exists" % (pkg, pkg_path))
151
152 tmp_dir = tempfile.mkdtemp()
153 current_dir = os.getcwd()
154 os.chdir(tmp_dir)
155 data_tar = 'data.tar.xz'
156
157 try:
158 cmd = [ar_cmd, 'x', pkg_path]
159 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
160 cmd = [tar_cmd, 'xf', data_tar]
161 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
162 except subprocess.CalledProcessError as e:
163 bb.utils.remove(tmp_dir, recurse=True)
164 bb.fatal("Unable to extract %s package. Command '%s' "
165 "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8")))
166 except OSError as e:
167 bb.utils.remove(tmp_dir, recurse=True)
168 bb.fatal("Unable to extract %s package. Command '%s' "
169 "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename))
170
171 bb.note("Extracted %s to %s" % (pkg_path, tmp_dir))
172 bb.utils.remove(os.path.join(tmp_dir, "debian-binary"))
173 bb.utils.remove(os.path.join(tmp_dir, "control.tar.gz"))
174 os.chdir(current_dir)
175
176 return tmp_dir
177
178 def _handle_intercept_failure(self, registered_pkgs):
179 self.mark_packages("unpacked", registered_pkgs.split())
180 115
181class DpkgPM(OpkgDpkgPM): 116class DpkgPM(OpkgDpkgPM):
182 def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None, deb_repo_workdir="oe-rootfs-repo", filterbydependencies=True): 117 def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None, deb_repo_workdir="oe-rootfs-repo", filterbydependencies=True):
@@ -517,6 +452,5 @@ class DpkgPM(OpkgDpkgPM):
517 "trying to extract the package." % pkg) 452 "trying to extract the package." % pkg)
518 453
519 tmp_dir = super(DpkgPM, self).extract(pkg, pkg_info) 454 tmp_dir = super(DpkgPM, self).extract(pkg, pkg_info)
520 bb.utils.remove(os.path.join(tmp_dir, "data.tar.xz"))
521 455
522 return tmp_dir 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 47e72cc7a6..23536294b0 100644
--- a/meta/lib/oe/package_manager/ipk/__init__.py
+++ b/meta/lib/oe/package_manager/ipk/__init__.py
@@ -4,11 +4,11 @@
4# SPDX-License-Identifier: GPL-2.0-only 4# SPDX-License-Identifier: GPL-2.0-only
5# 5#
6 6
7import glob
8import re 7import re
9import shutil 8import shutil
10import subprocess 9import subprocess
11from oe.package_manager import * 10from oe.package_manager import *
11from oe.package_manager.common_deb_ipk import OpkgDpkgPM
12 12
13class OpkgIndexer(Indexer): 13class OpkgIndexer(Indexer):
14 def write_index(self): 14 def write_index(self):
@@ -91,82 +91,6 @@ class PMPkgsList(PkgsList):
91 return opkg_query(cmd_output) 91 return opkg_query(cmd_output)
92 92
93 93
94
95class OpkgDpkgPM(PackageManager):
96 def __init__(self, d, target_rootfs):
97 """
98 This is an abstract class. Do not instantiate this directly.
99 """
100 super(OpkgDpkgPM, self).__init__(d, target_rootfs)
101
102 def package_info(self, pkg, cmd):
103 """
104 Returns a dictionary with the package info.
105
106 This method extracts the common parts for Opkg and Dpkg
107 """
108
109 proc = subprocess.run(cmd, capture_output=True, encoding="utf-8", shell=True)
110 if proc.returncode:
111 bb.fatal("Unable to list available packages. Command '%s' "
112 "returned %d:\n%s" % (cmd, proc.returncode, proc.stderr))
113 elif proc.stderr:
114 bb.note("Command '%s' returned stderr: %s" % (cmd, proc.stderr))
115
116 return opkg_query(proc.stdout)
117
118 def extract(self, pkg, pkg_info):
119 """
120 Returns the path to a tmpdir where resides the contents of a package.
121
122 Deleting the tmpdir is responsability of the caller.
123
124 This method extracts the common parts for Opkg and Dpkg
125 """
126
127 ar_cmd = bb.utils.which(os.getenv("PATH"), "ar")
128 tar_cmd = bb.utils.which(os.getenv("PATH"), "tar")
129 pkg_path = pkg_info[pkg]["filepath"]
130
131 if not os.path.isfile(pkg_path):
132 bb.fatal("Unable to extract package for '%s'."
133 "File %s doesn't exists" % (pkg, pkg_path))
134
135 tmp_dir = tempfile.mkdtemp()
136 current_dir = os.getcwd()
137 os.chdir(tmp_dir)
138
139 try:
140 cmd = [ar_cmd, 'x', pkg_path]
141 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
142 data_tar = glob.glob("data.tar.*")
143 if len(data_tar) != 1:
144 bb.fatal("Unable to extract %s package. Failed to identify "
145 "data tarball (found tarballs '%s').",
146 pkg_path, data_tar)
147 data_tar = data_tar[0]
148 cmd = [tar_cmd, 'xf', data_tar]
149 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
150 except subprocess.CalledProcessError as e:
151 bb.utils.remove(tmp_dir, recurse=True)
152 bb.fatal("Unable to extract %s package. Command '%s' "
153 "returned %d:\n%s" % (pkg_path, ' '.join(cmd), e.returncode, e.output.decode("utf-8")))
154 except OSError as e:
155 bb.utils.remove(tmp_dir, recurse=True)
156 bb.fatal("Unable to extract %s package. Command '%s' "
157 "returned %d:\n%s at %s" % (pkg_path, ' '.join(cmd), e.errno, e.strerror, e.filename))
158
159 bb.note("Extracted %s to %s" % (pkg_path, tmp_dir))
160 bb.utils.remove(os.path.join(tmp_dir, "debian-binary"))
161 bb.utils.remove(os.path.join(tmp_dir, "control.tar.gz"))
162 bb.utils.remove(os.path.join(tmp_dir, data_tar))
163 os.chdir(current_dir)
164
165 return tmp_dir
166
167 def _handle_intercept_failure(self, registered_pkgs):
168 self.mark_packages("unpacked", registered_pkgs.split())
169
170class OpkgPM(OpkgDpkgPM): 94class OpkgPM(OpkgDpkgPM):
171 def __init__(self, d, target_rootfs, config_file, archs, task_name='target', ipk_repo_workdir="oe-rootfs-repo", filterbydependencies=True, prepare_index=True): 95 def __init__(self, d, target_rootfs, config_file, archs, task_name='target', ipk_repo_workdir="oe-rootfs-repo", filterbydependencies=True, prepare_index=True):
172 super(OpkgPM, self).__init__(d, target_rootfs) 96 super(OpkgPM, self).__init__(d, target_rootfs)