<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> import platform <EOL> import gc <EOL> from cvs2svn_lib import config <EOL> from cvs2svn_lib . common import FatalError <EOL> from cvs2svn_lib . context import Ctx <EOL> from cvs2svn_lib . log import logger <EOL> from cvs2svn_lib . stats_keeper import StatsKeeper <EOL> from cvs2svn_lib . stats_keeper import read_stats_keeper <EOL> from cvs2svn_lib . artifact_manager import artifact_manager <EOL> class InvalidPassError ( FatalError ) : <EOL> def __init__ ( self , msg ) : <EOL> FatalError . __init__ ( <EOL> self , msg + '<STR_LIT>' ) <EOL> class GarbageCollectionPolicy ( object ) : <EOL> """<STR_LIT>""" <EOL> def check_for_garbage ( self ) : <EOL> raise NotImplementedError ( ) <EOL> class DefaultGarbageCollectionPolicy ( GarbageCollectionPolicy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> logger . verbose ( <EOL> '<STR_LIT>' <EOL> ) <EOL> def check_for_garbage ( self ) : <EOL> pass <EOL> class NoGarbageCollectionPolicy ( GarbageCollectionPolicy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> logger . verbose ( '<STR_LIT>' ) <EOL> gc . disable ( ) <EOL> def check_for_garbage ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> gc . set_debug ( gc . DEBUG_SAVEALL ) <EOL> gc_count = gc . collect ( ) <EOL> if gc_count : <EOL> if logger . is_on ( logger . DEBUG ) : <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> % ( gc_count , ) <EOL> ) <EOL> for g in gc . garbage : <EOL> logger . debug ( '<STR_LIT>' % ( g , ) ) <EOL> del gc . garbage [ : ] <EOL> except ( AttributeError , NotImplementedError ) : <EOL> pass <EOL> def choose_garbage_collection_policy ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> implementation = platform . python_implementation ( ) <EOL> except AttributeError : <EOL> implementation = None <EOL> if implementation == '<STR_LIT>' : <EOL> return NoGarbageCollectionPolicy ( ) <EOL> else : <EOL> logger . verbose ( '<STR_LIT>' ) <EOL> return DefaultGarbageCollectionPolicy ( ) <EOL> class Pass ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . name = self . __class__ . __name__ <EOL> def register_artifacts ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def _register_temp_file ( self , basename ) : <EOL> """<STR_LIT>""" <EOL> artifact_manager . register_temp_file ( basename , self ) <EOL> def _register_temp_file_needed ( self , basename ) : <EOL> """<STR_LIT>""" <EOL> artifact_manager . register_temp_file_needed ( basename , self ) <EOL> def run ( self , run_options , stats_keeper ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class PassManager : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , passes ) : <EOL> """<STR_LIT>""" <EOL> self . passes = passes <EOL> self . num_passes = len ( self . passes ) <EOL> self . garbage_collection_policy = choose_garbage_collection_policy ( ) <EOL> def get_pass_number ( self , pass_name , default = None ) : <EOL> """<STR_LIT>""" <EOL> if not pass_name and default is not None : <EOL> assert <NUM_LIT:1> <= default <= self . num_passes <EOL> return default <EOL> try : <EOL> pass_number = int ( pass_name ) <EOL> if not <NUM_LIT:1> <= pass_number <= self . num_passes : <EOL> raise InvalidPassError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( pass_number , self . num_passes , ) ) <EOL> return pass_number <EOL> except ValueError : <EOL> for ( i , the_pass ) in enumerate ( self . passes ) : <EOL> if the_pass . name == pass_name : <EOL> return i + <NUM_LIT:1> <EOL> raise InvalidPassError ( '<STR_LIT>' % ( pass_name , ) ) <EOL> def run ( self , run_options ) : <EOL> """<STR_LIT>""" <EOL> index_start = run_options . start_pass - <NUM_LIT:1> <EOL> index_end = run_options . end_pass <EOL> for ( i , the_pass ) in enumerate ( self . passes ) : <EOL> the_pass . register_artifacts ( ) <EOL> artifact_manager . register_temp_file ( <EOL> config . STATISTICS_FILE % ( i + <NUM_LIT:1> , ) , the_pass <EOL> ) <EOL> if i != <NUM_LIT:0> : <EOL> artifact_manager . register_temp_file_needed ( <EOL> config . STATISTICS_FILE % ( i + <NUM_LIT:1> - <NUM_LIT:1> , ) , the_pass <EOL> ) <EOL> for the_pass in self . passes [ <NUM_LIT:0> : index_start ] : <EOL> artifact_manager . pass_skipped ( the_pass ) <EOL> start_time = time . time ( ) <EOL> for i in range ( index_start , index_end ) : <EOL> the_pass = self . passes [ i ] <EOL> logger . quiet ( '<STR_LIT>' % ( i + <NUM_LIT:1> , the_pass . name , ) ) <EOL> artifact_manager . pass_started ( the_pass ) <EOL> if i == <NUM_LIT:0> : <EOL> stats_keeper = StatsKeeper ( ) <EOL> else : <EOL> stats_keeper = read_stats_keeper ( <EOL> artifact_manager . get_temp_file ( <EOL> config . STATISTICS_FILE % ( i + <NUM_LIT:1> - <NUM_LIT:1> , ) <EOL> ) <EOL> ) <EOL> the_pass . run ( run_options , stats_keeper ) <EOL> end_time = time . time ( ) <EOL> stats_keeper . log_duration_for_pass ( <EOL> end_time - start_time , i + <NUM_LIT:1> , the_pass . name <EOL> ) <EOL> logger . normal ( stats_keeper . single_pass_timing ( i + <NUM_LIT:1> ) ) <EOL> stats_keeper . archive ( <EOL> artifact_manager . get_temp_file ( config . STATISTICS_FILE % ( i + <NUM_LIT:1> , ) ) <EOL> ) <EOL> start_time = end_time <EOL> Ctx ( ) . clean ( ) <EOL> artifact_manager . pass_done ( the_pass , Ctx ( ) . skip_cleanup ) <EOL> self . garbage_collection_policy . check_for_garbage ( ) <EOL> for the_pass in self . passes [ index_end : ] : <EOL> artifact_manager . pass_deferred ( the_pass ) <EOL> logger . quiet ( stats_keeper ) <EOL> logger . normal ( stats_keeper . timings ( ) ) <EOL> artifact_manager . check_clean ( ) <EOL> def help_passes ( self ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> for ( i , the_pass ) in enumerate ( self . passes ) : <EOL> print '<STR_LIT>' % ( i + <NUM_LIT:1> , the_pass . name , ) </s>
