Skip to content

Commit bb772ee

Browse files
committed
osmo_interact: improve vty transcript language by a regular rexex
Currently the transcript language understand 3 different tokens: ... (ignore all lines until the following line matches) ... !REGEX (ignore all lines except REXEX) But to support osmo-stp with different compile options, the vty help is indented with different amount of spaces depending on the compile options. To support those add a regular regex using the prefix !r! E.g. ``` OsmoSTP(config-cs7-as)# ? - description Save human-readable description of the object vs + description Save human-readable description of the object ``` To use the new regex, the line would be: ``` !r! description[ ]+Save human-readable description of the object ``` Further all regex special characters needs to be escaped. ``` description Save human-readable description of the object (for humans) !r! description[ ]+Save human-readable description of the object \(for humans\) ``` Change-Id: Iadcd7a8c3677548a6405e098fe53d0614ef2012c
1 parent 5d0fac9 commit bb772ee

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

osmopy/osmo_interact/common.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,28 @@ def match_lines(expect, got):
218218
- If an 'expect' line is '... !regex', it matches any number of
219219
lines like '...', but the given regex must not match any of those
220220
lines.
221+
- If the line starts with '!r!' following the regex, but a exact
222+
match has priority
221223
222224
Return 'True' on match, or a string describing the mismatch.
223225
'''
224-
def match_line(expect_line, got_line):
225-
return expect_line == got_line
226226

227227
ANY = '...'
228228
ANY_EXCEPT = '... !'
229+
REGEX = '!r!'
230+
231+
def match_line(expect_line, got_line):
232+
if expect_line == got_line:
233+
return True
234+
235+
# try to parse the expect_line as regex
236+
if expect_line.startswith(REGEX):
237+
try:
238+
if re.compile(expect_line[len(REGEX):]).match(got_line):
239+
return True
240+
except:
241+
pass
242+
return False
229243

230244
e = 0
231245
g = 0

0 commit comments

Comments
 (0)