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 46 47 48 49 50 51 52 53 54 55
|
#!/usr/bin/python
#
# striplog -- strip leading lines from logs
#
# striplog -j strips JSON leader sentences.
# striplog with no option strips all leading lines beginning with #
#
# This file is Copyright (c) 2010 by the GPSD project
# BSD terms apply: see the file COPYING in the distribution root for details.
#
import getopt, sys
secondline = firstline = stripjson = False
stripval = 0
(options, arguments) = getopt.getopt(sys.argv[1:], "12n:j")
for (switch, val) in options:
if (switch == '-1'):
firstline = True
if (switch == '-2'):
secondline = True
if (switch == '-n'):
stripval = int(val)
if (switch == '-j'):
stripjson = True
try:
if firstline:
sys.stdin.readline()
elif secondline:
sys.stdin.readline()
sys.stdin.readline()
elif stripval:
for _dummy in range(stripval):
sys.stdin.readline()
elif stripjson:
while True:
line = sys.stdin.readline()
if line.startswith('{"class":"VERSION"') \
or line.startswith('{"class":"DEVICE"') \
or line.startswith('{"class":"DEVICES"') \
or line.startswith('{"class":"WATCH"'):
continue
else:
break
sys.stdout.write(line)
else:
while True:
line = sys.stdin.readline()
if line[0] != '#':
break
sys.stdout.write(line)
sys.stdout.write(sys.stdin.read())
except KeyboardInterrupt:
pass
|