[elbe-devel] [PATCH] preprocess: always set --variant=default

Manuel Traut manut at linutronix.de
Tue Dec 4 16:50:31 CET 2018


currently is not posible to set a default value for an element, e.g.

<hostname>test</hostname>
<hostname variant="ng">test-ng</hostname>

will result in

<hostname>test</hostname>

if no --variant parameter was given, but it will result in

<hostname>test</hostname>
<hostname variant="ng">test-ng</hostname>

if --variant="ng" was specified.

With this change elbe uses --variant=default as default. So

<hostname variant="default">test</hostname>
<hostname variant="ng">test-ng</hostname>

will work for both calls described above.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 docs/elbe-preprocess.txt        | 3 +++
 elbepack/commands/preprocess.py | 6 ++----
 elbepack/xmlpreprocess.py       | 7 ++-----
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/docs/elbe-preprocess.txt b/docs/elbe-preprocess.txt
index 1a562398..17c25549 100644
--- a/docs/elbe-preprocess.txt
+++ b/docs/elbe-preprocess.txt
@@ -23,6 +23,9 @@ only be used if 'elbe preprocess' is called with --variant=audio or
 --variant=video or --variant=audio,video. If no --variant is given, the tag
 will be dropped.
 
+A tag with variant="default" is only used if no --variant parameter was
+specified.
+
 OPTIONS
 -------
 
diff --git a/elbepack/commands/preprocess.py b/elbepack/commands/preprocess.py
index 44e298c4..18f56cdf 100644
--- a/elbepack/commands/preprocess.py
+++ b/elbepack/commands/preprocess.py
@@ -14,7 +14,7 @@ from elbepack.xmlpreprocess import XMLPreprocessError, xmlpreprocess
 
 def add_pass_through_options(oparser):
     oparser.add_option("-v", "--variants", dest="variant",
-                       default=None,
+                       default="default",
                        help="enable only tags with empty or given variant")
 
 
@@ -35,9 +35,7 @@ def run_command(argv):
         print("%s doesn't exist" % args[0], file=sys.stderr)
         sys.exit(20)
 
-    variants = []
-    if opt.variant:
-        variants = opt.variant.split(',')
+    variants = opt.variant.split(',')
 
     try:
         xmlpreprocess(args[0], opt.output, variants)
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 2a20445a..f2966357 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -29,16 +29,13 @@ class XMLPreprocessError(Exception):
     pass
 
 
-def xmlpreprocess(fname, output, variants=None):
+def xmlpreprocess(fname, output, variants):
 
     # pylint: disable=too-many-locals
     # pylint: disable=too-many-branches
 
     # first convert variants to a set
-    if not variants:
-        variants = set([])
-    else:
-        variants = set(variants)
+    variants = set(variants)
 
     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
     parser = XMLParser(huge_tree=True)
-- 
2.19.2




More information about the elbe-devel mailing list