diff options
author | Laurentiu Palcu <laurentiu.palcu@intel.com> | 2014-01-13 10:10:09 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-02-11 11:53:39 +0000 |
commit | ed83ace10a850aec516d492c5a2f7508d9749910 (patch) | |
tree | 4befc22e733b8989d5ac1c7759e730a6b6e9ca03 | |
parent | 2979098c57d827b95c5be6d08f5d7dec4ef50599 (diff) | |
download | poky-ed83ace10a850aec516d492c5a2f7508d9749910.tar.gz |
lib/oe/package_manager.py: add support for opkg backend
Additionaly, the commit contains a couple of minor changes
(comments, error printing, etc).
(From OE-Core rev: ef3faaef6b1a25c943a8d5594ce55b0e558b62f3)
Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/lib/oe/package_manager.py | 218 |
1 files changed, 210 insertions, 8 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py index fd86938ced..e06ded401a 100644 --- a/meta/lib/oe/package_manager.py +++ b/meta/lib/oe/package_manager.py | |||
@@ -14,7 +14,7 @@ def create_index(arg): | |||
14 | subprocess.check_output(index_cmd, shell=True) | 14 | subprocess.check_output(index_cmd, shell=True) |
15 | except subprocess.CalledProcessError as e: | 15 | except subprocess.CalledProcessError as e: |
16 | return("Index creation command %s failed with return code %d!" % | 16 | return("Index creation command %s failed with return code %d!" % |
17 | (' '.join(e.cmd), e.returncode)) | 17 | (e.cmd, e.returncode)) |
18 | 18 | ||
19 | return None | 19 | return None |
20 | 20 | ||
@@ -54,8 +54,7 @@ class PackageManager(object): | |||
54 | pass | 54 | pass |
55 | 55 | ||
56 | """ | 56 | """ |
57 | This function creates the Packages.gz files in each arch directory in | 57 | This function creates the index files |
58 | DEPLOY_DIR_DEB. | ||
59 | """ | 58 | """ |
60 | @abstractmethod | 59 | @abstractmethod |
61 | def write_index(self): | 60 | def write_index(self): |
@@ -138,12 +137,215 @@ class RpmPM(PackageManager): | |||
138 | 137 | ||
139 | 138 | ||
140 | class OpkgPM(PackageManager): | 139 | class OpkgPM(PackageManager): |
141 | def __init__(self): | 140 | def __init__(self, d, target_rootfs, config_file, archs): |
142 | super(OpkgPM, self).__init__() | 141 | super(OpkgPM, self).__init__(d) |
143 | 142 | ||
144 | """ | 143 | self.target_rootfs = target_rootfs |
145 | TBD | 144 | self.config_file = config_file |
146 | """ | 145 | self.pkg_archs = archs |
146 | |||
147 | self.deploy_dir = self.d.getVar("DEPLOY_DIR_IPK", True) | ||
148 | self.deploy_lock_file = os.path.join(self.deploy_dir, "deploy.lock") | ||
149 | |||
150 | self.opkg_cmd = bb.utils.which(os.getenv('PATH'), "opkg-cl") | ||
151 | self.opkg_args = "-f %s -o %s " % (self.config_file, target_rootfs) | ||
152 | self.opkg_args += self.d.getVar("OPKG_ARGS", True) | ||
153 | |||
154 | opkg_lib_dir = self.d.getVar('OPKGLIBDIR', True) | ||
155 | if opkg_lib_dir[0] == "/": | ||
156 | opkg_lib_dir = opkg_lib_dir[1:] | ||
157 | |||
158 | self.opkg_dir = os.path.join(target_rootfs, opkg_lib_dir, "opkg") | ||
159 | |||
160 | bb.utils.mkdirhier(self.opkg_dir) | ||
161 | |||
162 | self._create_config() | ||
163 | |||
164 | def _create_config(self): | ||
165 | with open(self.config_file, "w+") as config_file: | ||
166 | priority = 1 | ||
167 | for arch in self.pkg_archs.split(): | ||
168 | config_file.write("arch %s %d\n" % (arch, priority)) | ||
169 | priority += 5 | ||
170 | |||
171 | config_file.write("src oe file:%s\n" % self.deploy_dir) | ||
172 | |||
173 | for arch in self.pkg_archs.split(): | ||
174 | pkgs_dir = os.path.join(self.deploy_dir, arch) | ||
175 | if os.path.isdir(pkgs_dir): | ||
176 | config_file.write("src oe-%s file:%s\n" % (arch, pkgs_dir)) | ||
177 | |||
178 | def update(self): | ||
179 | self.deploy_dir_lock() | ||
180 | |||
181 | cmd = "%s %s update" % (self.opkg_cmd, self.opkg_args) | ||
182 | |||
183 | try: | ||
184 | subprocess.check_output(cmd.split()) | ||
185 | except subprocess.CalledProcessError as e: | ||
186 | self.deploy_dir_unlock() | ||
187 | bb.fatal("Unable to update the package index files. Command %s " | ||
188 | "returned %d" % (cmd, e.returncode)) | ||
189 | |||
190 | self.deploy_dir_unlock() | ||
191 | |||
192 | def install(self, pkgs, attempt_only=False): | ||
193 | cmd = "%s %s install %s" % (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) | ||
194 | |||
195 | os.environ['D'] = self.target_rootfs | ||
196 | os.environ['OFFLINE_ROOT'] = self.target_rootfs | ||
197 | os.environ['IPKG_OFFLINE_ROOT'] = self.target_rootfs | ||
198 | os.environ['OPKG_OFFLINE_ROOT'] = self.target_rootfs | ||
199 | os.environ['INTERCEPT_DIR'] = os.path.join(self.d.getVar('WORKDIR', True), | ||
200 | "intercept_scripts") | ||
201 | os.environ['NATIVE_ROOT'] = self.d.getVar('STAGING_DIR_NATIVE', True) | ||
202 | |||
203 | try: | ||
204 | bb.note("Installing the following packages: %s" % ' '.join(pkgs)) | ||
205 | subprocess.check_output(cmd.split()) | ||
206 | except subprocess.CalledProcessError as e: | ||
207 | (bb.fatal, bb.note)[attempt_only]("Unable to install packages. " | ||
208 | "Command %s returned %d" % | ||
209 | (cmd, e.returncode)) | ||
210 | |||
211 | def remove(self, pkgs, with_dependencies=True): | ||
212 | if with_dependencies: | ||
213 | cmd = "%s %s remove %s" % \ | ||
214 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) | ||
215 | else: | ||
216 | cmd = "%s %s --force-depends remove %s" % \ | ||
217 | (self.opkg_cmd, self.opkg_args, ' '.join(pkgs)) | ||
218 | |||
219 | try: | ||
220 | subprocess.check_output(cmd.split()) | ||
221 | except subprocess.CalledProcessError as e: | ||
222 | bb.fatal("Unable to remove packages. Command %s " | ||
223 | "returned %d" % (e.cmd, e.returncode)) | ||
224 | |||
225 | def write_index(self): | ||
226 | arch_vars = ["ALL_MULTILIB_PACKAGE_ARCHS", | ||
227 | "SDK_PACKAGE_ARCHS", | ||
228 | "MULTILIB_ARCHS"] | ||
229 | |||
230 | tmpdir = self.d.getVar('TMPDIR', True) | ||
231 | if os.path.exists(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN")): | ||
232 | return | ||
233 | |||
234 | self.deploy_dir_lock() | ||
235 | |||
236 | opkg_index_cmd = bb.utils.which(os.getenv('PATH'), "opkg-make-index") | ||
237 | |||
238 | if not os.path.exists(os.path.join(self.deploy_dir, "Packages")): | ||
239 | open(os.path.join(self.deploy_dir, "Packages"), "w").close() | ||
240 | |||
241 | index_cmds = [] | ||
242 | for arch_var in arch_vars: | ||
243 | archs = self.d.getVar(arch_var, True) | ||
244 | if archs is None: | ||
245 | continue | ||
246 | |||
247 | for arch in archs.split(): | ||
248 | pkgs_dir = os.path.join(self.deploy_dir, arch) | ||
249 | pkgs_file = os.path.join(pkgs_dir, "Packages") | ||
250 | |||
251 | if not os.path.isdir(pkgs_dir): | ||
252 | continue | ||
253 | |||
254 | if not os.path.exists(pkgs_file): | ||
255 | open(pkgs_file, "w").close() | ||
256 | |||
257 | index_cmds.append('%s -r %s -p %s -m %s' % | ||
258 | (opkg_index_cmd, pkgs_file, pkgs_file, pkgs_dir)) | ||
259 | |||
260 | if len(index_cmds) == 0: | ||
261 | self.deploy_dir_unlock() | ||
262 | bb.fatal("There are no packages in %s!" % self.deploy_dir) | ||
263 | |||
264 | nproc = multiprocessing.cpu_count() | ||
265 | pool = bb.utils.multiprocessingpool(nproc) | ||
266 | results = list(pool.imap(create_index, index_cmds)) | ||
267 | pool.close() | ||
268 | pool.join() | ||
269 | |||
270 | self.deploy_dir_unlock() | ||
271 | |||
272 | for result in results: | ||
273 | if result is not None: | ||
274 | bb.fatal(result) | ||
275 | |||
276 | open(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), "w").close() | ||
277 | |||
278 | def remove_packaging_data(self): | ||
279 | bb.utils.remove(self.opkg_dir) | ||
280 | # create the directory back, it's needed by PM lock | ||
281 | bb.utils.mkdirhier(self.opkg_dir) | ||
282 | |||
283 | def list_installed(self, format=None): | ||
284 | opkg_query_cmd = bb.utils.which(os.getenv('PATH'), "opkg-query-helper.py") | ||
285 | |||
286 | if format == "arch": | ||
287 | cmd = "%s %s status | %s -a" % \ | ||
288 | (self.opkg_cmd, self.opkg_args, opkg_query_cmd) | ||
289 | elif format == "file": | ||
290 | cmd = "%s %s status | %s -f" % \ | ||
291 | (self.opkg_cmd, self.opkg_args, opkg_query_cmd) | ||
292 | elif format == "ver": | ||
293 | cmd = "%s %s status | %s -v" % \ | ||
294 | (self.opkg_cmd, self.opkg_args, opkg_query_cmd) | ||
295 | else: | ||
296 | cmd = "%s %s list_installed | cut -d' ' -f1" % \ | ||
297 | (self.opkg_cmd, self.opkg_args) | ||
298 | |||
299 | try: | ||
300 | output = subprocess.check_output(cmd, shell=True).strip() | ||
301 | except subprocess.CalledProcessError as e: | ||
302 | bb.fatal("Cannot get the installed packages list. Command %s " | ||
303 | "returned %d" % (cmd, e.returncode)) | ||
304 | |||
305 | if format == "file": | ||
306 | tmp_output = "" | ||
307 | for pkg, pkg_file, pkg_arch in tuple(output.split('\n')): | ||
308 | full_path = os.path.join(self.deploy_dir, pkg_arch, pkg_file) | ||
309 | if os.path.exists(full_path): | ||
310 | tmp_output += "%s %s %s\n" % (pkg, full_path, pkg_arch) | ||
311 | else: | ||
312 | tmp_output += "%s %s %s\n" % (pkg, pkg_file, pkg_arch) | ||
313 | |||
314 | output = tmp_output | ||
315 | |||
316 | return output | ||
317 | |||
318 | def handle_bad_recommendations(self): | ||
319 | bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True) | ||
320 | if bad_recommendations is None: | ||
321 | return | ||
322 | |||
323 | status_file = os.path.join(self.opkg_dir, "status") | ||
324 | |||
325 | cmd = [self.opkg_cmd, self.opkg_args, "info"] | ||
326 | |||
327 | with open(status_file, "w+") as status: | ||
328 | for pkg in bad_recommendations.split(): | ||
329 | pkg_info = cmd + [pkg] | ||
330 | |||
331 | try: | ||
332 | output = subprocess.check_output(pkg_info).strip() | ||
333 | except subprocess.CalledProcessError as e: | ||
334 | bb.fatal("Cannot get package info. Command %s " | ||
335 | "returned %d" % (' '.join(pkg_info), e.returncode)) | ||
336 | |||
337 | if output == "": | ||
338 | bb.note("Requested ignored recommendation $i is " | ||
339 | "not a package" % pkg) | ||
340 | continue | ||
341 | |||
342 | for line in output.split('\n'): | ||
343 | if line.startswith("Package:") or \ | ||
344 | line.startswith("Architecture:") or \ | ||
345 | line.startswith("Version:"): | ||
346 | status.write(line) | ||
347 | |||
348 | status.write("Status: deinstall hold not-installed\n") | ||
147 | 349 | ||
148 | 350 | ||
149 | class DpkgPM(PackageManager): | 351 | class DpkgPM(PackageManager): |