<s> import sys <EOL> import uuid <EOL> from mdf . remote import messaging <EOL> _fmt = "<STR_LIT>" <EOL> class ProgressBar ( object ) : <EOL> def __init__ ( self , start_date , end_date ) : <EOL> self . start_date = start_date <EOL> self . num_days = ( end_date - start_date ) . days <EOL> self . _date = start_date <EOL> self . prog_bar = '<STR_LIT>' <EOL> self . fill_char = '<STR_LIT:*>' <EOL> self . width = <NUM_LIT> <EOL> self . set_date ( self . start_date ) <EOL> self . _subj = uuid . uuid1 ( ) <EOL> messaging . register_message_handler ( self . _subj , self . __msg_callback ) <EOL> def __call__ ( self , date , ctx ) : <EOL> messaging . send_message ( self . _subj , date ) <EOL> def __del__ ( self ) : <EOL> try : <EOL> messaging . unregister_message_handler ( self . _subj , self . __msg_callback ) <EOL> except RuntimeError : <EOL> pass <EOL> def __msg_callback ( self , subject , date ) : <EOL> if date <= self . _date : <EOL> return <EOL> self . set_date ( date ) <EOL> sys . stdout . write ( "<STR_LIT:\r>" ) <EOL> sys . stdout . write ( str ( self ) ) <EOL> sys . stdout . flush ( ) <EOL> def set_date ( self , date ) : <EOL> done = float ( ( date - self . start_date ) . days ) <EOL> self . __update_amount ( ( done / self . num_days ) * <NUM_LIT> ) <EOL> self . prog_bar += '<STR_LIT>' % ( date . strftime ( _fmt ) , done , self . num_days ) <EOL> self . _date = date <EOL> def __update_amount ( self , new_amount ) : <EOL> percent_done = int ( round ( ( new_amount / <NUM_LIT> ) * <NUM_LIT> ) ) <EOL> all_full = self . width - <NUM_LIT:2> <EOL> num_hashes = int ( round ( ( percent_done / <NUM_LIT> ) * all_full ) ) <EOL> self . prog_bar = '<STR_LIT:[>' + self . fill_char * num_hashes + '<STR_LIT:U+0020>' * ( all_full - num_hashes ) + '<STR_LIT:]>' <EOL> pct_place = ( len ( self . prog_bar ) // <NUM_LIT:2> ) - len ( str ( percent_done ) ) <EOL> pct_string = '<STR_LIT>' % percent_done <EOL> self . prog_bar = self . prog_bar [ <NUM_LIT:0> : pct_place ] + ( pct_string + self . prog_bar [ pct_place + len ( pct_string ) : ] ) <EOL> def __str__ ( self ) : <EOL> return str ( self . prog_bar ) <EOL> def combine_result ( self , other , other_ctx , ctx ) : <EOL> self . set_date ( other_ctx . get_date ( ) ) </s>
