From: Joshua G Lock <joshua.g.lock@linux.intel.com>
To: mariano.lopez@linux.intel.com, openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 1/3] package_manager.py: Move opkg_query() outside of Indexer class
Date: Thu, 12 May 2016 10:30:42 +0100 [thread overview]
Message-ID: <1463045442.3794.4.camel@linux.intel.com> (raw)
In-Reply-To: <c51b4f36eb7c3a057f10e3d9f424a8f239850b24.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>
>
> When using the opkg and apt-get package managers the function
> opkg_query() can be useful when query for package information.
>
> This change moves the function outside the Indexer class so
> the Indexer, OpkgPM, DpkgPM can benefit from it.
>
> [YOCTO #9569]
>
> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
> ---
> meta/lib/oe/package_manager.py | 104 ++++++++++++++++++++-----------
> ----------
> 1 file changed, 51 insertions(+), 53 deletions(-)
>
> diff --git a/meta/lib/oe/package_manager.py
> b/meta/lib/oe/package_manager.py
> index b4b359a..427518d 100644
> --- a/meta/lib/oe/package_manager.py
> +++ b/meta/lib/oe/package_manager.py
> @@ -27,6 +27,55 @@ def create_index(arg):
>
> return None
>
> +"""
> +This method parse the output from the package managerand return
> +a dictionary with the information of the packages. This is used
> +when the packages are in deb or ipk format.
> +"""
> +def opkg_query(cmd_output):
> + verregex = re.compile(' \([=<>]* [^ )]*\)')
> + output = dict()
> + filename = ""
> + dep = []
> + pkg = ""
Here we assign a default value for dep, pkg and filename but not arch
and ver.
I feel it's safest we assign defaults for all of the variables that are
otherwise only created if a matching line is found, otherwise we might
run into unexpected UnboundLocalError's which cause nasty crashes.
> + for line in cmd_output.splitlines():
> + line = line.rstrip()
> + if ':' in line:
> + if line.startswith("Package: "):
> + pkg = line.split(": ")[1]
> + elif line.startswith("Architecture: "):
> + arch = line.split(": ")[1]
> + elif line.startswith("Version: "):
> + ver = line.split(": ")[1]
> + elif line.startswith("File: "):
> + filename = line.split(": ")[1]
> + elif line.startswith("Depends: "):
> + depends = verregex.sub('', line.split(": ")[1])
> + for depend in depends.split(", "):
> + dep.append(depend)
> + elif line.startswith("Recommends: "):
> + recommends = verregex.sub('', line.split(": ")[1])
> + for recommend in recommends.split(", "):
> + dep.append("%s [REC]" % recommend)
> + else:
> + # IPK doesn't include the filename
> + if not filename:
> + filename = "%s_%s_%s.ipk" % (pkg, ver, arch)
> + if pkg:
> + output[pkg] = {"arch":arch, "ver":ver,
> + "filename":filename, "deps": dep }
> + pkg = ""
> + filename = ""
> + dep = []
> +
> + if pkg:
> + if not filename:
> + filename = "%s_%s_%s.ipk" % (pkg, ver, arch)
> + output[pkg] = {"arch":arch, "ver":ver,
> + "filename":filename, "deps": dep }
> +
> + return output
> +
>
> class Indexer(object):
> __metaclass__ = ABCMeta
> @@ -293,57 +342,6 @@ class PkgsList(object):
> pass
>
>
> - """
> - This method parse the output from the package manager
> - and return a dictionary with the information of the
> - installed packages. This is used whne the packages are
> - in deb or ipk format
> - """
> - def opkg_query(self, cmd_output):
> - verregex = re.compile(' \([=<>]* [^ )]*\)')
> - output = dict()
> - filename = ""
> - dep = []
> - pkg = ""
> - for line in cmd_output.splitlines():
> - line = line.rstrip()
> - if ':' in line:
> - if line.startswith("Package: "):
> - pkg = line.split(": ")[1]
> - elif line.startswith("Architecture: "):
> - arch = line.split(": ")[1]
> - elif line.startswith("Version: "):
> - ver = line.split(": ")[1]
> - elif line.startswith("File: "):
> - filename = line.split(": ")[1]
> - elif line.startswith("Depends: "):
> - depends = verregex.sub('', line.split(": ")[1])
> - for depend in depends.split(", "):
> - dep.append(depend)
> - elif line.startswith("Recommends: "):
> - recommends = verregex.sub('', line.split(":
> ")[1])
> - for recommend in recommends.split(", "):
> - dep.append("%s [REC]" % recommend)
> - else:
> - # IPK doesn't include the filename
> - if not filename:
> - filename = "%s_%s_%s.ipk" % (pkg, ver, arch)
> - if pkg:
> - output[pkg] = {"arch":arch, "ver":ver,
> - "filename":filename, "deps": dep }
> - pkg = ""
> - filename = ""
> - dep = []
> -
> - if pkg:
> - if not filename:
> - filename = "%s_%s_%s.ipk" % (pkg, ver, arch)
> - output[pkg] = {"arch":arch, "ver":ver,
> - "filename":filename, "deps": dep }
> -
> - return output
> -
> -
> class RpmPkgsList(PkgsList):
> def __init__(self, d, rootfs_dir, arch_var=None, os_var=None):
> super(RpmPkgsList, self).__init__(d, rootfs_dir)
> @@ -479,7 +477,7 @@ class OpkgPkgsList(PkgsList):
> bb.fatal("Cannot get the installed packages list.
> Command '%s' "
> "returned %d and stderr:\n%s" % (cmd,
> p.returncode, cmd_stderr))
>
> - return self.opkg_query(cmd_output)
> + return opkg_query(cmd_output)
>
>
> class DpkgPkgsList(PkgsList):
> @@ -497,7 +495,7 @@ class DpkgPkgsList(PkgsList):
> bb.fatal("Cannot get the installed packages list.
> Command '%s' "
> "returned %d:\n%s" % (' '.join(cmd),
> e.returncode, e.output))
>
> - return self.opkg_query(cmd_output)
> + return opkg_query(cmd_output)
>
>
> class PackageManager(object):
> --
> 2.6.6
>
next prev parent reply other threads:[~2016-05-12 9:30 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 [this message]
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
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=1463045442.3794.4.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox