summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/python/retrace/parser.py
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-03-25 13:31:27 +0000
committerJosé Fonseca <jfonseca@vmware.com>2009-03-25 21:03:38 +0000
commit9d97c3d0be9e57226b6a438a90b71f36e0c99269 (patch)
treeb0023db3bf31587f16314062c37eaf4390b0281a /src/gallium/state_trackers/python/retrace/parser.py
parent5743483778ffe5b389d10b1651ae1e8951b397ee (diff)
python/trace: Control the interpreter from command line options.
Diffstat (limited to 'src/gallium/state_trackers/python/retrace/parser.py')
-rwxr-xr-xsrc/gallium/state_trackers/python/retrace/parser.py40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/gallium/state_trackers/python/retrace/parser.py b/src/gallium/state_trackers/python/retrace/parser.py
index 5205f2d8dd..db9bcc8226 100755
--- a/src/gallium/state_trackers/python/retrace/parser.py
+++ b/src/gallium/state_trackers/python/retrace/parser.py
@@ -30,6 +30,7 @@
import sys
import xml.parsers.expat
import binascii
+import optparse
from model import *
@@ -342,16 +343,39 @@ class TraceDumper(TraceParser):
self.formatter.newline()
-def main(ParserFactory):
- for arg in sys.argv[1:]:
- if arg.endswith('.gz'):
- import gzip
- stream = gzip.GzipFile(arg, 'rt')
+class Main:
+ '''Common main class for all retrace command line utilities.'''
+
+ def __init__(self):
+ pass
+
+ def main(self):
+ optparser = self.get_optparser()
+ (options, args) = optparser.parse_args(sys.argv[1:])
+
+ if args:
+ for arg in args:
+ if arg.endswith('.gz'):
+ from gzip import GzipFile
+ stream = GzipFile(arg, 'rt')
+ elif arg.endswith('.bz2'):
+ from bz2 import BZ2File
+ stream = BZ2File(arg, 'rt')
+ else:
+ stream = open(arg, 'rt')
+ self.process_arg(stream, options)
else:
- stream = open(arg, 'rt')
- parser = ParserFactory(stream)
+ self.process_arg(stream, options)
+
+ def get_optparser(self):
+ optparser = optparse.OptionParser(
+ usage="\n\t%prog [options] [traces] ...")
+ return optparser
+
+ def process_arg(self, stream, options):
+ parser = TraceDumper(stream)
parser.parse()
if __name__ == '__main__':
- main(TraceDumper)
+ Main().main()