[elbe-devel] [PATCH 2/4] sdk: improve error handling and logging

Manuel Traut manut at linutronix.de
Thu Feb 28 13:30:09 CET 2019


None of the command executions in extract_pkg() are logged.
If a command fails fallbacks are implemented. But what is
actually executed can't be seen.

This makes the log parameter of extract_pkg non-optional
and use log.do() instead of system() to get command execution
logged.

It also fixups the callers to pass in a log object.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/elbeproject.py |  2 ++
 elbepack/pkgutils.py    | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index d75ed008..7fdd1a3f 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -318,12 +318,14 @@ class ElbeProject (object):
                     self.xml.defs,
                     crosstoolchainpkg,
                     'amd64',
+                    self.log,
                     True)
         extract_pkg(self.xml.prj,
                     hostsysrootpath,
                     self.xml.defs,
                     'gdb-multiarch',
                     'amd64',
+                    self.log,
                     True)
 
         n = gen_sdk_scripts(triplet,
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 19009b4c..6cb0c85e 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -143,8 +143,7 @@ def download_pkg(prj,
     return [y[0] for y in urilist]
 
 
-def extract_pkg(prj, target_dir, defs, package, arch="default",
-                incl_deps=False, log=None):
+def extract_pkg(prj, target_dir, defs, package, arch, log, incl_deps=False):
 
     # pylint: disable=too-many-arguments
 
@@ -153,13 +152,17 @@ def extract_pkg(prj, target_dir, defs, package, arch="default",
     for package in pkgs:
         ppath = os.path.join(target_dir, "%s.deb" % package)
         try:
-            system('dpkg -x "%s" "%s"' % (ppath, target_dir))
+            log.do('dpkg -x "%s" "%s"' % (ppath, target_dir))
         except CommandError:
             try:
                 # dpkg did not work, try falling back to ar and tar
-                system('ar p "%s" data.tar.gz | tar xz -C "%s"' % (ppath,
+                log.do('ar p "%s" data.tar.gz | tar xz -C "%s"' % (ppath,
                                                                    target_dir))
             except CommandError:
-                system('ar p "%s" data.tar.xz | tar xJ -C "%s"' % (ppath,
-                                                                   target_dir))
-        system('rm -f "%s"' % ppath)
+                try:
+                    log.do('ar p "%s" data.tar.xz | tar xJ -C "%s"' % (
+                           ppath, target_dir))
+                except CommandError as e:
+                    log.printo("extract %s failed: %s\n" % (ppath, e))
+                    raise e
+        log.do('rm -f "%s"' % ppath)
-- 
2.20.1




More information about the elbe-devel mailing list