1
- from typing import List , Dict , Optional , Tuple , Set
2
- import pandas as pd
1
+ from typing import Dict , List , Optional , Set , Tuple
3
2
4
3
from nubia .internal import context
4
+
5
5
from suzieq .shared .context import SqContext
6
+ from suzieq .shared .utils import lru_cache , timed_lru_cache
6
7
from suzieq .sqobjects import get_sqobject , get_tables
7
- from suzieq .shared .utils import timed_lru_cache , lru_cache
8
-
9
8
10
9
virt_tbl_cmd_mapping : Dict [str , str ] = {
11
10
'endpoint' : 'device' ,
15
14
'route' : 'routes' ,
16
15
'mac' : 'macs' ,
17
16
'interface' : 'interfaces' ,
18
- 'assert' : 'device' , # only for namespace/hostname
19
- 'query' : 'device' , # only for namespace/hostname
20
17
}
21
18
22
19
@@ -39,11 +36,7 @@ def completion_get_data(cmd: str, column: str,
39
36
if isinstance (v , tuple ):
40
37
kwargs [k ] = list (v )
41
38
42
- if cmd in ["assert" , "query" ]:
43
- df = get_sqobject (cmd )(context = ctxt ).get (columns = [column ], ** kwargs )
44
- if not df .empty and 'error' not in df .columns :
45
- result = set (df [column ].unique ())
46
- elif cmd == "extdb" :
39
+ if cmd == "extdb" :
47
40
result = set ()
48
41
# TODO: implement autocompletion with external tables
49
42
# ext_table = kwargs.pop('ext_table', None)
@@ -56,33 +49,8 @@ def completion_get_data(cmd: str, column: str,
56
49
return result
57
50
58
51
59
- @timed_lru_cache (60 )
60
- def get_assert_query_completions (cmd : str , column : str ,
61
- ** kwargs ) -> pd .DataFrame :
62
- '''Get completion for assert/query which return a dict'''
63
-
64
- nubia_ctxt = context .get_context ()
65
- if not nubia_ctxt :
66
- return pd .DataFrame ({column : []})
67
-
68
- ctxt : SqContext = nubia_ctxt .ctxt
69
-
70
- # kwargs are passed with values as tuples, not lists which
71
- # causes a bunch of problems in asserts. So, convert tuples
72
- # to lists again
73
- for k , v in kwargs .items ():
74
- if isinstance (v , tuple ):
75
- kwargs [k ] = list (v )
76
- try :
77
- df = get_sqobject (cmd )(context = ctxt ) \
78
- .get (columns = [column ], ** kwargs )
79
- return df
80
- except Exception :
81
- return pd .DataFrame ({column : []})
82
-
83
-
84
52
@lru_cache
85
- def completion_get_columns (cmd : str , component : Optional [str ] = None
53
+ def completion_get_columns (cmd : str , component : Optional [str ] = None ,
86
54
) -> List [str ]:
87
55
'''Return columns associated with a table for unique/top/assert'''
88
56
ctxt : SqContext = context .get_context ().ctxt
@@ -179,62 +147,6 @@ def hostname_completer(cmd: str, _subcmd: str, last_token: str,
179
147
return return_completions ('device' , 'hostname' , hostname_so_far , ** kwargs )
180
148
181
149
182
- def assert_name_completer (_cmd : str , _ : str ,
183
- last_token : str ,
184
- raw_cmd : str ) -> List [str ]:
185
- '''Return the completion for asserts'''
186
-
187
- asrt_so_far = None
188
-
189
- if isinstance (last_token , str ):
190
- asrt_so_far = last_token .split ('=' )[- 1 ]
191
-
192
- kwargs = get_kwargs_so_far (raw_cmd , ['workflow' ])
193
-
194
- return return_completions ('assert' , 'name' , asrt_so_far , ** kwargs )
195
-
196
-
197
- def assert_vars_name_completer (_cmd : str , _ : str ,
198
- last_token : str ,
199
- _raw_cmd : str ) -> List [str ]:
200
- """assert_vars completition"""
201
- vars_so_far = None
202
-
203
- if isinstance (last_token , str ):
204
- vars_so_far = last_token .split ('=' )[- 1 ]
205
-
206
- kwargs = {'assert_vars' : tuple (['*' ])}
207
-
208
- return return_completions ('assert' , 'name' , vars_so_far , ** kwargs )
209
-
210
-
211
- def query_vars_name_completer (_cmd : str , _ : str , last_token : str ,
212
- _raw_cmd : str ) -> List [str ]:
213
- """query_vars completitions"""
214
- vars_so_far : Optional [str ] = None
215
-
216
- if isinstance (last_token , str ):
217
- vars_so_far = last_token .split ('=' )[- 1 ]
218
-
219
- kwargs = {'query_vars' : tuple (['*' ])}
220
-
221
- return return_completions ('query' , 'name' , vars_so_far , ** kwargs )
222
-
223
-
224
- def workflow_name_completer (_cmd : str , _subcmd : str , last_token : str ,
225
- _raw_cmd : str ) -> List [str ]:
226
- '''Return the completion for workflows'''
227
-
228
- wf_so_far = None
229
-
230
- if isinstance (last_token , str ):
231
- wf_so_far = last_token .split ('=' )[- 1 ]
232
-
233
- kwargs = {'workflow' : tuple (['*' ])}
234
-
235
- return return_completions ('assert' , 'name' , wf_so_far , ** kwargs )
236
-
237
-
238
150
def column_name_completer (cmd : str , subcmd : str , last_token : str ,
239
151
raw_cmd : str ) -> List [str ]:
240
152
'''Return completions for column name'''
@@ -250,8 +162,7 @@ def column_name_completer(cmd: str, subcmd: str, last_token: str,
250
162
[None ])[0 ]
251
163
}
252
164
else :
253
- ext_table = get_kwargs_so_far (raw_cmd , ['table' ])
254
- kwargs = {'ext_table' : (ext_table .get ('table' , [None ]) or [None ])[0 ]}
165
+ kwargs = {}
255
166
256
167
if (subcmd in ['unique' , 'top' , 'assert' ]
257
168
and cmd not in ["endpoint" , "assert" ]):
@@ -291,7 +202,7 @@ def service_completer(_cmd: str, _subcmd: str, last_token: str,
291
202
292
203
svcs = set ({x for x in get_tables ()
293
204
if x not in ['path' , 'topology' , 'namespace' , 'endpoint' ,
294
- 'topcpu' , 'topmem' , 'assert' , 'query' ,
205
+ 'topcpu' , 'topmem' ,
295
206
'extdb' ]})
296
207
if svcs :
297
208
if svc_so_far :
0 commit comments