block = PlogBlock('Device ID:', ref='Device') block.header.ref = 'device_id' block.footer = PlogLine('----------', ref='footer').anything() lines = {} lines['entry_address'] = PlogLine('IP address:') lines['platform'] = PlogLine('Platform:') lines['interface'] = PlogLine('Interface:') lines['hold_time'] = PlogLine('Holdtime').maybe(' ').then(':') lines['version'] = PlogLine('Version').maybe(' ').then(':').multiline() lines['version'] = PlogLine('advertisement version:') lines['duplex'] = PlogLine('Duplex:') lines['power_drawn'] = PlogLine('Power drawn:') lines['power_request_id'] = PlogLine('Power request id:') lines['power_management_id'] = PlogLine('Power management id:') lines['power_request_levels'] = PlogLine('Power request levels are:') block.add_lines(**lines) # new parser f = open('test_data2.txt', 'r') # plog = Plog(f, whitespace='|') plog = Plog(f, whitespace='|', terminator=',') # run it plog.add_block(block) blocks = plog.run() for block in blocks: if block.valid(): print block.as_dict()
# block = PlogBlock('Device ID:', ref='Device') block.header.ref='device_id' block.footer = PlogLine('----------', ref='footer').anything() lines = {} lines['entry_address'] = PlogLine('IP address:') lines['platform'] = PlogLine('Platform:') lines['interface'] = PlogLine('Interface:') lines['hold_time'] = PlogLine('Holdtime').maybe(' ').then(':') lines['version'] = PlogLine('Version').maybe(' ').then(':').multiline() lines['ad_version'] = PlogLine('advertisement version:') block.add_lines(**lines) # new parser f = open('test_data2.txt', 'r') plog = Plog(f, whitespace='|') # run it plog.add_block(block) blocks = plog.run() for block in blocks: if block.valid(): print block.as_dict()
from api import Plog from patterns import PlogLine as Line, PlogBlock as Block block = Block('Device ID:', ref='Device') block.header.ref='device_id' block.add_lines( entry_address=Line('IP address:'), platform=Line('Platform:'), interface=Line('Interface:'), hold_time=Line('Holdtime').maybe(' ').then(':'), version=Line('Version').maybe(' ').then(':').multiline(), ad_version=Line('advertisement version:'), duplex=Line('Duplex:'), power_drawn=Line('Power drawn:'), power_request_id=Line('Power request id:'), power_management_id=Line('Power management id:'), power_request_levels=Line('Power request levels are:'), ) block.footer = Line('----------', ref='footer').anything() # new parser f = open('test_data2.txt', 'r') # plog = Plog(f, whitespace='|') plog = Plog(f, whitespace='|', terminator=',') # run it plog.add_block(block)
from api import Plog from patterns import PlogLine, PlogBlock f = open('test_data2.txt', 'r') # Capture something block = PlogBlock('Device ID:', ref='Device') block.header.ref = 'device_id' block.footer = PlogLine('----------', ref='footer').anything() ip_address = PlogLine('IP address:') block.add_lines(ip=ip_address) # new parser plog = Plog(f, whitespace='|') # run it plog.add_block(block) blocks = plog.run() for block in blocks: if block.valid(): print block.as_dict()
from api import Plog from patterns import PlogLine, PlogBlock f = open('test_data2.txt', 'r') # Capture something block = PlogBlock('Device ID:', ref='Device') block.header.ref='device_id' block.footer = PlogLine('----------', ref='footer').anything() ip_address = PlogLine('IP address:') block.add_lines(ip=ip_address) # new parser plog = Plog(f, whitespace='|') # run it plog.add_block(block) blocks = plog.run() for block in blocks: if block.valid(): print block.as_dict()