osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38285?usp=email )


Change subject: testenv: improve --config argument parsing
......................................................................

testenv: improve --config argument parsing

* Fix that it didn't complain about and invalid --config argument, as
  long as there was a valid --config argument before it.
* Let raise_error_config_arg only output the invalid --config argument
  instead of all of them.
* Complain if "--config all" is used in combination with another
  --config argument.

Change-Id: I66b976b0332be523c084a6b5d38d0f62134b495d
---
M _testenv/testenv/testenv_cfg.py
1 file changed, 21 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/85/38285/1

diff --git a/_testenv/testenv/testenv_cfg.py b/_testenv/testenv/testenv_cfg.py
index 9642ae8..5124a47 100644
--- a/_testenv/testenv/testenv_cfg.py
+++ b/_testenv/testenv/testenv_cfg.py
@@ -134,14 +134,14 @@
     get_vty_host_port(cfg, path)


-def raise_error_config_arg(glob_result):
+def raise_error_config_arg(glob_result, config_arg):
     valid = []
     for path in glob_result:
         basename = os.path.basename(path)
         if basename != "testenv.cfg":
             valid += [basename.split("_", 1)[1].split(".", -1)[0]]

-    msg = f"Invalid parameter for --config: {testenv.args.config}"
+    msg = f"Invalid parameter for --config: {config_arg}"

     if valid:
         msg += f" (valid: all, {', '.join(valid)})"
@@ -185,6 +185,8 @@
 def init():
     global cfgs

+    cfgs_all = {}
+
     config_paths = find_configs()

     for path in config_paths:
@@ -201,14 +203,24 @@
         handle_latest(cfg, path)
         verify(cfg, path)

+        # No --config argument given, and there is only one testenv.cfg
         if not testenv.args.config:
             cfgs[basename] = cfg
+            return
+
+        cfgs_all[basename] = cfg
+
+    # Select configs based on --config argument(s)
+    for config_arg in testenv.args.config:
+        if config_arg == "all":
+            if len(testenv.args.config) != 1:
+                raise testenv.NoTraceException("Can't use multiple --config 
arguments if one of them is 'all'")
+            cfgs = cfgs_all
+            return
+
+        basename = f"testenv_{config_arg}.cfg"
+        if basename in cfgs_all:
+            cfgs[basename] = cfgs_all[basename]
             continue

-        for config_arg in testenv.args.config:
-            if config_arg == "all" or f"testenv_{config_arg}.cfg" == basename:
-                cfgs[basename] = cfg
-                break
-
-    if not cfgs:
-        raise_error_config_arg(config_paths)
+        raise_error_config_arg(config_paths, config_arg)

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38285?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I66b976b0332be523c084a6b5d38d0f62134b495d
Gerrit-Change-Number: 38285
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to