<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import time <EOL> import sys <EOL> import os <EOL> import shutil <EOL> import logging <EOL> import pprint <EOL> from . disk import mkdirp <EOL> def _squeeze_time ( t ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> return max ( <NUM_LIT:0> , t - <NUM_LIT> ) <EOL> else : <EOL> return t <EOL> def format_time ( t ) : <EOL> t = _squeeze_time ( t ) <EOL> return "<STR_LIT>" % ( t , t / <NUM_LIT> ) <EOL> def short_format_time ( t ) : <EOL> t = _squeeze_time ( t ) <EOL> if t > <NUM_LIT> : <EOL> return "<STR_LIT>" % ( t / <NUM_LIT> ) <EOL> else : <EOL> return "<STR_LIT>" % ( t ) <EOL> def pformat ( obj , indent = <NUM_LIT:0> , depth = <NUM_LIT:3> ) : <EOL> if '<STR_LIT>' in sys . modules : <EOL> import numpy as np <EOL> print_options = np . get_printoptions ( ) <EOL> np . set_printoptions ( precision = <NUM_LIT:6> , threshold = <NUM_LIT:64> , edgeitems = <NUM_LIT:1> ) <EOL> else : <EOL> print_options = None <EOL> out = pprint . pformat ( obj , depth = depth , indent = indent ) <EOL> if print_options : <EOL> np . set_printoptions ( ** print_options ) <EOL> return out <EOL> class Logger ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , depth = <NUM_LIT:3> ) : <EOL> """<STR_LIT>""" <EOL> self . depth = depth <EOL> def warn ( self , msg ) : <EOL> logging . warn ( "<STR_LIT>" % ( self , msg ) ) <EOL> def debug ( self , msg ) : <EOL> logging . debug ( "<STR_LIT>" % ( self , msg ) ) <EOL> def format ( self , obj , indent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return pformat ( obj , indent = indent , depth = self . depth ) <EOL> class PrintTime ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , logfile = None , logdir = None ) : <EOL> if logfile is not None and logdir is not None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . last_time = time . time ( ) <EOL> self . start_time = self . last_time <EOL> if logdir is not None : <EOL> logfile = os . path . join ( logdir , '<STR_LIT>' ) <EOL> self . logfile = logfile <EOL> if logfile is not None : <EOL> mkdirp ( os . path . dirname ( logfile ) ) <EOL> if os . path . exists ( logfile ) : <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> try : <EOL> shutil . move ( logfile + '<STR_LIT>' % i , <EOL> logfile + '<STR_LIT>' % ( i + <NUM_LIT:1> ) ) <EOL> except : <EOL> "<STR_LIT>" <EOL> try : <EOL> shutil . copy ( logfile , logfile + '<STR_LIT>' ) <EOL> except : <EOL> "<STR_LIT>" <EOL> try : <EOL> with open ( logfile , '<STR_LIT:w>' ) as logfile : <EOL> logfile . write ( '<STR_LIT>' ) <EOL> logfile . write ( '<STR_LIT>' % time . ctime ( self . last_time ) ) <EOL> except : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , msg = '<STR_LIT>' , total = False ) : <EOL> """<STR_LIT>""" <EOL> if not total : <EOL> time_lapse = time . time ( ) - self . last_time <EOL> full_msg = "<STR_LIT>" % ( msg , format_time ( time_lapse ) ) <EOL> else : <EOL> time_lapse = time . time ( ) - self . start_time <EOL> full_msg = "<STR_LIT>" % ( msg , time_lapse , <EOL> time_lapse / <NUM_LIT> ) <EOL> print ( full_msg , file = sys . stderr ) <EOL> if self . logfile is not None : <EOL> try : <EOL> with open ( self . logfile , '<STR_LIT:a>' ) as f : <EOL> print ( full_msg , file = f ) <EOL> except : <EOL> """<STR_LIT>""" <EOL> self . last_time = time . time ( ) </s>
