irgendwie scheine ich auf dem Schlauch zu stehen. Ich habe folgenden Code für SimpleParse erstellt. Ich habe erst damit angefangen. Der Dispatcher ist noch ganz am Beginn. Eigentlich müsste es also Fehlermeldungen hageln. Der Code liefert aber nur eine leere Liste. Was habe ich vergessen?
Code: Alles auswählen
from simpleparse.parser import Parser
from simpleparse.dispatchprocessor import *
from simpleparse.common import numbers
import pprint
# #############################################################################
class LMProcessor(DispatchProcessor):
int_unsigned = numbers.IntInterpreter()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def __init__(self):
self.feature = {}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def flex_code(self, (tag, left, right, sublist), buffer):
dcode = dispatchList(self, sublist, buffer)
return self.feature
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def feat_summary(self, (tag, left, right, sublist), buffer):
dcode = dispatchList(self, sublist, buffer)
return self.feature
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def tok_sum(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def feat_line(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def lic_typ(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def tok_usage(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def user(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def srv_name(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def other_info(self, (tag, left, right, sublist), buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def out1(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def version(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def srv_prt_hndl(self, tagl, buffer):
return dispatchList(self, sublist, buffer)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def date(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def port(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def handle(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def feature(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def tok_total(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def tok_inuse(self, tagl, buffer):
return str(getString(tagl, buffer))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def tok_num(self, tagl, buffer):
return str(getString(tagl, buffer))
declaration = r''' # grammar for lmstat-code
flexlm_file := flex_code
flex_code := feat_summary+
feat_summary := tok_sum, feat_line?, lic_typ?, tok_usage*
tok_sum := "Users of", ST, feature, ":", ST, "(Total of", ST, tok_total, ST, "licenses issued; Total of", ST, tok_inuse, ST, "licenses in use)", ST, NEWLINE
feat_line := ST, '"', feature, '"', ST, other_info, NEWLINE
lic_typ := ST, typ, ST, "license", ST, NEWLINE
tok_usage := user, ST, srv_name, ST, out1, ST, version, ST, srv_prt_hndl, KOMMA, ST, "start", ST, date, KOMMA, ST, tok_num, ST, "licenses", ST, NEWLINE
user := int_unsigned
srv_name := [a-zA-Z0-9.-]+
other_info := -[\n]*
out1 := [a-zA-Z/]
version := "(v", int_unsigned, ".", int_unsigned, ")"
srv_prt_hndl := "(", srv_name, "/", port, ST, handle, ")"
date := [a-zA-Z/:]
port := int_unsigned
handle := int_unsigned
feature := [a-zA-Z], [a-zA-Z0-9_]*
tok_total := int_unsigned
tok_inuse := int_unsigned
tok_num := int_unsigned
typ := [a-zA-Z]*
<KOMMA> := ","
<ST> := " \t"*
<NEWLINE> := "\n"+
'''
flm_code = """Users of feature_1: (Total of 37 licenses issued; Total of 37 licenses in use)
"feature_1" v61.9, vendor: AnythingLM, expiry: 23-apr-2018
floating license
103605 cae-srv-01 /dev/tty (v61.9) (liv-srv-6/27009 925), start Fri 4/6 21:21, 18 licenses
107994 cae-srv-02 /dev/tty (v61.9) (liv-srv-6/27009 814), start Fri 4/6 21:42, 19 licenses
Users of feature_2: (Total of 65536 licenses issued; Total of 24 licenses in use)
"feature_2" v61.9, vendor: AnythingLM, expiry: 23-apr-2018
floating license
103605 cae-srv-01 /dev/tty (v61.7) (liv-srv-6/27009 581), start Fri 4/6 21:21, 24 licenses
Users of feature_3: (Total of 37 licenses issued; Total of 37 licenses in use)
"feature_3" v61.9, vendor: AnythingLM, expiry: 23-apr-2018
floating license
103605 cae-srv-01 /dev/tty (v61.7) (liv-srv-6/27009 789), start Fri 4/6 21:21, 18 licenses
107994 cae-srv-02 /dev/tty (v61.7) (liv-srv-6/27009 610), start Fri 4/6 21:42, 19 licenses
"""
# #############################################################################
if __name__ =="__main__":
my_proc = LMProcessor()
parser = Parser(declaration, "flexlm_file" )
success, results, next = parser.parse(flm_code, processor=my_proc)
print results
#pprint.pprint(results[0])
Vielen Dank im Voraus
Calo