From fa8dcff5d2e18ded5310d3f86ea0dc1bf2795af8 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sun, 24 Jul 2022 15:36:18 -0500 Subject: graphql: T4554: add resolver support for op-mode scripts --- src/services/api/graphql/utils/util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/services/api/graphql/utils/util.py') 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, '') -- cgit v1.2.3