[elbe-devel] [PATCH v2 7/7] pbuilder: add support for preprocess by using the new PreprocessWrapper

Torben Hohn torben.hohn at linutronix.de
Mon Oct 15 12:43:20 CEST 2018


add preprocess options using PreprocessWrapper.add_options()
and use PreprocessWrapper in CreateAction

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/pbuilder.py |  6 +++++-
 elbepack/pbuilderaction.py    | 42 ++++++++++++++++++++++++++----------------
 2 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/elbepack/commands/pbuilder.py b/elbepack/commands/pbuilder.py
index 1a806c67..5b8542d4 100644
--- a/elbepack/commands/pbuilder.py
+++ b/elbepack/commands/pbuilder.py
@@ -10,6 +10,7 @@ import sys
 
 from optparse import OptionParser
 from elbepack.pbuilderaction import PBuilderAction, PBuilderError
+from elbepack.xmlpreprocess import PreprocessWrapper
 
 
 def run_command(argv):
@@ -39,7 +40,10 @@ def run_command(argv):
                        help="directory where to save downloaded Files")
 
     oparser.add_option("--cpuset", default=-1, type="int",
-                       help="Limit cpuset of pbuilder commands (bitmask) (defaults to -1 for all CPUs)")
+                       help="Limit cpuset of pbuilder commands (bitmask) "
+                            "(defaults to -1 for all CPUs)")
+
+    PreprocessWrapper.add_options(oparser)
 
     (opt, args) = oparser.parse_args(argv)
 
diff --git a/elbepack/pbuilderaction.py b/elbepack/pbuilderaction.py
index a161a7bf..a1e25b9c 100644
--- a/elbepack/pbuilderaction.py
+++ b/elbepack/pbuilderaction.py
@@ -12,6 +12,7 @@ import os
 from elbepack.directories import elbe_exe
 from elbepack.shellhelper import CommandError, system, command_out_stderr
 from elbepack.filesystem import TmpdirFilesystem
+from elbepack.xmlpreprocess import PreprocessWrapper
 
 
 def cmd_exists(x):
@@ -68,22 +69,31 @@ class CreateAction(PBuilderAction):
     def execute(self, opt, _args):
 
         if opt.xmlfile:
-            ret, prjdir, err = command_out_stderr(
-                '%s control create_project' % (elbe_exe))
-            if ret != 0:
-                print("elbe control create_project failed.", file=sys.stderr)
-                print(err, file=sys.stderr)
-                print("Giving up", file=sys.stderr)
-                sys.exit(20)
-
-            prjdir = prjdir.strip()
-            ret, _, err = command_out_stderr(
-                '%s control set_xml "%s" "%s"' %
-                (elbe_exe, prjdir, opt.xmlfile))
-
-            if ret != 0:
-                print("elbe control set_xml failed.", file=sys.stderr)
-                print(err, file=sys.stderr)
+            try:
+                with PreprocessWrapper(opt.xmlfile, opt) as ppw:
+                    ret, prjdir, err = command_out_stderr(
+                        '%s control create_project' % (elbe_exe))
+                    if ret != 0:
+                        print("elbe control create_project failed.",
+                              file=sys.stderr)
+                        print(err, file=sys.stderr)
+                        print("Giving up", file=sys.stderr)
+                        sys.exit(20)
+
+                    prjdir = prjdir.strip()
+                    ret, _, err = command_out_stderr(
+                        '%s control set_xml "%s" "%s"' %
+                        (elbe_exe, prjdir, ppw.preproc))
+
+                    if ret != 0:
+                        print("elbe control set_xml failed.", file=sys.stderr)
+                        print(err, file=sys.stderr)
+                        print("Giving up", file=sys.stderr)
+                        sys.exit(20)
+            except CommandError:
+                # this is the failure from PreprocessWrapper
+                # it already printed the error message from
+                # elbe preprocess
                 print("Giving up", file=sys.stderr)
                 sys.exit(20)
 
-- 
2.11.0




More information about the elbe-devel mailing list