I am working on a Python script to interact with the Node. I am using pexpect module to spawn a connection and interact with the node.
I am facing issue with the expect parameters which is getting the response with some color codes. How can we match the pattern without color codes?
Here I am pasting the code snippet
import pexpect
import re
import pdb
prompt1= "Parameter\s+1\s+of\s+3,\s+restartRank\s+\(enumRef-ReqFieldReplaceableUnit.RestartRank\):\s+Enter\s+one\s+of\s+the\s+following\s+integers:\s+0:RESTART_WARM,\s+1:RESTART_COLD,\s+2:RESTART_COLDWTEST:"
expectprompts = [failPrmt, prompt1,pexpect.TIMEOUT, pexpect.EOF]
i = childconn.expect(expectprompts, timeout=tmOut)
output received from the Node
PROMPT RECEIVED FROM THE NODE ======>>>> : <class 'pexpect.exceptions.TIMEOUT'>
Timeout / EOF Occured !!!!!!!!!!!!!!!!!!!!!!!!!!
Expect Result : ? y^M
^M
=================================================================================================================^M
Proxy MO Action Nr of Params^M
=================================================================================================================^M
4205 FieldReplaceableUnit=RRU-B1-B3-3 restartUnit 3^M
^M
Parameter 1 of 3, restartRank (enumRef-ReqFieldReplaceableUnit.RestartRank): ^M
Enter one of the following integers: 0:RESTART_WARM, 1:RESTART_COLD, 2:RESTART^MT_COLDWTEST:
2021-09-02 12:04:47,097 | wessdpprodapp10 | 73543 |INFO | Expect Result after sending ctrl-y: ? y^M
^M
=================================================================================================================^M
Proxy MO Action Nr of Params^M
=================================================================================================================^M
4205 FieldReplaceableUnit=RRU-B1-B3-3 restartUnit 3^M
^M
Parameter 1 of 3, restartRank (enumRef-ReqFieldReplaceableUnit.RestartRank): ^M
Enter one of the following integers: 0:RESTART_WARM, 1:RESTART_COLD, 2:RESTART^MT_COLDWTEST:
It is not able to match the pattern as there are color codes available in between the expected output. Is there a way to match the pattern by ignoring color code in the pattern match of Pexpect Module?
In this scenario, it is not possible the receive the response and then match the pattern with other regex sources. Please guide me if there is a way to ignore ansi color codes within pexpect module.
Thanks in advance