From: Joshua G Lock <joshua.g.lock@linux.intel.com>
To: mariano.lopez@linux.intel.com, openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 3/3] package_manager.py: Add extract() method for RPM package manager
Date: Thu, 12 May 2016 10:31:04 +0100 [thread overview]
Message-ID: <1463045464.3794.6.camel@linux.intel.com> (raw)
In-Reply-To: <1c3ceaa93f95993002acd3ce3e1a07bea1ffd6b1.1462969737.git.mariano.lopez@linux.intel.com>
On Wed, 2016-05-11 at 12:31 +0000, mariano.lopez@linux.intel.com wrote:
> From: Mariano Lopez <mariano.lopez@linux.intel.com>
>
> This new method extract the content of RPM file to a tmpdir,
> without actually installing the package.
>
> [YOCTO #9569]
>
> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
> ---
> meta/lib/oe/package_manager.py | 80
> ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 80 insertions(+)
>
> diff --git a/meta/lib/oe/package_manager.py
> b/meta/lib/oe/package_manager.py
> index 0830da9..d95564a 100644
> --- a/meta/lib/oe/package_manager.py
> +++ b/meta/lib/oe/package_manager.py
> @@ -1404,6 +1404,86 @@ class RpmPM(PackageManager):
> for f in rpm_db_locks:
> bb.utils.remove(f, True)
>
> + """
> + Returns a dictionary with the package info.
> + """
> + def package_info(self, pkg):
> + cmd = "%s %s info --urls %s" % (self.smart_cmd,
> self.smart_opt, pkg)
> + try:
> + output = subprocess.check_output(cmd,
> stderr=subprocess.STDOUT, shell=True)
> + except subprocess.CalledProcessError as e:
> + bb.fatal("Unable to list available packages. Command
> '%s' "
> + "returned %d:\n%s" % (cmd, e.returncode,
> e.output))
> +
> + #Parse output
> + for line in output.splitlines():
> + line = line.rstrip()
> + if line.startswith("Name:"):
> + pkg = line.split(": ")[1]
> + elif line.startswith("Version:"):
> + tmp_str = line.split(": ")[1]
> + ver, arch = tmp_str.split("@")
> + break
Could pkg, ver and arch be potentially undefined here?
> +
> + # Get filename
> + index = re.search("^URLs", output, re.MULTILINE)
> + tmp_str = output[index.end():]
> + for line in tmp_str.splitlines():
> + if "/" in line:
> + line = line.lstrip()
> + filename = line.split(" ")[0]
> + break
> +
> + # To have the same data type than other package_info methods
> + pkg_dict = {}
> + pkg_dict[pkg] = {"arch":arch, "ver":ver,
> "filename":filename}
> +
> + return pkg_dict
> +
> + """
> + Returns the path to a tmpdir where resides the contents of a
> package.
> +
> + Deleting the tmpdir is responsability of the caller.
> +
> + """
> + def extract(self, pkg):
> + pkg_info = self.package_info(pkg)
> + if not pkg_info:
> + bb.fatal("Unable to get information for package '%s'
> while "
> + "trying to extract the package." % pkg)
> +
> + pkg_arch = pkg_info[pkg]["arch"]
> + pkg_filename = pkg_info[pkg]["filename"]
> + pkg_path = os.path.join(self.deploy_dir, pkg_arch,
> pkg_filename)
> +
> + cpio_cmd = bb.utils.which(os.getenv("PATH"), "cpio")
> + rpm2cpio_cmd = bb.utils.which(os.getenv("PATH"), "rpm2cpio")
> +
> + if not os.path.isfile(pkg_path):
> + bb.fatal("Unable to extract package for '%s'."
> + "File %s doesn't exists" % (pkg, pkg_path))
> +
> + tmp_dir = tempfile.mkdtemp()
> + current_dir = os.getcwd()
> + os.chdir(tmp_dir)
> +
> + try:
> + cmd = "%s %s | %s -idmv" % (rpm2cpio_cmd, pkg_path,
> cpio_cmd)
> + output = subprocess.check_output(cmd,
> stderr=subprocess.STDOUT, shell=True)
> + except subprocess.CalledProcessError as e:
> + bb.utils.remove(tmp_dir, recurse=True)
> + bb.fatal("Unable to extract %s package. Command '%s' "
> + "returned %d:\n%s" % (pkg_path, cmd,
> e.returncode, e.output))
> + except OSError as e:
> + bb.utils.remove(tmp_dir, recurse=True)
> + bb.fatal("Unable to extract %s package. Command '%s' "
> + "returned %d:\n%s at %s" % (pkg_path, cmd,
> e.errno, e.strerror, e.filename))
> +
> + bb.note("Extracted %s to %s" % (pkg_path, tmp_dir))
> + os.chdir(current_dir)
> +
> + return tmp_dir
> +
>
> class OpkgDpkgPM(PackageManager):
> """
> --
> 2.6.6
>
next prev parent reply other threads:[~2016-05-12 9:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 12:31 [PATCH 0/3] Add extract() method to package manager mariano.lopez
2016-05-11 12:31 ` [PATCH 1/3] package_manager.py: Move opkg_query() outside of Indexer class mariano.lopez
2016-05-12 9:30 ` Joshua G Lock
2016-05-11 12:31 ` [PATCH 2/3] package_manager.py: Add extract() method for opkg and dpkg mariano.lopez
2016-05-12 9:30 ` Joshua G Lock
2016-05-11 12:31 ` [PATCH 3/3] package_manager.py: Add extract() method for RPM package manager mariano.lopez
2016-05-12 9:31 ` Joshua G Lock [this message]
2016-05-12 19:05 ` Mariano Lopez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463045464.3794.6.camel@linux.intel.com \
--to=joshua.g.lock@linux.intel.com \
--cc=mariano.lopez@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.