diff options
author | John Estabrook <jestabro@vyos.io> | 2022-07-24 15:36:18 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2022-07-25 15:47:11 -0500 |
commit | fa8dcff5d2e18ded5310d3f86ea0dc1bf2795af8 (patch) | |
tree | 8429207b5386557b83007ba71fae9b874042840b /src/services/api/graphql/utils | |
parent | 423485a0b87a650c74dd490a1335af969ef83237 (diff) | |
download | vyos-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')
-rw-r--r-- | src/services/api/graphql/utils/util.py | 14 |
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, '') |