#! /usr/bin/env python
-
+#
+# This file is part of libFirm.
+# Copyright (C) 2012 Karlsruhe Institute of Technology.
import sys
import os
import re
self.execute('drop table if exists `%s`' % self.evtab)
self.execute('drop table if exists `%s`' % self.ctxtab)
- self.create_table(ctxcols, self.ctxtab, "text", "int auto_increment", extra = ", PRIMARY KEY (`id`)")
- self.create_table(evcols, self.evtab, "data", "int not null", extra = ", INDEX(`id`)")
+ self.create_table(ctxcols, self.ctxtab, "text", "int auto_increment", extra = ", PRIMARY KEY (`id`)")
+ self.create_table(evcols, self.evtab, "data", "int not null", extra = ", INDEX(`id`)")
keys = "id, " + ", ".join(evcols)
marks = ",".join(['%s'] * (len(evcols)+1))
- self.evinsert = "insert into `%s` values (%s)" % (self.evtab, marks)
+ self.evinsert = "insert into `%s` (%s) values (%s)" % (self.evtab, keys, marks)
keys = ", ".join(ctxcols)
marks = ",".join(['%s'] * len(ctxcols))
self.ctxtab = options.prefix + "ctx"
self.evtab = options.prefix + "ev"
- if not options.update:
- self.create_table(ctxcols, self.ctxtab, "text", "integer primary key")
- #self.execute("CREATE INDEX IF NOT EXISTS `%sindex` ON `%s`(id)"
- # % (self.ctxtab, self.ctxtab))
- self.create_table(evcols, self.evtab, "data", "int")
- self.execute("CREATE INDEX IF NOT EXISTS `%sindex` ON `%s`(id)"
- % (self.evtab, self.evtab))
+ self.create_table(ctxcols, self.ctxtab, "text", "integer primary key")
+ self.create_table(evcols, self.evtab, "data", "int")
+ self.execute("CREATE INDEX IF NOT EXISTS `%sindex` ON `%s`(id)"
+ % (self.evtab, self.evtab))
keys = "id, " + ", ".join(evcols)
marks = ",".join(["?"] * (len(evcols)+1))
evind = 0
ctxcols = dict()
evcols = dict()
+ ctxlist = []
+ evlist = []
linenr = 0
self.valid_keys = set()
key = fields[i]
if not ctxcols.has_key(key):
ctxcols[key] = ctxind
+ ctxlist.append(key)
ctxind += 1
elif fields[0] == 'E':
if not evcols.has_key(key):
self.valid_keys.add(key)
evcols[key] = evind
+ evlist.append(key)
evind += 1
self.ctxcols = ctxcols
self.evcols = evcols
- return (ctxcols, evcols)
+ return (ctxlist, evlist)
def input(self):
return fileinput.FileInput(files=self.files, openhook=fileinput.hook_compressed)
print '%10d / %10d' % (curr_event, self.n_events)
for p in range(1,len(items),2):
- key = items[p]
+ key = items[p]
if key not in self.evcols:
continue
if self.evvals[keyidx] != None:
self.flush_events(self.curr_id)
- value = items[p+1]
+ value = items[p+1]
self.evvals[keyidx] = value
def __init__(self):
- parser = optparse.OptionParser('usage: %prog [options] <event file...>')
- parser.add_option("", "--update", dest="update", help="update database instead of dropping all existing values", action="store_true", default=False)
+ parser = optparse.OptionParser('usage: %prog [options] <event file...>', add_help_option=False)
+ parser.add_option("", "--help", help="show this help message and exit", action="help")
+ parser.add_option("", "--update", dest="update", help="update database instead of dropping all existing values", action="store_true", default=False)
parser.add_option("-v", "--verbose", dest="verbose", help="verbose messages", action="store_true", default=False)
parser.add_option("-f", "--filter", dest="filter", help="regexp to filter event keys", metavar="REGEXP")
parser.add_option("-u", "--user", dest="user", help="user", metavar="USER")
- parser.add_option("-H", "--host", dest="host", help="host", metavar="HOST")
+ parser.add_option("-h", "--host", dest="host", help="host", metavar="HOST")
parser.add_option("-p", "--password", dest="password", help="password", metavar="PASSWORD")
- parser.add_option("-d", "--db", dest="database", help="database", metavar="DB")
+ parser.add_option("-D", "--database", dest="database", help="database", metavar="DB")
parser.add_option("-e", "--engine", dest="engine", help="engine (sqlite3, mysql)", metavar="ENG", default='sqlite3')
parser.add_option("-P", "--prefix", dest="prefix", help="table prefix", metavar="PREFIX", default='')
(options, args) = parser.parse_args()