<s> import os <EOL> import sh <EOL> import sys <EOL> def format_cwd ( cwd ) : <EOL> return os . path . join ( cwd ) if cwd else '<STR_LIT:.>' <EOL> _original_init = sh . RunningCommand . __init__ <EOL> def _verbose_init ( self , cmd , call_args , stdin , stdout , stderr ) : <EOL> print u"<STR_LIT>" . format ( <EOL> cwd = format_cwd ( call_args [ '<STR_LIT>' ] ) , <EOL> command = '<STR_LIT:U+0020>' . join ( cmd [ <NUM_LIT:0> ] . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ <NUM_LIT:1> : ] + cmd [ <NUM_LIT:1> : ] ) , <EOL> ) <EOL> try : <EOL> _original_init ( self , cmd , call_args , stdin , stdout , stderr ) <EOL> except sh . ErrorReturnCode as e : <EOL> sys . stdout . write ( e . stdout ) <EOL> sys . stderr . write ( e . stderr ) <EOL> raise <EOL> else : <EOL> sys . stdout . write ( self . stdout ) <EOL> sys . stderr . write ( self . stderr ) <EOL> def patch_sh_verbose ( ) : <EOL> sh . RunningCommand . __init__ = _verbose_init <EOL> class ShVerbose ( object ) : <EOL> def __init__ ( self , verbose = True ) : <EOL> self . verbose = verbose <EOL> self . start_init = None <EOL> def __enter__ ( self ) : <EOL> self . start_init = sh . RunningCommand . __init__ <EOL> sh . RunningCommand . __init__ = ( _verbose_init if self . verbose <EOL> else _original_init ) <EOL> def __exit__ ( self , exc_type , exc_val , exc_tb ) : <EOL> sh . RunningCommand . __init__ = self . start_init </s>
