<s> from __future__ import unicode_literals <EOL> from threading import RLock <EOL> class NullProgressMonitor ( object ) : <EOL> def info ( self , info ) : <EOL> pass <EOL> def start ( self , task = '<STR_LIT>' , work = <NUM_LIT:100> ) : <EOL> pass <EOL> def work ( self , info = '<STR_LIT>' , amount = <NUM_LIT:1> ) : <EOL> pass <EOL> def done ( self ) : <EOL> pass <EOL> class CLIProgressMonitor ( object ) : <EOL> def __init__ ( self , min_step = - <NUM_LIT:1> ) : <EOL> self . min_step = min_step <EOL> self . last_current = <NUM_LIT:0.0> <EOL> def info ( self , info ) : <EOL> print ( '<STR_LIT>' . format ( info ) ) <EOL> def start ( self , task = '<STR_LIT>' , work = <NUM_LIT> ) : <EOL> print ( '<STR_LIT>' . format ( task ) ) <EOL> self . total_work = float ( work ) <EOL> self . current_work = <NUM_LIT:0.0> <EOL> self . task = task <EOL> self . last_current = <NUM_LIT:0.0> <EOL> def work ( self , info = '<STR_LIT>' , amount = <NUM_LIT:1.0> ) : <EOL> self . current_work += amount <EOL> progress = float ( self . current_work ) * <NUM_LIT> / self . total_work <EOL> if self . min_step == - <NUM_LIT:1> or ( <EOL> ( progress - self . last_current ) >= self . min_step ) : <EOL> print ( '<STR_LIT>' . format ( info , progress ) ) <EOL> self . last_current = progress <EOL> def done ( self ) : <EOL> print ( '<STR_LIT>' . format ( self . task ) ) <EOL> class CLILockProgressMonitor ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> self . lock = RLock ( ) <EOL> def info ( self , info ) : <EOL> print ( '<STR_LIT>' . format ( info ) ) <EOL> def start ( self , task = '<STR_LIT>' , work = <NUM_LIT> ) : <EOL> print ( '<STR_LIT>' . format ( task ) ) <EOL> self . total_work = float ( work ) <EOL> self . current_work = <NUM_LIT:0.0> <EOL> self . task = task <EOL> def work ( self , info = '<STR_LIT>' , amount = <NUM_LIT:1.0> ) : <EOL> with self . lock : <EOL> self . current_work += amount <EOL> print ( '<STR_LIT>' . format ( info , float ( self . current_work ) * <EOL> <NUM_LIT> / self . total_work ) ) <EOL> def done ( self ) : <EOL> print ( '<STR_LIT>' . format ( self . task ) ) </s>
