summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/utils/util.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-07-24 15:36:18 -0500
committerJohn Estabrook <jestabro@vyos.io>2022-07-25 15:47:11 -0500
commitfa8dcff5d2e18ded5310d3f86ea0dc1bf2795af8 (patch)
tree8429207b5386557b83007ba71fae9b874042840b /src/services/api/graphql/utils/util.py
parent423485a0b87a650c74dd490a1335af969ef83237 (diff)
downloadvyos-1x-fa8dcff5d2e18ded5310d3f86ea0dc1bf2795af8.tar.gz
vyos-1x-fa8dcff5d2e18ded5310d3f86ea0dc1bf2795af8.zip
graphql: T4554: add resolver support for op-mode scripts
Diffstat (limited to 'src/services/api/graphql/utils/util.py')
-rw-r--r--src/services/api/graphql/utils/util.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/services/api/graphql/utils/util.py b/src/services/api/graphql/utils/util.py
index bf30f673a..e3dea31bf 100644
--- a/src/services/api/graphql/utils/util.py
+++ b/src/services/api/graphql/utils/util.py
@@ -39,3 +39,17 @@ def is_show_function_name(name):
if re.match(r"^show", name):
return True
return False
+
+def _nth_rsplit(delim: str, n: int, s: str):
+ groups = s.split(delim)
+ l = len(groups)
+ if n > l-1:
+ return ('', s)
+ return (delim.join(groups[:l-n]), delim.join(groups[l-n:]))
+
+def split_compound_op_mode_name(name: str, files: list):
+ for i in range(1, name.count('_') + 1):
+ pair = _nth_rsplit('_', i, name)
+ if pair[1] in files:
+ return pair
+ return (name, '')