[elbe-devel] [PATCH 04/18] elbepack: config: make all argument helpers type agnostic

Thomas Weißschuh thomas.weissschuh at linutronix.de
Tue Aug 13 13:15:34 CEST 2024


Adapt all helper methods to work on both ArgumentParsers and decorated
functions.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/config.py       | 25 ++++++++++++++++---------
 elbepack/initvmaction.py | 28 +++++++++++++++++-----------
 2 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/elbepack/config.py b/elbepack/config.py
index 552953aaeba2..4643a5371198 100644
--- a/elbepack/config.py
+++ b/elbepack/config.py
@@ -7,8 +7,9 @@ import os
 from elbepack.cli import add_argument
 
 
-def add_argument_soaptimeout(parser):
-    parser.add_argument(
+def add_argument_soaptimeout(parser_or_func):
+    return add_argument(
+        parser_or_func,
         '--soaptimeout',
         type=int,
         default=os.environ.get('ELBE_SOAPTIMEOUT_SECS', '90'),
@@ -25,28 +26,32 @@ def add_argument_soapport(parser_or_func, arg='--port'):
     )
 
 
-def add_arguments_soapclient(parser):
-    parser.add_argument(
+def add_arguments_soapclient(parser_or_func):
+    parser_or_func = add_argument(
+        parser_or_func,
         '--host',
         dest='soaphost',
         default=os.environ.get('ELBE_SOAPHOST', 'localhost'),
     )
-    add_argument_soapport(parser)
-    add_argument_soaptimeout(parser)
+    parser_or_func = add_argument_soapport(parser_or_func)
+    parser_or_func = add_argument_soaptimeout(parser_or_func)
 
-    parser.add_argument(
+    parser_or_func = add_argument(
+        parser_or_func,
         '--user',
         dest='soapuser',
         default=os.environ.get('ELBE_USER', 'root'),
     )
 
-    parser.add_argument(
+    parser_or_func = add_argument(
+        parser_or_func,
         '--pass',
         dest='soappassword',
         default=os.environ.get('ELBE_USER', 'foo'),
     )
 
-    parser.add_argument(
+    parser_or_func = add_argument(
+        parser_or_func,
         '--retries',
         dest='retries',
         type=int,
@@ -54,6 +59,8 @@ def add_arguments_soapclient(parser):
         help='How many times to retry the connection to the server before '
              'giving up (default is 10 times, yielding 10 seconds).')
 
+    return parser_or_func
+
 
 def add_argument_sshport(parser_or_func):
     return add_argument(
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 01cf89f7dc96..780cd464cb9a 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -26,27 +26,33 @@ from elbepack.xmlpreprocess import preprocess_file
 prog = os.path.basename(sys.argv[0])
 
 
-def _add_initvm_from_args_arguments(f):
-    f = add_argument('--qemu', action='store_true',
-                     dest='qemu_mode', default=False,
-                     help='Use QEMU direct instead of libvirtd.')(f)
-
-    f = add_argument(
+def _add_initvm_from_args_arguments(parser_or_func):
+    parser_or_func = add_argument(
+        parser_or_func,
+        '--qemu',
+        action='store_true',
+        dest='qemu_mode',
+        default=False,
+        help='Use QEMU direct instead of libvirtd.')
+
+    parser_or_func = add_argument(
+        parser_or_func,
         '--directory',
         dest='directory',
         type=os.path.abspath,
         default=os.getcwd() + '/initvm',
-        help='directory, where the initvm resides, default is ./initvm')(f)
+        help='directory, where the initvm resides, default is ./initvm')
 
-    f = add_argument(
+    parser_or_func = add_argument(
+        parser_or_func,
         '--domain',
         dest='domain',
         default=os.environ.get('ELBE_INITVM_DOMAIN', 'initvm'),
-        help='Name of the libvirt initvm')(f)
+        help='Name of the libvirt initvm')
 
-    f = add_argument_soapport(f)
+    parser_or_func = add_argument_soapport(parser_or_func)
 
-    return f
+    return parser_or_func
 
 
 def _initvm_from_args(args):

-- 
2.46.0



More information about the elbe-devel mailing list