<s> import time , sys <EOL> class TimeoutException : <EOL> pass <EOL> class SubCommandErrorException : <EOL> def __init__ ( self , msg ) : <EOL> self . _msg = msg <EOL> def __str__ ( self ) : <EOL> return str ( self . _msg ) <EOL> class Logger : <EOL> def __init__ ( self , verbosity = <NUM_LIT:1> , out = sys . stdout ) : <EOL> self . _verbosity = int ( verbosity ) <EOL> self . _out = out <EOL> def log ( self , msgtype , msg ) : <EOL> if ( <EOL> self . _verbosity >= <NUM_LIT:2> or msgtype in [ '<STR_LIT>' , '<STR_LIT:error>' ] <EOL> or ( self . _verbosity == <NUM_LIT:1> and msgtype != '<STR_LIT>' ) <EOL> ) : <EOL> self . _out . write ( msg ) <EOL> self . _out . write ( "<STR_LIT:\r\n>" ) <EOL> class Timer : <EOL> def __init__ ( self , limit = None ) : <EOL> self . _start = time . time ( ) <EOL> self . _limit = limit <EOL> def check ( self ) : <EOL> if self . remaining <= <NUM_LIT:0> : <EOL> raise TimeoutException ( ) <EOL> @ property <EOL> def elapsed ( self ) : <EOL> return time . time ( ) - self . _start <EOL> @ property <EOL> def remaining ( self ) : <EOL> if self . _limit is not None : <EOL> ans = self . _limit - self . elapsed <EOL> return <NUM_LIT:0> if ans < <NUM_LIT:0> else ans <EOL> else : <EOL> return <NUM_LIT> * <NUM_LIT> * <NUM_LIT> <EOL> class SubCommand : <EOL> def __init__ ( self , command ) : <EOL> self . command = command <EOL> def _get_data_root ( self ) : <EOL> return self . command . DATA_ROOT <EOL> def _get_opt ( self , opt ) : <EOL> return self . command . _opts [ opt ] <EOL> def _check_timer ( self ) : <EOL> if self . command . timer is not None : <EOL> self . command . timer . check ( ) <EOL> def _timer_remaining ( self ) : <EOL> return self . command . timer . remaining <EOL> def _debug ( self , msg ) : <EOL> self . _log ( '<STR_LIT>' , msg ) <EOL> def _info ( self , msg ) : <EOL> self . _log ( '<STR_LIT:info>' , msg ) <EOL> def _warn ( self , msg ) : <EOL> self . _log ( '<STR_LIT>' , msg ) <EOL> def _error ( self , msg , no_exception = False ) : <EOL> self . _log ( '<STR_LIT:error>' , msg ) <EOL> if not no_exception : <EOL> raise SubCommandErrorException ( msg ) <EOL> def _log ( self , msgtype , msg ) : <EOL> self . command . logger . log ( msgtype , msg ) </s>
