Permalink
Browse files

accept filenames as arguments, including gzip files

  • Loading branch information...
1 parent 4245092 commit 93b6d70c41176d2d2e4c63d921fbcb7f0c6216cb @indygreg indygreg committed Sep 21, 2011
Showing with 27 additions and 3 deletions.
  1. +27 −3 parse_crashdata.py
View
30 parse_crashdata.py
@@ -47,8 +47,11 @@
from breakpad.crashdata import CrashDataParser
from optparse import OptionParser
+from os.path import exists
from sys import stdin
+import gzip
+
op = OptionParser()
op.add_option('--signature', '-s', dest='signature', default=None,
help='Filter crashes by those containing this string in signature')
@@ -58,15 +61,16 @@
(options, args) = op.parse_args()
+read_files = len(args) > 0
+
print_uuids = True
if options.print_versions:
print_uuids = False
version_counts = {}
-parser = CrashDataParser()
-for row in parser.parse_handle(stdin):
+def handle_row(row):
# filter stage
relevant = True
@@ -75,7 +79,7 @@
relevant = False
if not relevant:
- continue
+ return
# data collection
version = row.version
@@ -88,6 +92,26 @@
if print_uuids:
print row.uuid
+parser = CrashDataParser()
+if not read_files:
+ for row in parser.parse_handle(stdin):
+ handle_row(row)
+else:
+ for filename in args:
+ if not exists(filename):
+ print 'Specified file does not exist: %s' % filename
+ continue
+
+ # automagically perform gzip uncompression
+ if filename[-3:] == '.gz':
+ gz = gzip.open(filename, 'rb')
+ for row in parser.parse_handle(gz):
+ handle_row(row)
+
+ else:
+ for row in parser.parse_file(filename):
+ handle_row(row)
+
if options.print_versions:
keys = version_counts.keys()
keys.sort()

0 comments on commit 93b6d70

Please sign in to comment.