/usr/share/pyshared/londiste/file_write.py is in skytools 2.1.12-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """Writes events into file."""
import sys, os, skytools
from cStringIO import StringIO
from playback import *
__all__ = ['FileWrite']
class FileWrite(Replicator):
"""Writes events into file.
Incomplete implementation.
"""
last_successful_batch = None
def load_state(self, batch_id):
# maybe check if batch exists on filesystem?
self.cur_tick = self.cur_batch_info['tick_id']
self.prev_tick = self.cur_batch_info['prev_tick_id']
return 1
def process_batch(self, db, batch_id, ev_list):
pass
def save_state(self, do_commit):
# nothing to save
pass
def sync_tables(self, dst_db):
# nothing to sync
return 1
def interesting(self, ev):
# wants all of them
return 1
def handle_data_event(self, ev):
fmt = self.sql_command[ev.type]
sql = fmt % (ev.ev_extra1, ev.data)
row = "%s -- txid:%d" % (sql, ev.txid)
self.sql_list.append(row)
ev.tag_done()
def handle_system_event(self, ev):
row = "-- sysevent:%s txid:%d data:%s" % (
ev.type, ev.txid, ev.data)
self.sql_list.append(row)
ev.tag_done()
def flush_sql(self):
self.sql_list.insert(0, "-- tick:%d prev:%s" % (
self.cur_tick, self.prev_tick))
self.sql_list.append("-- end_tick:%d\n" % self.cur_tick)
# store result
dir = self.cf.get("file_dst")
fn = os.path.join(dir, "tick_%010d.sql" % self.cur_tick)
f = open(fn, "w")
buf = "\n".join(self.sql_list)
f.write(buf)
f.close()
if __name__ == '__main__':
script = Replicator(sys.argv[1:])
script.start()
|