<s> """<STR_LIT>""" <EOL> import os . path <EOL> import re <EOL> import sqlite3 <EOL> from cvsgit . changeset import Change , ChangeSet <EOL> from cvsgit . i18n import _ <EOL> class MetaDb ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> self . filename = filename <EOL> self . _dbh = None <EOL> def get_dbh ( self ) : <EOL> if self . _dbh is None : <EOL> dbh = sqlite3 . connect ( self . filename ) <EOL> dbh . execute ( "<STR_LIT>" ) <EOL> dbh . execute ( "<STR_LIT>" ) <EOL> dbh . execute ( "<STR_LIT>" ) <EOL> sql = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> dbh . execute ( sql ) <EOL> sql = '<STR_LIT>' '<STR_LIT>' <EOL> dbh . execute ( sql ) <EOL> dbh . execute ( """<STR_LIT>""" ) <EOL> sql = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> dbh . execute ( sql ) <EOL> sql = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> dbh . execute ( sql ) <EOL> dbh . execute ( """<STR_LIT>""" ) <EOL> self . _dbh = dbh <EOL> return self . _dbh <EOL> dbh = property ( get_dbh ) <EOL> def load_statcache ( self ) : <EOL> """<STR_LIT>""" <EOL> sql = '<STR_LIT>' <EOL> statcache = { } <EOL> for row in self . dbh . execute ( sql ) : <EOL> statcache [ row [ <NUM_LIT:0> ] ] = row [ <NUM_LIT:1> : ] <EOL> return statcache <EOL> def update_statcache ( self , statcache ) : <EOL> """<STR_LIT>""" <EOL> sql = '<STR_LIT>' '<STR_LIT>' <EOL> for path in statcache . keys ( ) : <EOL> values = ( path , ) + statcache [ path ] <EOL> self . dbh . execute ( sql , values ) <EOL> def add_change ( self , change ) : <EOL> """<STR_LIT>""" <EOL> self . dbh . execute ( """<STR_LIT>""" , <EOL> ( change . timestamp , change . author , change . log , <EOL> change . filestatus , change . filename , change . revision , <EOL> change . state , change . mode , ) ) <EOL> def add_changeset ( self , changeset ) : <EOL> """<STR_LIT>""" <EOL> id = self . dbh . execute ( """<STR_LIT>""" , ( changeset . start_time , changeset . end_time , ) ) . lastrowid <EOL> try : <EOL> self . dbh . executemany ( """<STR_LIT>""" % id , map ( lambda c : ( c . filename , c . revision ) , <EOL> changeset . changes ) ) <EOL> except : <EOL> self . dbh . execute ( """<STR_LIT>""" % id ) <EOL> raise <EOL> def mark_changeset ( self , id , mark ) : <EOL> """<STR_LIT>""" <EOL> assert ( id != None ) <EOL> sql = '<STR_LIT>' <EOL> self . dbh . execute ( sql , ( mark , id , ) ) <EOL> self . dbh . commit ( ) <EOL> def begin_transaction ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dbh . execute ( '<STR_LIT>' ) <EOL> def commit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dbh . commit ( ) <EOL> def end_transaction ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dbh . execute ( '<STR_LIT>' ) <EOL> def count_changes ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . dbh . execute ( """<STR_LIT>""" ) . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def changes_by_timestamp ( self , processed = None , reentrant = True ) : <EOL> """<STR_LIT>""" <EOL> if processed == True : <EOL> where = '<STR_LIT>' <EOL> elif processed == False : <EOL> where = '<STR_LIT>' <EOL> else : <EOL> where = '<STR_LIT:1>' <EOL> def mkchange ( row ) : <EOL> return Change ( timestamp = row [ <NUM_LIT:0> ] , author = row [ <NUM_LIT:1> ] , log = row [ <NUM_LIT:2> ] , <EOL> filestatus = row [ <NUM_LIT:3> ] , filename = row [ <NUM_LIT:4> ] , <EOL> revision = row [ <NUM_LIT:5> ] , state = row [ <NUM_LIT:6> ] , mode = row [ <NUM_LIT:7> ] ) <EOL> if not reentrant : <EOL> for row in self . dbh . execute ( """<STR_LIT>""" % where ) : <EOL> yield ( mkchange ( row ) ) <EOL> return <EOL> self . dbh . execute ( """<STR_LIT>""" ) <EOL> self . dbh . execute ( """<STR_LIT>""" ) <EOL> self . dbh . execute ( """<STR_LIT>""" ) <EOL> self . dbh . execute ( """<STR_LIT>""" % where ) <EOL> try : <EOL> while True : <EOL> rows = self . dbh . execute ( """<STR_LIT>""" ) . fetchall ( ) <EOL> if len ( rows ) == <NUM_LIT:0> : <EOL> break <EOL> for row in rows : <EOL> change = mkchange ( row ) <EOL> yield ( change ) <EOL> self . dbh . execute ( """<STR_LIT>""" , <EOL> ( change . filename , change . revision , ) ) <EOL> finally : <EOL> self . dbh . execute ( '<STR_LIT>' ) <EOL> def count_changesets ( self ) : <EOL> """<STR_LIT>""" <EOL> sql = '<STR_LIT>' <EOL> return self . dbh . execute ( sql ) . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def _select_changesets ( self , where ) : <EOL> where = where % { '<STR_LIT>' : '<STR_LIT>' } <EOL> sql = """<STR_LIT>""" % where <EOL> changeset = None <EOL> for row in self . dbh . execute ( sql ) : <EOL> change = Change ( timestamp = row [ <NUM_LIT:3> ] , <EOL> author = row [ <NUM_LIT:4> ] , <EOL> log = row [ <NUM_LIT:5> ] , <EOL> filestatus = row [ <NUM_LIT:6> ] , <EOL> filename = row [ <NUM_LIT:7> ] , <EOL> revision = row [ <NUM_LIT:8> ] , <EOL> state = row [ <NUM_LIT:9> ] , <EOL> mode = row [ <NUM_LIT:10> ] ) <EOL> if changeset is None or changeset . id != row [ <NUM_LIT:0> ] : <EOL> if changeset : <EOL> yield ( changeset ) <EOL> changeset = ChangeSet ( change , id = row [ <NUM_LIT:0> ] ) <EOL> changeset . provider = self <EOL> changeset . start_time = row [ <NUM_LIT:1> ] <EOL> changeset . end_time = row [ <NUM_LIT:2> ] <EOL> else : <EOL> changeset . changes . append ( change ) <EOL> if changeset : <EOL> yield ( changeset ) <EOL> def head_changeset ( self ) : <EOL> """<STR_LIT>""" <EOL> where = '<STR_LIT>' <EOL> for cs in self . _select_changesets ( where ) : <EOL> return cs <EOL> def changesets_by_start_time ( self ) : <EOL> """<STR_LIT>""" <EOL> where = '<STR_LIT>' <EOL> return self . _select_changesets ( where ) <EOL> def all_authors ( self ) : <EOL> """<STR_LIT>""" <EOL> return map ( lambda row : row [ <NUM_LIT:0> ] , self . dbh . execute ( """<STR_LIT>""" ) . fetchall ( ) ) </s>
