[oe-commits] [openembedded-core] 06/09: package_manager.py: better error handling in opkg's package listing

git at git.openembedded.org git at git.openembedded.org
Tue Apr 5 08:56:35 UTC 2016


rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 7d9e915224a9bc451fddfbbfad533d9b06e9987d
Author: Patrick Ohly <patrick.ohly at intel.com>
AuthorDate: Mon Apr 4 15:41:42 2016 +0200

    package_manager.py: better error handling in opkg's package listing
    
    opkg does not return a non-zero exit code even if it found
    errors. When that happens, parsing the output leads to strange
    follow-up errors.
    
    To avoid this we need to check explicitly for non-empty
    stderr. Reporting only that on a failure also leads to shorter error
    messages (stdout may be very large).
    
    Signed-off-by: Patrick Ohly <patrick.ohly at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oe/package_manager.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 0d23d8b..b4b359a 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -468,13 +468,16 @@ class OpkgPkgsList(PkgsList):
     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:
+        # opkg returns success even when it printed some
+        # "Collected errors:" report to stderr. Mixing stderr into
+        # stdout then leads to random failures later on when
+        # parsing the output. To avoid this we need to collect both
+        # output streams separately and check for empty stderr.
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+        cmd_output, cmd_stderr = p.communicate()
+        if p.returncode or cmd_stderr:
             bb.fatal("Cannot get the installed packages list. Command '%s' "
-                     "returned %d:\n%s" % (cmd, e.returncode, e.output))
+                     "returned %d and stderr:\n%s" % (cmd, p.returncode, cmd_stderr))
 
         return self.opkg_query(cmd_output)
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list