2014-07-10 58 views
3

我是新來pyparsing,需要幫助與下面的輸出從上述解析成一個字典對象轉換NetScaler的節目輸出到BNF解析

MONLB01> sh lb vserver montest_4567_VS2 
    montest_4567_VS2 (167.22.55.130:4567) - TCP Type: ADDRESS 
    State: DOWN 
    Effective State: DOWN 
    Client Idle Timeout: 9000 sec 
    Down state flush: ENABLED 
    Configured Method: ROUNDROBIN 
    Mode: IP 
    Persistence: NONE 
    Connection Failover: DISABLED 
1) montest_6248_S3 (177.24.41.3: 6248) - TCP State: DOWN  Weight: 1 
2) montest_6248_S4 (177.24.41.3: 6248) - TCP State: DOWN  Weight: 1 
    Done 

UPDATE

from pyparsing import \ 
    Literal, Word, ZeroOrMore, Group, Dict, Optional, \ 
    printables, ParseException, restOfLine 
    import pprint 


    inibnf = None 
    def inifile_BNF(): 
    <!!!!!Parsing Logic!!!Need Help here> 
    return inibnf 


pp = pprint.PrettyPrinter(2) 
def test(strng): 
    print strng 
    try: 
     iniFile = file(strng) 
     iniData = "".join(iniFile.readlines()) 
     bnf = inifile_BNF() 
     tokens = bnf.parseString(iniData) 
     pp.pprint(tokens.asList()) 

    except ParseException, err: 
     print err.line 
     print " "*(err.column-1) + "^" 
     print err 

iniFile.close() 
ini = test("netscalerout.txt") 

我需要使用pyparsing庫編寫解析邏輯

+0

你到現在爲止做了什麼..你已經實現了什麼代碼..SO不是現成解決方案的地方.. – Amistad

回答

2

我想通了,textFSM是最適合這個。