diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2016-05-12 11:28:14 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-14 23:05:11 +0100 |
commit | 0ff3f495ca4fb22a49791bf484416ac2e486d854 (patch) | |
tree | 7584c1990d39d1ddb62a80eb63bbff21ba8026dd /meta/lib/oe/package_manager.py | |
parent | b372a828182b924a8118c6cf4c7b45a7a093704b (diff) | |
download | poky-0ff3f495ca4fb22a49791bf484416ac2e486d854.tar.gz |
package_manager.py: Add extract() method for RPM package manager
This new method extract the content of RPM file to a tmpdir,
without actually installing the package.
[YOCTO #9569]
(From OE-Core rev: 5f5c2a0fac5ad2baca162902410064375e8c610c)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/package_manager.py')
-rw-r--r-- | meta/lib/oe/package_manager.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py index f5517a4aae..1eedeb8526 100644 --- a/meta/lib/oe/package_manager.py +++ b/meta/lib/oe/package_manager.py | |||
@@ -1408,6 +1408,91 @@ class RpmPM(PackageManager): | |||
1408 | for f in rpm_db_locks: | 1408 | for f in rpm_db_locks: |
1409 | bb.utils.remove(f, True) | 1409 | bb.utils.remove(f, True) |
1410 | 1410 | ||
1411 | """ | ||
1412 | Returns a dictionary with the package info. | ||
1413 | """ | ||
1414 | def package_info(self, pkg): | ||
1415 | cmd = "%s %s info --urls %s" % (self.smart_cmd, self.smart_opt, pkg) | ||
1416 | try: | ||
1417 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) | ||
1418 | except subprocess.CalledProcessError as e: | ||
1419 | bb.fatal("Unable to list available packages. Command '%s' " | ||
1420 | "returned %d:\n%s" % (cmd, e.returncode, e.output)) | ||
1421 | |||
1422 | # Set default values to avoid UnboundLocalError | ||
1423 | arch = "" | ||
1424 | ver = "" | ||
1425 | filename = "" | ||
1426 | |||
1427 | #Parse output | ||
1428 | for line in output.splitlines(): | ||
1429 | line = line.rstrip() | ||
1430 | if line.startswith("Name:"): | ||
1431 | pkg = line.split(": ")[1] | ||
1432 | elif line.startswith("Version:"): | ||
1433 | tmp_str = line.split(": ")[1] | ||
1434 | ver, arch = tmp_str.split("@") | ||
1435 | break | ||
1436 | |||
1437 | # Get filename | ||
1438 | index = re.search("^URLs", output, re.MULTILINE) | ||
1439 | tmp_str = output[index.end():] | ||
1440 | for line in tmp_str.splitlines(): | ||
1441 | if "/" in line: | ||
1442 | line = line.lstrip() | ||
1443 | filename = line.split(" ")[0] | ||
1444 | break | ||
1445 | |||
1446 | # To have the same data type than other package_info methods | ||
1447 | pkg_dict = {} | ||
1448 | pkg_dict[pkg] = {"arch":arch, "ver":ver, "filename":filename} | ||
1449 | |||
1450 | return pkg_dict | ||
1451 | |||
1452 | """ | ||
1453 | Returns the path to a tmpdir where resides the contents of a package. | ||
1454 | |||
1455 | Deleting the tmpdir is responsability of the caller. | ||
1456 | |||
1457 | """ | ||
1458 | def extract(self, pkg): | ||
1459 | pkg_info = self.package_info(pkg) | ||
1460 | if not pkg_info: | ||
1461 | bb.fatal("Unable to get information for package '%s' while " | ||
1462 | "trying to extract the package." % pkg) | ||
1463 | |||
1464 | pkg_arch = pkg_info[pkg]["arch"] | ||
1465 | pkg_filename = pkg_info[pkg]["filename"] | ||
1466 | pkg_path = os.path.join(self.deploy_dir, pkg_arch, pkg_filename) | ||
1467 | |||
1468 | cpio_cmd = bb.utils.which(os.getenv("PATH"), "cpio") | ||
1469 | rpm2cpio_cmd = bb.utils.which(os.getenv("PATH"), "rpm2cpio") | ||
1470 | |||
1471 | if not os.path.isfile(pkg_path): | ||
1472 | bb.fatal("Unable to extract package for '%s'." | ||
1473 | "File %s doesn't exists" % (pkg, pkg_path)) | ||
1474 | |||
1475 | tmp_dir = tempfile.mkdtemp() | ||
1476 | current_dir = os.getcwd() | ||
1477 | os.chdir(tmp_dir) | ||
1478 | |||
1479 | try: | ||
1480 | cmd = "%s %s | %s -idmv" % (rpm2cpio_cmd, pkg_path, cpio_cmd) | ||
1481 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) | ||
1482 | except subprocess.CalledProcessError as e: | ||
1483 | bb.utils.remove(tmp_dir, recurse=True) | ||
1484 | bb.fatal("Unable to extract %s package. Command '%s' " | ||
1485 | "returned %d:\n%s" % (pkg_path, cmd, e.returncode, e.output)) | ||
1486 | except OSError as e: | ||
1487 | bb.utils.remove(tmp_dir, recurse=True) | ||
1488 | bb.fatal("Unable to extract %s package. Command '%s' " | ||
1489 | "returned %d:\n%s at %s" % (pkg_path, cmd, e.errno, e.strerror, e.filename)) | ||
1490 | |||
1491 | bb.note("Extracted %s to %s" % (pkg_path, tmp_dir)) | ||
1492 | os.chdir(current_dir) | ||
1493 | |||
1494 | return tmp_dir | ||
1495 | |||
1411 | 1496 | ||
1412 | class OpkgDpkgPM(PackageManager): | 1497 | class OpkgDpkgPM(PackageManager): |
1413 | """ | 1498 | """ |