Package londiste :: Module file_read
[frames] | no frames]

Source Code for Module londiste.file_read

 1   
 2  """Reads events from file instead of db queue.""" 
 3   
 4  import sys, os, re, skytools 
 5   
 6  from playback import * 
 7  from table_copy import * 
 8   
 9  __all__ = ['FileRead'] 
10   
11  file_regex = r"^tick_0*([0-9]+)\.sql$" 
12  file_rc = re.compile(file_regex) 
13   
14   
15 -class FileRead(CopyTable):
16 """Reads events from file instead of db queue. 17 18 Incomplete implementation. 19 """ 20
21 - def __init__(self, args, log = None):
22 CopyTable.__init__(self, args, log, copy_thread = 0)
23
24 - def launch_copy(self, tbl):
25 # copy immidiately 26 self.do_copy(t)
27
28 - def work(self):
29 last_batch = self.get_last_batch(curs) 30 list = self.get_file_list()
31
32 - def get_list(self):
33 """Return list of (first_batch, full_filename) pairs.""" 34 35 src_dir = self.cf.get('file_src') 36 list = os.listdir(src_dir) 37 list.sort() 38 res = [] 39 for fn in list: 40 m = file_rc.match(fn) 41 if not m: 42 self.log.debug("Ignoring file: %s" % fn) 43 continue 44 full = os.path.join(src_dir, fn) 45 batch_id = int(m.group(1)) 46 res.append((batch_id, full)) 47 return res
48 49 if __name__ == '__main__': 50 script = Replicator(sys.argv[1:]) 51 script.start() 52