8 from optparse import OptionParser
10 def ev_create_stmt(heads):
11 create = 'create table if not exists ev (id int, time int, timeev int'
13 create += (', %s real' % (x,))
17 def ctx_create_stmt(heads):
18 create = 'create table if not exists ctx (id int unique on conflict ignore'
20 create += (', %s text' % (x,))
27 for line in fileinput.input(file):
28 items = re.split('\s+', line)
30 ev_heads.add(items[2])
32 ctx_heads.add(items[2])
33 return (ev_heads, ctx_heads)
35 def fill_tables(file):
38 for line in fileinput.input(file):
39 items = re.split('\s+', line)
47 stmt = 'insert into ctx (id'
50 stmt += ') values (' + str(int(id, 16))
52 stmt += ', \'' + x + '\''
63 t = (id, val, time, timeev)
64 stmt = 'insert into ev (id, %s, time, timeev) values (%d, %s, %s, %s);' % (key, int(id, 16), val, time, timeev)
71 parser = OptionParser('usage: %prog [options] input')
72 parser.add_option("-c", "--create", action="store_true")
73 (options, args) = parser.parse_args()
81 if not os.path.isfile(file):
82 print "cannot find input file %s" % (file, )
85 (ev_heads, ctx_heads) = find_heads(file)
88 print ev_create_stmt(ev_heads)
89 print ctx_create_stmt(ctx_heads)
92 print 'begin transaction;'
97 if __name__ == "__main__":