[elbe-devel] [PATCH 2/5] elbepack: preprocess: parse variant string during option parsing

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jul 3 11:10:56 CEST 2024


This will allow an easy reuse of "opt.variants" in other callsites.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/commands/preprocess.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/elbepack/commands/preprocess.py b/elbepack/commands/preprocess.py
index 5d7d2b62f05d..6270541761be 100644
--- a/elbepack/commands/preprocess.py
+++ b/elbepack/commands/preprocess.py
@@ -9,9 +9,16 @@ from optparse import OptionGroup, OptionParser
 from elbepack.xmlpreprocess import XMLPreprocessError, xmlpreprocess
 
 
+def _comma_separated_list(option, opt, value, parser):
+    if value is None:
+        return
+
+    setattr(parser.values, option.dest, value.split(','))
+
+
 def _add_options(oparser):
     oparser.add_option('-v', '--variants', dest='variant',
-                       default=None,
+                       action='callback', callback=_comma_separated_list, type=str,
                        help='enable only tags with empty or given variant')
 
     oparser.add_option('-p', '--proxy', dest='proxy',
@@ -49,12 +56,8 @@ def run_command(argv):
         print(f"{args[0]} doesn't exist", file=sys.stderr)
         sys.exit(113)
 
-    variants = []
-    if opt.variant:
-        variants = opt.variant.split(',')
-
     try:
-        xmlpreprocess(args[0], opt.output, variants, opt.proxy, opt.gzip)
+        xmlpreprocess(args[0], opt.output, opt.variant, opt.proxy, opt.gzip)
     except XMLPreprocessError as e:
         print(e, file=sys.stderr)
         sys.exit(114)

-- 
2.45.2



More information about the elbe-devel mailing list