<s> import os , sys , yaml , datetime <EOL> from yaml import Loader , SafeLoader <EOL> import logging <EOL> import logging . handlers <EOL> import codecs <EOL> time_format = u"<STR_LIT>" <EOL> log_time_format = u"<STR_LIT>" <EOL> now = datetime . datetime . now ( ) . strftime ( log_time_format ) <EOL> today = datetime . datetime . now ( ) . strftime ( time_format ) <EOL> hostname = os . getenv ( "<STR_LIT>" ) <EOL> cwd = os . getcwd ( ) <EOL> formatter = u"<STR_LIT>" <EOL> min_formatter = u"<STR_LIT>" <EOL> extra_formatter = u"<STR_LIT>" <EOL> max_size = <NUM_LIT:20> * <NUM_LIT> * <NUM_LIT> <EOL> keep_count = <NUM_LIT:5> <EOL> def load_yaml_file ( yaml_file ) : <EOL> logger = logging . getLogger ( ) <EOL> try : <EOL> f = codecs . open ( yaml_file , encoding = '<STR_LIT:utf-8>' ) <EOL> yaml_opts = yaml . load ( f ) <EOL> f . close ( ) <EOL> return yaml_opts <EOL> except : <EOL> raise <EOL> def construct_yaml_str ( self , node ) : <EOL> return self . construct_scalar ( node ) <EOL> Loader . add_constructor ( u'<STR_LIT>' , construct_yaml_str ) <EOL> SafeLoader . add_constructor ( u'<STR_LIT>' , construct_yaml_str ) <EOL> def Logger ( logfile_name , log_level = logging . INFO , time_format = log_time_format , extra_info = False , ** kw ) : <EOL> logger = logging . getLogger ( ) <EOL> log_logging_level = log_level <EOL> console_logging_level = log_level <EOL> log_formatter = formatter <EOL> console_formatter = min_formatter <EOL> if extra_info : log_formatter = extra_formatter <EOL> if log_level == logging . DEBUG : <EOL> console_formatter = log_formatter <EOL> if kw . has_key ( "<STR_LIT>" ) : <EOL> console_logging_level = kw [ "<STR_LIT>" ] <EOL> if kw . has_key ( "<STR_LIT>" ) : <EOL> log_formatter = kw [ "<STR_LIT>" ] <EOL> if kw . has_key ( "<STR_LIT>" ) : <EOL> console_formatter = kw [ "<STR_LIT>" ] <EOL> if kw . has_key ( "<STR_LIT>" ) : <EOL> log_formatter = kw [ "<STR_LIT>" ] <EOL> console_formatter = log_formatter <EOL> logdir = os . path . dirname ( logfile_name ) <EOL> if not os . path . isdir ( logdir ) : <EOL> os . makedirs ( logdir ) <EOL> log_formatter = logging . Formatter ( log_formatter , datefmt = time_format ) <EOL> console_formatter = logging . Formatter ( console_formatter , datefmt = time_format ) <EOL> logger . setLevel ( log_logging_level ) <EOL> log_handler = logging . handlers . RotatingFileHandler ( <EOL> logfile_name , <EOL> maxBytes = max_size , <EOL> backupCount = keep_count , <EOL> encoding = '<STR_LIT:utf-8>' <EOL> ) <EOL> log_handler . setFormatter ( log_formatter ) <EOL> console_handler = logging . StreamHandler ( ) <EOL> console_handler . setLevel ( console_logging_level ) <EOL> console_handler . setFormatter ( console_formatter ) <EOL> logger . addHandler ( log_handler ) <EOL> logger . addHandler ( console_handler ) <EOL> return logger <EOL> def LoggerQuickSetup ( log_file , log_level = logging . INFO , filename_time_format = '<STR_LIT>' , extra_info = False , ** kw ) : <EOL> log_file = log_file + "<STR_LIT:_>" + today + "<STR_LIT>" <EOL> logger = Logger ( log_file , log_level = log_level , extra_info = extra_info , ** kw ) <EOL> logger . info ( "<STR_LIT>" % log_file ) <EOL> return logger <EOL> def promptUser ( msg , accptResp ) : <EOL> resp = raw_input ( msg ) <EOL> if resp == accptResp : <EOL> return True <EOL> else : <EOL> return False </s>
