[elbe-devel] [PATCH v2 5/7] xmlpreprocess initvm: add support for passing options to "elbe preprocess"
Torben Hohn
torben.hohn at linutronix.de
Mon Oct 15 12:43:18 CEST 2018
'elbe preprocess' is less useful, when the variant option can not be passed
to it.
Add support for passing options to xmlpreprocess.PreprocessWrapper().
Then call PreprocessWrapper.add_options() from commands.initvm().
And finally pass the opt variable to the instantiation of PreprocessWrapper
in elbepack.initvmaction.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/commands/initvm.py | 3 +++
elbepack/initvmaction.py | 2 +-
elbepack/xmlpreprocess.py | 26 ++++++++++++++++++++++----
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/elbepack/commands/initvm.py b/elbepack/commands/initvm.py
index c85d8a79..eeb5a1e6 100644
--- a/elbepack/commands/initvm.py
+++ b/elbepack/commands/initvm.py
@@ -11,6 +11,7 @@ import os
from optparse import OptionParser
from elbepack.initvmaction import InitVMAction, InitVMError
+from elbepack.xmlpreprocess import PreprocessWrapper
def run_command(argv):
@@ -65,6 +66,8 @@ def run_command(argv):
help="allow initvm to support nested kvm. "
"This makes /proc/cpuinfo inside initvm differ per host.")
+ PreprocessWrapper.add_options(oparser)
+
(opt, args) = oparser.parse_args(argv)
if len(args) < 1:
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 27c0f6ac..6b9b746e 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -245,7 +245,7 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
# pylint: disable=too-many-branches
try:
- with PreprocessWrapper(xmlfile) as ppw:
+ with PreprocessWrapper(xmlfile, opt) as ppw:
xmlfile = ppw.preproc
ret, prjdir, err = command_out_stderr(
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index bd082779..2a20445a 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -9,6 +9,7 @@ from __future__ import print_function
import sys
from tempfile import NamedTemporaryFile
+from optparse import OptionGroup
from lxml import etree
from lxml.etree import XMLParser, parse
@@ -123,16 +124,21 @@ def xmlpreprocess(fname, output, variants=None):
class PreprocessWrapper(object): # pylint: disable=too-few-public-methods
- def __init__(self, xmlfile):
+ def __init__(self, xmlfile, opt):
self.xmlfile = xmlfile
self.outxml = None
+ self.options = ""
+
+ if opt.variant:
+ self.options += ' --variants "%s"' % opt.variant
def __enter__(self):
self.outxml = NamedTemporaryFile(prefix='elbe', suffix='xml')
- cmd = '%s preprocess -o %s %s' % (elbe_exe,
- self.outxml.name,
- self.xmlfile)
+ cmd = '%s preprocess %s -o %s %s' % (elbe_exe,
+ self.options,
+ self.outxml.name,
+ self.xmlfile)
ret, _, err = command_out_stderr(cmd)
if ret != 0:
print("elbe preprocess failed.", file=sys.stderr)
@@ -144,6 +150,18 @@ class PreprocessWrapper(object): # pylint: disable=too-few-public-methods
def __exit__(self, _typ, _value, _traceback):
self.outxml = None
+ @staticmethod
+ def add_options(oparser):
+ # import it here because of cyclic imports
+ from elbepack.commands.preprocess import add_pass_through_options
+
+ group = OptionGroup(oparser,
+ 'Elbe preprocess options',
+ 'Options passed through to invocation of '
+ '"elbe preprocess"')
+ add_pass_through_options(group)
+ oparser.add_option_group(group)
+
@property
def preproc(self):
return self.outxml.name
--
2.11.0
More information about the elbe-devel
mailing list