1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/env python
'''
Example showing reading debug info from a pipe.
'''
import sys
import Queue
from optparse import OptionParser
from pynorm.extra.pipeparser import PipeParser
USAGE = 'usage: %s [options]' % sys.argv[0]
DEFAULT_PIPE = 'normtest'
def get_option_parser():
parser = OptionParser(usage=USAGE)
parser.set_defaults(pipe=DEFAULT_PIPE)
parser.add_option('-p', '--pipe',
help='The pipe to connect to (default %s)' % DEFAULT_PIPE)
return parser
def main(argv):
(opts, args) = get_option_parser().parse_args(argv)
if len(args) != 1:
print USAGE
return 1
pipep = PipeParser(opts.pipe)
pipep.start()
while True:
try:
report = pipep.reports.get(True, 3)
except Queue.Empty:
continue
try:
print report['time'], report['remote'][0]['fec_cur']
except IndexError:
pass
pipep.reports.task_done()
if __name__ == '__main__':
sys.exit(main(sys.argv))
|