-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompleter_generator.py
33 lines (26 loc) · 1.06 KB
/
completer_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import json
from prompt_toolkit.completion import NestedCompleter
from settings import CONFIG_DIR, nested_dict_base
def get_sub_node_set():
if not os.path.exists(CONFIG_DIR+'groups.json') or not os.path.exists(CONFIG_DIR+'connections.json'):
return None
with open(CONFIG_DIR+'groups.json') as f:
groups_info = json.load(f)
with open(CONFIG_DIR+'connections.json', encoding='utf-8') as f:
conn = json.load(f)
res = {}
for item in groups_info:
sub_name = groups_info[item]['displayName'].replace(' ', '%20')
connections = [conn[i]['displayName'].replace(' ', '%20')
for i in groups_info[item]['connections']]
res[sub_name] = set(connections)
return res
def generate_completer():
res = get_sub_node_set()
nested_dict_base['update'] = set(res.keys()) if res else None
nested_dict_base['connect'] = res
nested_dict_base['info'] = res
nested_dict_base['delete'] = res
completer = NestedCompleter.from_nested_dict(nested_dict_base)
return completer