<s> import re <EOL> import sys , csv <EOL> import MySQLdb <EOL> def commit_changes ( db , cursor , sql ) : <EOL> try : <EOL> for q in sql : <EOL> cursor . execute ( q ) <EOL> db . commit ( ) <EOL> except MySQLdb . Error , e : <EOL> handle_error ( db , e ) <EOL> def handle_error ( db , e ) : <EOL> if e [ <NUM_LIT:0> ] == <NUM_LIT> : <EOL> pass <EOL> else : <EOL> db . rollback ( ) <EOL> sys . stderr . write ( str ( e ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def check_contributor_id ( id ) : <EOL> regexp = re . compile ( "<STR_LIT>" ) <EOL> match = regexp . match ( id ) <EOL> try : <EOL> match . group ( ) <EOL> except : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def check_recipient_id ( id ) : <EOL> regexp = re . compile ( "<STR_LIT>" ) <EOL> match = regexp . match ( id ) <EOL> try : <EOL> match . group ( ) <EOL> except : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def usage ( ) : <EOL> sys . stderr . write ( """<STR_LIT>""" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) == <NUM_LIT:3> : <EOL> db = MySQLdb . connect ( host = "<STR_LIT:localhost>" , port = <NUM_LIT> , user = "<STR_LIT:root>" , passwd = "<STR_LIT>" , db = sys . argv [ <NUM_LIT:2> ] ) <EOL> if sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> import overall <EOL> overall . main ( db ) <EOL> elif sys . argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> import groupedbycycle <EOL> groupedbycycle . main ( db ) <EOL> else : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
