---
+++
@@ -5,8 +5,6 @@
import gui
from optparse import OptionParser
from copy import copy
-
-opt = None
class FactorizedLine:
def __init__(s, parent = None):
@@ -173,11 +171,13 @@
return False
class LogLine:
- def __init__(s, txt):
+ def __init__(s, txt, opt):
+ #print "skipp", opt.skipped_fields
s.full_line = txt.strip('\r\n')
s.words = [Word(a.strip('\r\n')) for a in txt.split()]
s.date = [a.word for a in s.words[0:int(opt.skipped_fields)]]
s.words = s.words[int(opt.skipped_fields):]
+
class Word:
def __init__(s, word):
@@ -192,33 +192,37 @@
return True
class Log:
- def __init__(s, file):
+ def __init__(s, file, opt):
s.f = open(file, 'r')
s.tree = FactorizedLine()
s.line_count = 0
+ s.opt = opt
s.lines = []
while 1:
line = s.f.readline()
if not line:
break
- line = LogLine(line)
+ line = LogLine(line, s.opt)
s.tree.add_line(line)
s.line_count += 1
s.lines.append(line)
-
+
s.tree.build()
if __name__ == "__main__":
- filename = sys.argv[-1]
- sys.argv = sys.argv[:len(sys.argv) - 2]
-
- opt_parser = OptionParser()
- opt_parser.add_option("-s", "--skip", help="skip the first X field of each line",
+ opt_parser = OptionParser(usage="usage: %prog [options] file_to_view")
+ opt_parser.add_option("-s", "--skip", help="skip the first X fields of each line",
dest="skipped_fields", metavar="X")
(opt, args) = opt_parser.parse_args()
if opt.skipped_fields is None:
- opt.skipped_fields = "3"
- log = Log(filename)
+ opt.skipped_fields = 3
+ else:
+ opt.skipped_fields = int(opt.skipped_fields)
+
+ if len(args) == 0:
+ opt_parser.print_help()
+ exit(1)
+ log = Log(args[0], opt)
gui.start(log, opt)
Generated with KisssPM