1
2 """Writes events into file."""
3
4 import sys, os, skytools
5 from cStringIO import StringIO
6 from playback import *
7
8 __all__ = ['FileWrite']
9
11 """Writes events into file.
12
13 Incomplete implementation.
14 """
15
16 last_successful_batch = None
17
19
20 self.cur_tick = self.cur_batch_info['tick_id']
21 self.prev_tick = self.cur_batch_info['prev_tick_id']
22 return 1
23
26
30
34
38
40 fmt = self.sql_command[ev.type]
41 sql = fmt % (ev.ev_extra1, ev.data)
42 row = "%s -- txid:%d" % (sql, ev.txid)
43 self.sql_list.append(row)
44 ev.tag_done()
45
47 row = "-- sysevent:%s txid:%d data:%s" % (
48 ev.type, ev.txid, ev.data)
49 self.sql_list.append(row)
50 ev.tag_done()
51
53 self.sql_list.insert(0, "-- tick:%d prev:%s" % (
54 self.cur_tick, self.prev_tick))
55 self.sql_list.append("-- end_tick:%d\n" % self.cur_tick)
56
57 dir = self.cf.get("file_dst")
58 fn = os.path.join(dir, "tick_%010d.sql" % self.cur_tick)
59 f = open(fn, "w")
60 buf = "\n".join(self.sql_list)
61 f.write(buf)
62 f.close()
63
64 if __name__ == '__main__':
65 script = Replicator(sys.argv[1:])
66 script.start()
67