All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Clean PkgsList return data implementation.
@ 2016-01-07 20:07 mariano.lopez
  2016-01-07 20:07 ` [PATCH 1/4] lib/oe/package_manager: Add list_pkgs() to PkgsList class mariano.lopez
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: mariano.lopez @ 2016-01-07 20:07 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

Currently the when calling the list() from the classes that inherit
from PKgsList, it must pass the format required and it will return
a formated string listing all the packages installed. Retruning such
string is not the best data structure to manipulate in the callers.

This series of patches change PkgsList to return a dictionary and the
callers will format the output as required.

This patches require: 

rpmresolve.c: Fix unfreed pointers that keep DB opened
http://patches.openembedded.org/patch/111021/

[YOCTO #7427]

The following changes since commit b9054f22526b89a752a07c5d4e6ca26afbf303aa:

  bitbake: fetch/git: Change to use clearer ssh url syntax for broken servers (2016-01-07 15:23:57 +0000)

are available in the git repository at:

  git://git.yoctoproject.org/poky-contrib mariano/bug7427v3
  http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug7427v3

Mariano Lopez (4):
  lib/oe/package_manager: Add list_pkgs() to PkgsList class
  lib/oe/utils: Add function format_pkg_list()
  lib/oe/rootfs: Use list_pkgs() instead of list()
  lib/oe/package_manager.py: Remove list() from PkgsList class

 meta/classes/buildhistory.bbclass        |  11 +-
 meta/classes/license.bbclass             |   8 +-
 meta/classes/populate_sdk_base.bbclass   |   8 +-
 meta/classes/rootfs-postcommands.bbclass |   5 +-
 meta/lib/oe/package_manager.py           | 185 +++++++++++++------------------
 meta/lib/oe/rootfs.py                    |   8 +-
 meta/lib/oe/sdk.py                       |   8 +-
 meta/lib/oe/utils.py                     |  22 ++++
 8 files changed, 129 insertions(+), 126 deletions(-)

-- 
1.8.4.5



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] lib/oe/package_manager: Add list_pkgs() to PkgsList class
  2016-01-07 20:07 [PATCH 0/4] Clean PkgsList return data implementation mariano.lopez
@ 2016-01-07 20:07 ` mariano.lopez
  2016-01-07 20:07 ` [PATCH 2/4] lib/oe/utils: Add function format_pkg_list() mariano.lopez
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: mariano.lopez @ 2016-01-07 20:07 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

Currently the class PkgList returns a formated string of the
installed packages. It would be more clean to pass a standard
data structure to the callers instead to format the output
inside PkgsList class.

This patch adds list_pkgs() method to PkgsList class to get the
all the information for installed packages and return a dictionary
with the info.

[YOCTO #7427]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
 meta/lib/oe/package_manager.py | 120 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 32afeaf..95e7ae7 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -296,6 +296,45 @@ class PkgsList(object):
     def list(self, format=None):
         pass
 
+    @abstractmethod
+    def list_pkgs(self):
+        pass
+
+    def opkg_query(self, cmd_output):
+        verregex = re.compile(' \([=<>]* [^ )]*\)')
+        output = dict()
+        filename = ""
+        dep = []
+        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)
+                output[pkg] = {"arch":arch, "ver":ver,
+                            "filename":filename, "deps": dep }
+                filename = ""
+                dep = []
+
+        return output
+
 
 class RpmPkgsList(PkgsList):
     def __init__(self, d, rootfs_dir, arch_var=None, os_var=None):
@@ -412,6 +451,59 @@ class RpmPkgsList(PkgsList):
 
         return '\n'.join(output)
 
+    def list_pkgs(self):
+        cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir
+        cmd += ' -D "_dbpath /var/lib/rpm" -qa'
+        if self.rpm_version == 4:
+            cmd += " --qf '[%{NAME} %{ARCH} %{VERSION}\n]'"
+        else:
+            cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'"
+
+        try:
+            # bb.note(cmd)
+            tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip()
+        except subprocess.CalledProcessError as e:
+            bb.fatal("Cannot get the installed packages list. Command '%s' "
+                     "returned %d:\n%s" % (cmd, e.returncode, e.output))
+
+        output = dict()
+        deps = dict()
+        if self.rpm_version == 4:
+            bb.warn("Dependency listings are not supported with rpm 4 since rpmresolve does not work")
+            dependencies = ""
+        else:
+            dependencies = self._list_pkg_deps()
+
+        # Populate deps dictionary for better manipulation
+        for line in dependencies.splitlines():
+            pkg, dep = line.split("|")
+            if not pkg in deps:
+                deps[pkg] = list()
+            if not dep in deps[pkg]:
+                deps[pkg].append(dep)
+
+        for line in tmp_output.split('\n'):
+            if len(line.strip()) == 0:
+                continue
+            pkg = line.split()[0]
+            arch = line.split()[1]
+            ver = line.split()[2]
+            dep = deps.get(pkg, [])
+
+            # Skip GPG keys
+            if pkg == 'gpg-pubkey':
+                continue
+            if self.rpm_version == 4:
+                pkgorigin = "unknown"
+            else:
+                pkgorigin = line.split()[3]
+            new_pkg, new_arch = self._pkg_translate_smart_to_oe(pkg, arch)
+
+            output[new_pkg] = {"arch":new_arch, "ver":ver,
+                        "filename":pkgorigin, "deps":dep}
+
+        return output
+
 
 class OpkgPkgsList(PkgsList):
     def __init__(self, d, rootfs_dir, config_file):
@@ -466,6 +558,19 @@ class OpkgPkgsList(PkgsList):
 
         return '\n'.join(output)
 
+    def list_pkgs(self, format=None):
+        cmd = "%s %s status" % (self.opkg_cmd, self.opkg_args)
+
+        try:
+            # bb.note(cmd)
+            cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip()
+
+        except subprocess.CalledProcessError as e:
+            bb.fatal("Cannot get the installed packages list. Command '%s' "
+                     "returned %d:\n%s" % (cmd, e.returncode, e.output))
+
+        return self.opkg_query(cmd_output)
+
 
 class DpkgPkgsList(PkgsList):
     def list(self, format=None):
@@ -523,6 +628,21 @@ class DpkgPkgsList(PkgsList):
 
         return output
 
+    def list_pkgs(self):
+        cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"),
+               "--admindir=%s/var/lib/dpkg" % self.rootfs_dir,
+               "-W"]
+
+        cmd.append("-f=Package: ${Package}\nArchitecture: ${PackageArch}\nVersion: ${Version}\nFile: ${Package}_${Version}_${Architecture}.deb\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n")
+
+        try:
+            cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
+        except subprocess.CalledProcessError as e:
+            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)
+
 
 class PackageManager(object):
     """
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] lib/oe/utils: Add function format_pkg_list()
  2016-01-07 20:07 [PATCH 0/4] Clean PkgsList return data implementation mariano.lopez
  2016-01-07 20:07 ` [PATCH 1/4] lib/oe/package_manager: Add list_pkgs() to PkgsList class mariano.lopez
@ 2016-01-07 20:07 ` mariano.lopez
  2016-01-07 20:07 ` [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list() mariano.lopez
  2016-01-07 20:07 ` [PATCH 4/4] lib/oe/package_manager.py: Remove list() from PkgsList class mariano.lopez
  3 siblings, 0 replies; 7+ messages in thread
From: mariano.lopez @ 2016-01-07 20:07 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

The class PkgsList returns a dictionary with all the installed
packages, because the data structure is a dictionary there is
needed to format the data in order to write to a file.

The function format_pkg_list returns a formated sting with all
packages installed. The output will depend on the requested format
when calling the function.

[YOCTO #7427]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
 meta/lib/oe/utils.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index cee087f..9a86410 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -208,6 +208,28 @@ def squashspaces(string):
     import re
     return re.sub("\s+", " ", string).strip()
 
+def format_pkg_list(pkg_dict, ret_format=None):
+    output = []
+
+    if ret_format == "arch":
+        for pkg in sorted(pkg_dict):
+            output.append("%s %s" % (pkg, pkg_dict[pkg]["arch"]))
+    elif ret_format == "file":
+        for pkg in sorted(pkg_dict):
+            output.append("%s %s %s" % (pkg, pkg_dict[pkg]["filename"], pkg_dict[pkg]["arch"]))
+    elif ret_format == "ver":
+        for pkg in sorted(pkg_dict):
+            output.append("%s %s %s" % (pkg, pkg_dict[pkg]["arch"], pkg_dict[pkg]["ver"]))
+    elif ret_format == "deps":
+        for pkg in sorted(pkg_dict):
+            for dep in pkg_dict[pkg]["deps"]:
+                output.append("%s|%s" % (pkg, dep))
+    else:
+        for pkg in sorted(pkg_dict):
+            output.append(pkg)
+
+    return '\n'.join(output)
+
 #
 # Python 2.7 doesn't have threaded pools (just multiprocessing)
 # so implement a version here
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list()
  2016-01-07 20:07 [PATCH 0/4] Clean PkgsList return data implementation mariano.lopez
  2016-01-07 20:07 ` [PATCH 1/4] lib/oe/package_manager: Add list_pkgs() to PkgsList class mariano.lopez
  2016-01-07 20:07 ` [PATCH 2/4] lib/oe/utils: Add function format_pkg_list() mariano.lopez
@ 2016-01-07 20:07 ` mariano.lopez
  2016-01-09 23:55   ` Pau Espin Pedrol
  2016-01-07 20:07 ` [PATCH 4/4] lib/oe/package_manager.py: Remove list() from PkgsList class mariano.lopez
  3 siblings, 1 reply; 7+ messages in thread
From: mariano.lopez @ 2016-01-07 20:07 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

This patch changes the use list_pkgs() instead of list()
from class RpmPkgsList. The change is in two functions,
image_list_installed_packages from rootfs.py and
sdk_list_installed_packages from sdk.py.

With this change the functions calling the functions
listed above, must format the output as they required.
The formatting can be done using format_pkg_list() from
oe.utils.

The classes calling the afected functions are changed too
with this patch, to keep the same functionality using the
new data structure.

[YOCTO #7427]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
 meta/classes/buildhistory.bbclass        | 11 +++++++----
 meta/classes/license.bbclass             |  8 ++++++--
 meta/classes/populate_sdk_base.bbclass   |  8 ++++++--
 meta/classes/rootfs-postcommands.bbclass |  5 +++--
 meta/lib/oe/package_manager.py           | 18 ++++++++++--------
 meta/lib/oe/rootfs.py                    |  8 ++++----
 meta/lib/oe/sdk.py                       |  8 ++++----
 7 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass
index 4153e58..a2f8ac7 100644
--- a/meta/classes/buildhistory.bbclass
+++ b/meta/classes/buildhistory.bbclass
@@ -337,18 +337,21 @@ def write_pkghistory(pkginfo, d):
 def buildhistory_list_installed(d, rootfs_type="image"):
     from oe.rootfs import image_list_installed_packages
     from oe.sdk import sdk_list_installed_packages
+    from oe.utils import format_pkg_list
 
     process_list = [('file', 'bh_installed_pkgs.txt'),\
                     ('deps', 'bh_installed_pkgs_deps.txt')]
 
+    if rootfs_type == "image":
+        pkgs = image_list_installed_packages(d)
+    else:
+        pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target")
+
     for output_type, output_file in process_list:
         output_file_full = os.path.join(d.getVar('WORKDIR', True), output_file)
 
         with open(output_file_full, 'w') as output:
-            if rootfs_type == "image":
-                output.write(image_list_installed_packages(d, output_type))
-            else:
-                output.write(sdk_list_installed_packages(d, rootfs_type == "sdk_target", output_type))
+            output.write(format_pkg_list(pkgs, output_type))
 
 python buildhistory_list_installed_image() {
     buildhistory_list_installed(d)
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 6651d55..fed42ca 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -21,8 +21,12 @@ python write_package_manifest() {
     license_image_dir = d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}')
     bb.utils.mkdirhier(license_image_dir)
     from oe.rootfs import image_list_installed_packages
+    from oe.utils import format_pkg_list
+
+    pkgs = image_list_installed_packages(d)
+    output = format_pkg_list(pkgs)
     open(os.path.join(license_image_dir, 'package.manifest'),
-        'w+').write(image_list_installed_packages(d))
+        'w+').write(output)
 }
 
 python write_deploy_manifest() {
@@ -38,7 +42,7 @@ python license_create_manifest() {
         return 0
 
     pkg_dic = {}
-    for pkg in image_list_installed_packages(d).splitlines():
+    for pkg in sorted(image_list_installed_packages(d)):
         pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True),
                                 'runtime-reverse', pkg)
         pkg_name = os.path.basename(os.readlink(pkg_info))
diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass
index 23dc115..26e06a5 100644
--- a/meta/classes/populate_sdk_base.bbclass
+++ b/meta/classes/populate_sdk_base.bbclass
@@ -62,20 +62,24 @@ SDK_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"
 SDK_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"
 python write_target_sdk_manifest () {
     from oe.sdk import sdk_list_installed_packages
+    from oe.utils import format_pkg_list
     sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST", True))
+    pkgs = sdk_list_installed_packages(d, True)
     if not os.path.exists(sdkmanifestdir):
         bb.utils.mkdirhier(sdkmanifestdir)
     with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output:
-        output.write(sdk_list_installed_packages(d, True, 'ver'))
+        output.write(format_pkg_list(pkgs, 'ver'))
 }
 
 python write_host_sdk_manifest () {
     from oe.sdk import sdk_list_installed_packages
+    from oe.utils import format_pkg_list
     sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True))
+    pkgs = sdk_list_installed_packages(d, False)
     if not os.path.exists(sdkmanifestdir):
         bb.utils.mkdirhier(sdkmanifestdir)
     with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output:
-        output.write(sdk_list_installed_packages(d, False, 'ver'))
+        output.write(format_pkg_list(pkgs, 'ver'))
 }
 
 POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
index 96d3051..fe664b7 100644
--- a/meta/classes/rootfs-postcommands.bbclass
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -207,14 +207,15 @@ insert_feed_uris () {
 
 python write_image_manifest () {
     from oe.rootfs import image_list_installed_packages
+    from oe.utils import format_pkg_list
 
     deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True)
     link_name = d.getVar('IMAGE_LINK_NAME', True)
     manifest_name = d.getVar('IMAGE_MANIFEST', True)
 
+    pkgs = image_list_installed_packages(d)
     with open(manifest_name, 'w+') as image_manifest:
-        image_manifest.write(image_list_installed_packages(d, 'ver'))
-        image_manifest.write("\n")
+        image_manifest.write(format_pkg_list(pkgs, "ver"))
 
     if manifest_name is not None and os.path.exists(manifest_name):
         manifest_link = deploy_dir + "/" + link_name + ".manifest"
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 95e7ae7..522cbf7 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -693,7 +693,7 @@ class PackageManager(object):
         pass
 
     @abstractmethod
-    def list_installed(self, format=None):
+    def list_installed(self):
         pass
 
     @abstractmethod
@@ -713,7 +713,9 @@ class PackageManager(object):
         installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR', True),
                                            "installed_pkgs.txt")
         with open(installed_pkgs_file, "w+") as installed_pkgs:
-            installed_pkgs.write(self.list_installed("arch"))
+            pkgs = self.list_installed()
+            output = oe.utils.format_pkg_list(pkgs, "arch")
+            installed_pkgs.write(output)
 
         if globs is None:
             globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
@@ -1417,8 +1419,8 @@ class RpmPM(PackageManager):
                             self.image_rpmlib,
                             symlinks=True)
 
-    def list_installed(self, format=None):
-        return self.pkgs_list.list(format)
+    def list_installed(self):
+        return self.pkgs_list.list_pkgs()
 
     '''
     If incremental install, we need to determine what we've got,
@@ -1782,8 +1784,8 @@ class OpkgPM(PackageManager):
         # create the directory back, it's needed by PM lock
         bb.utils.mkdirhier(self.opkg_dir)
 
-    def list_installed(self, format=None):
-        return OpkgPkgsList(self.d, self.target_rootfs, self.config_file).list(format)
+    def list_installed(self):
+        return OpkgPkgsList(self.d, self.target_rootfs, self.config_file).list_pkgs()
 
     def handle_bad_recommendations(self):
         bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True) or ""
@@ -2166,8 +2168,8 @@ class DpkgPM(PackageManager):
             bb.fatal("Cannot fix broken dependencies. Command '%s' "
                      "returned %d:\n%s" % (cmd, e.returncode, e.output))
 
-    def list_installed(self, format=None):
-        return DpkgPkgsList(self.d, self.target_rootfs).list()
+    def list_installed(self):
+        return DpkgPkgsList(self.d, self.target_rootfs).list_pkgs()
 
 
 def generate_index_files(d):
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
index a2af332..45a88fb 100644
--- a/meta/lib/oe/rootfs.py
+++ b/meta/lib/oe/rootfs.py
@@ -963,17 +963,17 @@ def create_rootfs(d, manifest_dir=None):
     os.environ.update(env_bkp)
 
 
-def image_list_installed_packages(d, format=None, rootfs_dir=None):
+def image_list_installed_packages(d, rootfs_dir=None):
     if not rootfs_dir:
         rootfs_dir = d.getVar('IMAGE_ROOTFS', True)
 
     img_type = d.getVar('IMAGE_PKGTYPE', True)
     if img_type == "rpm":
-        return RpmPkgsList(d, rootfs_dir).list(format)
+        return RpmPkgsList(d, rootfs_dir).list_pkgs()
     elif img_type == "ipk":
-        return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET", True)).list(format)
+        return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET", True)).list_pkgs()
     elif img_type == "deb":
-        return DpkgPkgsList(d, rootfs_dir).list(format)
+        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
 
 if __name__ == "__main__":
     """
diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
index 6affa40..b308aea 100644
--- a/meta/lib/oe/sdk.py
+++ b/meta/lib/oe/sdk.py
@@ -345,7 +345,7 @@ class DpkgSdk(Sdk):
 
 
 
-def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None):
+def sdk_list_installed_packages(d, target, rootfs_dir=None):
     if rootfs_dir is None:
         sdk_output = d.getVar('SDK_OUTPUT', True)
         target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
@@ -356,12 +356,12 @@ def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None):
     if img_type == "rpm":
         arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
         os_var = ["SDK_OS", None][target is True]
-        return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list(format)
+        return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list_pkgs()
     elif img_type == "ipk":
         conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
-        return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list(format)
+        return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list_pkgs()
     elif img_type == "deb":
-        return DpkgPkgsList(d, rootfs_dir).list(format)
+        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
 
 def populate_sdk(d, manifest_dir=None):
     env_bkp = os.environ.copy()
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] lib/oe/package_manager.py: Remove list() from PkgsList class
  2016-01-07 20:07 [PATCH 0/4] Clean PkgsList return data implementation mariano.lopez
                   ` (2 preceding siblings ...)
  2016-01-07 20:07 ` [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list() mariano.lopez
@ 2016-01-07 20:07 ` mariano.lopez
  3 siblings, 0 replies; 7+ messages in thread
From: mariano.lopez @ 2016-01-07 20:07 UTC (permalink / raw)
  To: openembedded-core

From: Mariano Lopez <mariano.lopez@linux.intel.com>

Now that the method list() is not used anymore, remove it.

[YOCTO #7427]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
---
 meta/lib/oe/package_manager.py | 153 -----------------------------------------
 1 file changed, 153 deletions(-)

diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 522cbf7..6eac3e1 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -293,10 +293,6 @@ class PkgsList(object):
         self.rootfs_dir = rootfs_dir
 
     @abstractmethod
-    def list(self, format=None):
-        pass
-
-    @abstractmethod
     def list_pkgs(self):
         pass
 
@@ -401,56 +397,6 @@ class RpmPkgsList(PkgsList):
 
         return output
 
-    def list(self, format=None):
-        if format == "deps":
-            if self.rpm_version == 4:
-                bb.fatal("'deps' format dependency listings are not supported with rpm 4 since rpmresolve does not work")
-            return self._list_pkg_deps()
-
-        cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir
-        cmd += ' -D "_dbpath /var/lib/rpm" -qa'
-        if self.rpm_version == 4:
-            cmd += " --qf '[%{NAME} %{ARCH} %{VERSION}\n]'"
-        else:
-            cmd += " --qf '[%{NAME} %{ARCH} %{VERSION} %{PACKAGEORIGIN}\n]'"
-
-        try:
-            # bb.note(cmd)
-            tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip()
-
-        except subprocess.CalledProcessError as e:
-            bb.fatal("Cannot get the installed packages list. Command '%s' "
-                     "returned %d:\n%s" % (cmd, e.returncode, e.output))
-
-        output = list()
-        for line in tmp_output.split('\n'):
-            if len(line.strip()) == 0:
-                continue
-            pkg = line.split()[0]
-            arch = line.split()[1]
-            ver = line.split()[2]
-            # Skip GPG keys
-            if pkg == 'gpg-pubkey':
-                continue
-            if self.rpm_version == 4:
-                pkgorigin = "unknown"
-            else:
-                pkgorigin = line.split()[3]
-            new_pkg, new_arch = self._pkg_translate_smart_to_oe(pkg, arch)
-
-            if format == "arch":
-                output.append('%s %s' % (new_pkg, new_arch))
-            elif format == "file":
-                output.append('%s %s %s' % (new_pkg, pkgorigin, new_arch))
-            elif format == "ver":
-                output.append('%s %s %s' % (new_pkg, new_arch, ver))
-            else:
-                output.append('%s' % (new_pkg))
-
-            output.sort()
-
-        return '\n'.join(output)
-
     def list_pkgs(self):
         cmd = self.rpm_cmd + ' --root ' + self.rootfs_dir
         cmd += ' -D "_dbpath /var/lib/rpm" -qa'
@@ -513,51 +459,6 @@ class OpkgPkgsList(PkgsList):
         self.opkg_args = "-f %s -o %s " % (config_file, rootfs_dir)
         self.opkg_args += self.d.getVar("OPKG_ARGS", True)
 
-    def list(self, format=None):
-        opkg_query_cmd = bb.utils.which(os.getenv('PATH'), "opkg-query-helper.py")
-
-        if format == "arch":
-            cmd = "%s %s status | %s -a" % \
-                (self.opkg_cmd, self.opkg_args, opkg_query_cmd)
-        elif format == "file":
-            cmd = "%s %s status | %s -f" % \
-                (self.opkg_cmd, self.opkg_args, opkg_query_cmd)
-        elif format == "ver":
-            cmd = "%s %s status | %s -v" % \
-                (self.opkg_cmd, self.opkg_args, opkg_query_cmd)
-        elif format == "deps":
-            cmd = "%s %s status | %s" % \
-                (self.opkg_cmd, self.opkg_args, opkg_query_cmd)
-        else:
-            cmd = "%s %s list_installed | cut -d' ' -f1" % \
-                (self.opkg_cmd, self.opkg_args)
-
-        try:
-            # bb.note(cmd)
-            tmp_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).strip()
-
-        except subprocess.CalledProcessError as e:
-            bb.fatal("Cannot get the installed packages list. Command '%s' "
-                     "returned %d:\n%s" % (cmd, e.returncode, e.output))
-
-        output = list()
-        for line in tmp_output.split('\n'):
-            if len(line.strip()) == 0:
-                continue
-            if format == "file":
-                pkg, pkg_file, pkg_arch = line.split()
-                full_path = os.path.join(self.rootfs_dir, pkg_arch, pkg_file)
-                if os.path.exists(full_path):
-                    output.append('%s %s %s' % (pkg, full_path, pkg_arch))
-                else:
-                    output.append('%s %s %s' % (pkg, pkg_file, pkg_arch))
-            else:
-                output.append(line)
-
-        output.sort()
-
-        return '\n'.join(output)
-
     def list_pkgs(self, format=None):
         cmd = "%s %s status" % (self.opkg_cmd, self.opkg_args)
 
@@ -573,60 +474,6 @@ class OpkgPkgsList(PkgsList):
 
 
 class DpkgPkgsList(PkgsList):
-    def list(self, format=None):
-        cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"),
-               "--admindir=%s/var/lib/dpkg" % self.rootfs_dir,
-               "-W"]
-
-        if format == "arch":
-            cmd.append("-f=${Package} ${PackageArch}\n")
-        elif format == "file":
-            cmd.append("-f=${Package} ${Package}_${Version}_${Architecture}.deb ${PackageArch}\n")
-        elif format == "ver":
-            cmd.append("-f=${Package} ${PackageArch} ${Version}\n")
-        elif format == "deps":
-            cmd.append("-f=Package: ${Package}\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n")
-        else:
-            cmd.append("-f=${Package}\n")
-
-        try:
-            output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
-        except subprocess.CalledProcessError as e:
-            bb.fatal("Cannot get the installed packages list. Command '%s' "
-                     "returned %d:\n%s" % (' '.join(cmd), e.returncode, e.output))
-
-        if format == "file":
-            tmp_output = ""
-            for line in tuple(output.split('\n')):
-                if not line.strip():
-                    continue
-                pkg, pkg_file, pkg_arch = line.split()
-                full_path = os.path.join(self.rootfs_dir, pkg_arch, pkg_file)
-                if os.path.exists(full_path):
-                    tmp_output += "%s %s %s\n" % (pkg, full_path, pkg_arch)
-                else:
-                    tmp_output += "%s %s %s\n" % (pkg, pkg_file, pkg_arch)
-
-            output = tmp_output
-        elif format == "deps":
-            opkg_query_cmd = bb.utils.which(os.getenv('PATH'), "opkg-query-helper.py")
-            file_out = tempfile.NamedTemporaryFile()
-            file_out.write(output)
-            file_out.flush()
-
-            try:
-                output = subprocess.check_output("cat %s | %s" %
-                                                 (file_out.name, opkg_query_cmd),
-                                                 stderr=subprocess.STDOUT,
-                                                 shell=True)
-            except subprocess.CalledProcessError as e:
-                file_out.close()
-                bb.fatal("Cannot compute packages dependencies. Command '%s' "
-                         "returned %d:\n%s" % (e.cmd, e.returncode, e.output))
-
-            file_out.close()
-
-        return output
 
     def list_pkgs(self):
         cmd = [bb.utils.which(os.getenv('PATH'), "dpkg-query"),
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list()
  2016-01-07 20:07 ` [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list() mariano.lopez
@ 2016-01-09 23:55   ` Pau Espin Pedrol
  2016-01-11 20:14     ` Mariano Lopez
  0 siblings, 1 reply; 7+ messages in thread
From: Pau Espin Pedrol @ 2016-01-09 23:55 UTC (permalink / raw)
  To: mariano.lopez; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 12352 bytes --]

Hi,

I don't have the env to test the patch anymore.

However, I have a question on this patch. I inline the comment in the code
here, below the related lines:

2016-01-07 21:07 GMT+01:00 <mariano.lopez@linux.intel.com>:

> From: Mariano Lopez <mariano.lopez@linux.intel.com>
>
> This patch changes the use list_pkgs() instead of list()
> from class RpmPkgsList. The change is in two functions,
> image_list_installed_packages from rootfs.py and
> sdk_list_installed_packages from sdk.py.
>
> With this change the functions calling the functions
> listed above, must format the output as they required.
> The formatting can be done using format_pkg_list() from
> oe.utils.
>
> The classes calling the afected functions are changed too
> with this patch, to keep the same functionality using the
> new data structure.
>
> [YOCTO #7427]
>
> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
> ---
>  meta/classes/buildhistory.bbclass        | 11 +++++++----
>  meta/classes/license.bbclass             |  8 ++++++--
>  meta/classes/populate_sdk_base.bbclass   |  8 ++++++--
>  meta/classes/rootfs-postcommands.bbclass |  5 +++--
>  meta/lib/oe/package_manager.py           | 18 ++++++++++--------
>  meta/lib/oe/rootfs.py                    |  8 ++++----
>  meta/lib/oe/sdk.py                       |  8 ++++----
>  7 files changed, 40 insertions(+), 26 deletions(-)
>
> diff --git a/meta/classes/buildhistory.bbclass
> b/meta/classes/buildhistory.bbclass
> index 4153e58..a2f8ac7 100644
> --- a/meta/classes/buildhistory.bbclass
> +++ b/meta/classes/buildhistory.bbclass
> @@ -337,18 +337,21 @@ def write_pkghistory(pkginfo, d):
>  def buildhistory_list_installed(d, rootfs_type="image"):
>      from oe.rootfs import image_list_installed_packages
>      from oe.sdk import sdk_list_installed_packages
> +    from oe.utils import format_pkg_list
>
>      process_list = [('file', 'bh_installed_pkgs.txt'),\
>                      ('deps', 'bh_installed_pkgs_deps.txt')]
>
> +    if rootfs_type == "image":
> +        pkgs = image_list_installed_packages(d)
> +    else:
> +        pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target")
> +
>      for output_type, output_file in process_list:
>          output_file_full = os.path.join(d.getVar('WORKDIR', True),
> output_file)
>
>          with open(output_file_full, 'w') as output:
> -            if rootfs_type == "image":
> -                output.write(image_list_installed_packages(d,
> output_type))
> -            else:
> -                output.write(sdk_list_installed_packages(d, rootfs_type
> == "sdk_target", output_type))
> +            output.write(format_pkg_list(pkgs, output_type))
>
>  python buildhistory_list_installed_image() {
>      buildhistory_list_installed(d)
> diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
> index 6651d55..fed42ca 100644
> --- a/meta/classes/license.bbclass
> +++ b/meta/classes/license.bbclass
> @@ -21,8 +21,12 @@ python write_package_manifest() {
>      license_image_dir = d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}')
>      bb.utils.mkdirhier(license_image_dir)
>      from oe.rootfs import image_list_installed_packages
> +    from oe.utils import format_pkg_list
> +
> +    pkgs = image_list_installed_packages(d)
> +    output = format_pkg_list(pkgs)
>      open(os.path.join(license_image_dir, 'package.manifest'),
> -        'w+').write(image_list_installed_packages(d))
> +        'w+').write(output)
>  }
>
>  python write_deploy_manifest() {
> @@ -38,7 +42,7 @@ python license_create_manifest() {
>          return 0
>
>      pkg_dic = {}
> -    for pkg in image_list_installed_packages(d).splitlines():
> +    for pkg in sorted(image_list_installed_packages(d)):
>          pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True),
>                                  'runtime-reverse', pkg)
>          pkg_name = os.path.basename(os.readlink(pkg_info))
> diff --git a/meta/classes/populate_sdk_base.bbclass
> b/meta/classes/populate_sdk_base.bbclass
> index 23dc115..26e06a5 100644
> --- a/meta/classes/populate_sdk_base.bbclass
> +++ b/meta/classes/populate_sdk_base.bbclass
> @@ -62,20 +62,24 @@ SDK_TARGET_MANIFEST =
> "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"
>  SDK_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"
>  python write_target_sdk_manifest () {
>      from oe.sdk import sdk_list_installed_packages
> +    from oe.utils import format_pkg_list
>      sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST",
> True))
> +    pkgs = sdk_list_installed_packages(d, True)
>      if not os.path.exists(sdkmanifestdir):
>          bb.utils.mkdirhier(sdkmanifestdir)
>      with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output:
> -        output.write(sdk_list_installed_packages(d, True, 'ver'))
> +        output.write(format_pkg_list(pkgs, 'ver'))
>  }
>
>  python write_host_sdk_manifest () {
>      from oe.sdk import sdk_list_installed_packages
> +    from oe.utils import format_pkg_list
>      sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True))
> +    pkgs = sdk_list_installed_packages(d, False)
>      if not os.path.exists(sdkmanifestdir):
>          bb.utils.mkdirhier(sdkmanifestdir)
>      with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output:
> -        output.write(sdk_list_installed_packages(d, False, 'ver'))
> +        output.write(format_pkg_list(pkgs, 'ver'))
>  }
>
>  POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
> diff --git a/meta/classes/rootfs-postcommands.bbclass
> b/meta/classes/rootfs-postcommands.bbclass
> index 96d3051..fe664b7 100644
> --- a/meta/classes/rootfs-postcommands.bbclass
> +++ b/meta/classes/rootfs-postcommands.bbclass
> @@ -207,14 +207,15 @@ insert_feed_uris () {
>
>  python write_image_manifest () {
>      from oe.rootfs import image_list_installed_packages
> +    from oe.utils import format_pkg_list
>
>      deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True)
>      link_name = d.getVar('IMAGE_LINK_NAME', True)
>      manifest_name = d.getVar('IMAGE_MANIFEST', True)
>
> +    pkgs = image_list_installed_packages(d)
>      with open(manifest_name, 'w+') as image_manifest:
> -        image_manifest.write(image_list_installed_packages(d, 'ver'))
> -        image_manifest.write("\n")
> +        image_manifest.write(format_pkg_list(pkgs, "ver"))
>
>
As far as I understand from patch 2/4 in this series, you get something
like "pkgInfo0\npkgInfoX\npkInfoLast" when using join() from inside
format_pkg_list(), so you get no "\n" at the end of the file, and still you
are also removing the line which adds the "\n" at the end. That would break
the workaround which was added to fix bug #7427 in yocto right? Or am I
missing something?


>      if manifest_name is not None and os.path.exists(manifest_name):
>          manifest_link = deploy_dir + "/" + link_name + ".manifest"
> diff --git a/meta/lib/oe/package_manager.py
> b/meta/lib/oe/package_manager.py
> index 95e7ae7..522cbf7 100644
> --- a/meta/lib/oe/package_manager.py
> +++ b/meta/lib/oe/package_manager.py
> @@ -693,7 +693,7 @@ class PackageManager(object):
>          pass
>
>      @abstractmethod
> -    def list_installed(self, format=None):
> +    def list_installed(self):
>          pass
>
>      @abstractmethod
> @@ -713,7 +713,9 @@ class PackageManager(object):
>          installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR', True),
>                                             "installed_pkgs.txt")
>          with open(installed_pkgs_file, "w+") as installed_pkgs:
> -            installed_pkgs.write(self.list_installed("arch"))
> +            pkgs = self.list_installed()
> +            output = oe.utils.format_pkg_list(pkgs, "arch")
> +            installed_pkgs.write(output)
>
>          if globs is None:
>              globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
> @@ -1417,8 +1419,8 @@ class RpmPM(PackageManager):
>                              self.image_rpmlib,
>                              symlinks=True)
>
> -    def list_installed(self, format=None):
> -        return self.pkgs_list.list(format)
> +    def list_installed(self):
> +        return self.pkgs_list.list_pkgs()
>
>      '''
>      If incremental install, we need to determine what we've got,
> @@ -1782,8 +1784,8 @@ class OpkgPM(PackageManager):
>          # create the directory back, it's needed by PM lock
>          bb.utils.mkdirhier(self.opkg_dir)
>
> -    def list_installed(self, format=None):
> -        return OpkgPkgsList(self.d, self.target_rootfs,
> self.config_file).list(format)
> +    def list_installed(self):
> +        return OpkgPkgsList(self.d, self.target_rootfs,
> self.config_file).list_pkgs()
>
>      def handle_bad_recommendations(self):
>          bad_recommendations = self.d.getVar("BAD_RECOMMENDATIONS", True)
> or ""
> @@ -2166,8 +2168,8 @@ class DpkgPM(PackageManager):
>              bb.fatal("Cannot fix broken dependencies. Command '%s' "
>                       "returned %d:\n%s" % (cmd, e.returncode, e.output))
>
> -    def list_installed(self, format=None):
> -        return DpkgPkgsList(self.d, self.target_rootfs).list()
> +    def list_installed(self):
> +        return DpkgPkgsList(self.d, self.target_rootfs).list_pkgs()
>
>
>  def generate_index_files(d):
> diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
> index a2af332..45a88fb 100644
> --- a/meta/lib/oe/rootfs.py
> +++ b/meta/lib/oe/rootfs.py
> @@ -963,17 +963,17 @@ def create_rootfs(d, manifest_dir=None):
>      os.environ.update(env_bkp)
>
>
> -def image_list_installed_packages(d, format=None, rootfs_dir=None):
> +def image_list_installed_packages(d, rootfs_dir=None):
>      if not rootfs_dir:
>          rootfs_dir = d.getVar('IMAGE_ROOTFS', True)
>
>      img_type = d.getVar('IMAGE_PKGTYPE', True)
>      if img_type == "rpm":
> -        return RpmPkgsList(d, rootfs_dir).list(format)
> +        return RpmPkgsList(d, rootfs_dir).list_pkgs()
>      elif img_type == "ipk":
> -        return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET",
> True)).list(format)
> +        return OpkgPkgsList(d, rootfs_dir, d.getVar("IPKGCONF_TARGET",
> True)).list_pkgs()
>      elif img_type == "deb":
> -        return DpkgPkgsList(d, rootfs_dir).list(format)
> +        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
>
>  if __name__ == "__main__":
>      """
> diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
> index 6affa40..b308aea 100644
> --- a/meta/lib/oe/sdk.py
> +++ b/meta/lib/oe/sdk.py
> @@ -345,7 +345,7 @@ class DpkgSdk(Sdk):
>
>
>
> -def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None):
> +def sdk_list_installed_packages(d, target, rootfs_dir=None):
>      if rootfs_dir is None:
>          sdk_output = d.getVar('SDK_OUTPUT', True)
>          target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
> @@ -356,12 +356,12 @@ def sdk_list_installed_packages(d, target,
> format=None, rootfs_dir=None):
>      if img_type == "rpm":
>          arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
>          os_var = ["SDK_OS", None][target is True]
> -        return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list(format)
> +        return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list_pkgs()
>      elif img_type == "ipk":
>          conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is
> True]
> -        return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var,
> True)).list(format)
> +        return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var,
> True)).list_pkgs()
>      elif img_type == "deb":
> -        return DpkgPkgsList(d, rootfs_dir).list(format)
> +        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
>
>  def populate_sdk(d, manifest_dir=None):
>      env_bkp = os.environ.copy()
> --
> 1.8.4.5
>
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>

Thanks for your time spent on this,
Pau

[-- Attachment #2: Type: text/html, Size: 15120 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list()
  2016-01-09 23:55   ` Pau Espin Pedrol
@ 2016-01-11 20:14     ` Mariano Lopez
  0 siblings, 0 replies; 7+ messages in thread
From: Mariano Lopez @ 2016-01-11 20:14 UTC (permalink / raw)
  To: Pau Espin Pedrol; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 13777 bytes --]



On 01/09/2016 05:55 PM, Pau Espin Pedrol wrote:
> Hi,
>
> I don't have the env to test the patch anymore.
>
> However, I have a question on this patch. I inline the comment in the 
> code here, below the related lines:
>
> 2016-01-07 21:07 GMT+01:00 <mariano.lopez@linux.intel.com 
> <mailto:mariano.lopez@linux.intel.com>>:
>
>     From: Mariano Lopez <mariano.lopez@linux.intel.com
>     <mailto:mariano.lopez@linux.intel.com>>
>
>     This patch changes the use list_pkgs() instead of list()
>     from class RpmPkgsList. The change is in two functions,
>     image_list_installed_packages from rootfs.py and
>     sdk_list_installed_packages from sdk.py.
>
>     With this change the functions calling the functions
>     listed above, must format the output as they required.
>     The formatting can be done using format_pkg_list() from
>     oe.utils.
>
>     The classes calling the afected functions are changed too
>     with this patch, to keep the same functionality using the
>     new data structure.
>
>     [YOCTO #7427]
>
>     Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com
>     <mailto:mariano.lopez@linux.intel.com>>
>     ---
>      meta/classes/buildhistory.bbclass        | 11 +++++++----
>      meta/classes/license.bbclass             |  8 ++++++--
>      meta/classes/populate_sdk_base.bbclass   |  8 ++++++--
>      meta/classes/rootfs-postcommands.bbclass |  5 +++--
>      meta/lib/oe/package_manager.py           | 18 ++++++++++--------
>      meta/lib/oe/rootfs.py                    |  8 ++++----
>      meta/lib/oe/sdk.py                       |  8 ++++----
>      7 files changed, 40 insertions(+), 26 deletions(-)
>
>     diff --git a/meta/classes/buildhistory.bbclass
>     b/meta/classes/buildhistory.bbclass
>     index 4153e58..a2f8ac7 100644
>     --- a/meta/classes/buildhistory.bbclass
>     +++ b/meta/classes/buildhistory.bbclass
>     @@ -337,18 +337,21 @@ def write_pkghistory(pkginfo, d):
>      def buildhistory_list_installed(d, rootfs_type="image"):
>          from oe.rootfs import image_list_installed_packages
>          from oe.sdk import sdk_list_installed_packages
>     +    from oe.utils import format_pkg_list
>
>          process_list = [('file', 'bh_installed_pkgs.txt'),\
>                          ('deps', 'bh_installed_pkgs_deps.txt')]
>
>     +    if rootfs_type == "image":
>     +        pkgs = image_list_installed_packages(d)
>     +    else:
>     +        pkgs = sdk_list_installed_packages(d, rootfs_type ==
>     "sdk_target")
>     +
>          for output_type, output_file in process_list:
>              output_file_full = os.path.join(d.getVar('WORKDIR',
>     True), output_file)
>
>              with open(output_file_full, 'w') as output:
>     -            if rootfs_type == "image":
>     - output.write(image_list_installed_packages(d, output_type))
>     -            else:
>     - output.write(sdk_list_installed_packages(d, rootfs_type ==
>     "sdk_target", output_type))
>     +            output.write(format_pkg_list(pkgs, output_type))
>
>      python buildhistory_list_installed_image() {
>          buildhistory_list_installed(d)
>     diff --git a/meta/classes/license.bbclass
>     b/meta/classes/license.bbclass
>     index 6651d55..fed42ca 100644
>     --- a/meta/classes/license.bbclass
>     +++ b/meta/classes/license.bbclass
>     @@ -21,8 +21,12 @@ python write_package_manifest() {
>          license_image_dir =
>     d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}')
>          bb.utils.mkdirhier(license_image_dir)
>          from oe.rootfs import image_list_installed_packages
>     +    from oe.utils import format_pkg_list
>     +
>     +    pkgs = image_list_installed_packages(d)
>     +    output = format_pkg_list(pkgs)
>          open(os.path.join(license_image_dir, 'package.manifest'),
>     - 'w+').write(image_list_installed_packages(d))
>     +        'w+').write(output)
>      }
>
>      python write_deploy_manifest() {
>     @@ -38,7 +42,7 @@ python license_create_manifest() {
>              return 0
>
>          pkg_dic = {}
>     -    for pkg in image_list_installed_packages(d).splitlines():
>     +    for pkg in sorted(image_list_installed_packages(d)):
>              pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True),
>                                      'runtime-reverse', pkg)
>              pkg_name = os.path.basename(os.readlink(pkg_info))
>     diff --git a/meta/classes/populate_sdk_base.bbclass
>     b/meta/classes/populate_sdk_base.bbclass
>     index 23dc115..26e06a5 100644
>     --- a/meta/classes/populate_sdk_base.bbclass
>     +++ b/meta/classes/populate_sdk_base.bbclass
>     @@ -62,20 +62,24 @@ SDK_TARGET_MANIFEST =
>     "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"
>      SDK_HOST_MANIFEST =
>     "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"
>      python write_target_sdk_manifest () {
>          from oe.sdk import sdk_list_installed_packages
>     +    from oe.utils import format_pkg_list
>          sdkmanifestdir =
>     os.path.dirname(d.getVar("SDK_TARGET_MANIFEST", True))
>     +    pkgs = sdk_list_installed_packages(d, True)
>          if not os.path.exists(sdkmanifestdir):
>              bb.utils.mkdirhier(sdkmanifestdir)
>          with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output:
>     -        output.write(sdk_list_installed_packages(d, True, 'ver'))
>     +        output.write(format_pkg_list(pkgs, 'ver'))
>      }
>
>      python write_host_sdk_manifest () {
>          from oe.sdk import sdk_list_installed_packages
>     +    from oe.utils import format_pkg_list
>          sdkmanifestdir =
>     os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True))
>     +    pkgs = sdk_list_installed_packages(d, False)
>          if not os.path.exists(sdkmanifestdir):
>              bb.utils.mkdirhier(sdkmanifestdir)
>          with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output:
>     -        output.write(sdk_list_installed_packages(d, False, 'ver'))
>     +        output.write(format_pkg_list(pkgs, 'ver'))
>      }
>
>      POPULATE_SDK_POST_TARGET_COMMAND_append = "
>     write_target_sdk_manifest ; "
>     diff --git a/meta/classes/rootfs-postcommands.bbclass
>     b/meta/classes/rootfs-postcommands.bbclass
>     index 96d3051..fe664b7 100644
>     --- a/meta/classes/rootfs-postcommands.bbclass
>     +++ b/meta/classes/rootfs-postcommands.bbclass
>     @@ -207,14 +207,15 @@ insert_feed_uris () {
>
>      python write_image_manifest () {
>          from oe.rootfs import image_list_installed_packages
>     +    from oe.utils import format_pkg_list
>
>          deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True)
>          link_name = d.getVar('IMAGE_LINK_NAME', True)
>          manifest_name = d.getVar('IMAGE_MANIFEST', True)
>
>     +    pkgs = image_list_installed_packages(d)
>          with open(manifest_name, 'w+') as image_manifest:
>     - image_manifest.write(image_list_installed_packages(d, 'ver'))
>     -        image_manifest.write("\n")
>     +        image_manifest.write(format_pkg_list(pkgs, "ver"))
>
>
> As far as I understand from patch 2/4 in this series, you get 
> something like "pkgInfo0\npkgInfoX\npkInfoLast" when using join() from 
> inside format_pkg_list(), so you get no "\n" at the end of the file, 
> and still you are also removing the line which adds the "\n" at the 
> end. That would break the workaround which was added to fix bug #7427 
> in yocto right? Or am I missing something?

You are right, I just notice that I sent the incorrect set of patches 
(this one doesn't list the last deb or ipk package). I'll send the 
correct set.

Thanks for notice this.
>
>          if manifest_name is not None and os.path.exists(manifest_name):
>              manifest_link = deploy_dir + "/" + link_name + ".manifest"
>     diff --git a/meta/lib/oe/package_manager.py
>     b/meta/lib/oe/package_manager.py
>     index 95e7ae7..522cbf7 100644
>     --- a/meta/lib/oe/package_manager.py
>     +++ b/meta/lib/oe/package_manager.py
>     @@ -693,7 +693,7 @@ class PackageManager(object):
>              pass
>
>          @abstractmethod
>     -    def list_installed(self, format=None):
>     +    def list_installed(self):
>              pass
>
>          @abstractmethod
>     @@ -713,7 +713,9 @@ class PackageManager(object):
>              installed_pkgs_file =
>     os.path.join(self.d.getVar('WORKDIR', True),
>     "installed_pkgs.txt")
>              with open(installed_pkgs_file, "w+") as installed_pkgs:
>     - installed_pkgs.write(self.list_installed("arch"))
>     +            pkgs = self.list_installed()
>     +            output = oe.utils.format_pkg_list(pkgs, "arch")
>     +            installed_pkgs.write(output)
>
>              if globs is None:
>                  globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY',
>     True)
>     @@ -1417,8 +1419,8 @@ class RpmPM(PackageManager):
>                                  self.image_rpmlib,
>                                  symlinks=True)
>
>     -    def list_installed(self, format=None):
>     -        return self.pkgs_list.list(format)
>     +    def list_installed(self):
>     +        return self.pkgs_list.list_pkgs()
>
>          '''
>          If incremental install, we need to determine what we've got,
>     @@ -1782,8 +1784,8 @@ class OpkgPM(PackageManager):
>              # create the directory back, it's needed by PM lock
>              bb.utils.mkdirhier(self.opkg_dir)
>
>     -    def list_installed(self, format=None):
>     -        return OpkgPkgsList(self.d, self.target_rootfs,
>     self.config_file).list(format)
>     +    def list_installed(self):
>     +        return OpkgPkgsList(self.d, self.target_rootfs,
>     self.config_file).list_pkgs()
>
>          def handle_bad_recommendations(self):
>              bad_recommendations =
>     self.d.getVar("BAD_RECOMMENDATIONS", True) or ""
>     @@ -2166,8 +2168,8 @@ class DpkgPM(PackageManager):
>                  bb.fatal("Cannot fix broken dependencies. Command '%s' "
>                           "returned %d:\n%s" % (cmd, e.returncode,
>     e.output))
>
>     -    def list_installed(self, format=None):
>     -        return DpkgPkgsList(self.d, self.target_rootfs).list()
>     +    def list_installed(self):
>     +        return DpkgPkgsList(self.d, self.target_rootfs).list_pkgs()
>
>
>      def generate_index_files(d):
>     diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py
>     index a2af332..45a88fb 100644
>     --- a/meta/lib/oe/rootfs.py
>     +++ b/meta/lib/oe/rootfs.py
>     @@ -963,17 +963,17 @@ def create_rootfs(d, manifest_dir=None):
>          os.environ.update(env_bkp)
>
>
>     -def image_list_installed_packages(d, format=None, rootfs_dir=None):
>     +def image_list_installed_packages(d, rootfs_dir=None):
>          if not rootfs_dir:
>              rootfs_dir = d.getVar('IMAGE_ROOTFS', True)
>
>          img_type = d.getVar('IMAGE_PKGTYPE', True)
>          if img_type == "rpm":
>     -        return RpmPkgsList(d, rootfs_dir).list(format)
>     +        return RpmPkgsList(d, rootfs_dir).list_pkgs()
>          elif img_type == "ipk":
>     -        return OpkgPkgsList(d, rootfs_dir,
>     d.getVar("IPKGCONF_TARGET", True)).list(format)
>     +        return OpkgPkgsList(d, rootfs_dir,
>     d.getVar("IPKGCONF_TARGET", True)).list_pkgs()
>          elif img_type == "deb":
>     -        return DpkgPkgsList(d, rootfs_dir).list(format)
>     +        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
>
>      if __name__ == "__main__":
>          """
>     diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py
>     index 6affa40..b308aea 100644
>     --- a/meta/lib/oe/sdk.py
>     +++ b/meta/lib/oe/sdk.py
>     @@ -345,7 +345,7 @@ class DpkgSdk(Sdk):
>
>
>
>     -def sdk_list_installed_packages(d, target, format=None,
>     rootfs_dir=None):
>     +def sdk_list_installed_packages(d, target, rootfs_dir=None):
>          if rootfs_dir is None:
>              sdk_output = d.getVar('SDK_OUTPUT', True)
>              target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
>     @@ -356,12 +356,12 @@ def sdk_list_installed_packages(d, target,
>     format=None, rootfs_dir=None):
>          if img_type == "rpm":
>              arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
>              os_var = ["SDK_OS", None][target is True]
>     -        return RpmPkgsList(d, rootfs_dir, arch_var,
>     os_var).list(format)
>     +        return RpmPkgsList(d, rootfs_dir, arch_var,
>     os_var).list_pkgs()
>          elif img_type == "ipk":
>              conf_file_var = ["IPKGCONF_SDK",
>     "IPKGCONF_TARGET"][target is True]
>     -        return OpkgPkgsList(d, rootfs_dir,
>     d.getVar(conf_file_var, True)).list(format)
>     +        return OpkgPkgsList(d, rootfs_dir,
>     d.getVar(conf_file_var, True)).list_pkgs()
>          elif img_type == "deb":
>     -        return DpkgPkgsList(d, rootfs_dir).list(format)
>     +        return DpkgPkgsList(d, rootfs_dir).list_pkgs()
>
>      def populate_sdk(d, manifest_dir=None):
>          env_bkp = os.environ.copy()
>     --
>     1.8.4.5
>
>     --
>     _______________________________________________
>     Openembedded-core mailing list
>     Openembedded-core@lists.openembedded.org
>     <mailto:Openembedded-core@lists.openembedded.org>
>     http://lists.openembedded.org/mailman/listinfo/openembedded-core
>
>
> Thanks for your time spent on this,
> Pau

-- 
Mariano Lopez

[-- Attachment #2: Type: text/html, Size: 23966 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-01-11 20:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-07 20:07 [PATCH 0/4] Clean PkgsList return data implementation mariano.lopez
2016-01-07 20:07 ` [PATCH 1/4] lib/oe/package_manager: Add list_pkgs() to PkgsList class mariano.lopez
2016-01-07 20:07 ` [PATCH 2/4] lib/oe/utils: Add function format_pkg_list() mariano.lopez
2016-01-07 20:07 ` [PATCH 3/4] lib/oe/rootfs: Use list_pkgs() instead of list() mariano.lopez
2016-01-09 23:55   ` Pau Espin Pedrol
2016-01-11 20:14     ` Mariano Lopez
2016-01-07 20:07 ` [PATCH 4/4] lib/oe/package_manager.py: Remove list() from PkgsList class mariano.lopez

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.