<s> from __future__ import division <EOL> import os <EOL> import time <EOL> import argparse <EOL> from lfd . util import colorize <EOL> def redprint ( msg ) : <EOL> print colorize . colorize ( msg , "<STR_LIT>" , bold = True ) <EOL> def yellowprint ( msg ) : <EOL> print colorize . colorize ( msg , "<STR_LIT>" , bold = True ) <EOL> class ArgumentParser ( argparse . ArgumentParser ) : <EOL> def parse_args ( self , * args , ** kw ) : <EOL> res = argparse . ArgumentParser . parse_args ( self , * args , ** kw ) <EOL> from argparse import _HelpAction , _SubParsersAction <EOL> for x in self . _subparsers . _actions : <EOL> if not isinstance ( x , _SubParsersAction ) : <EOL> continue <EOL> v = x . choices [ res . subparser_name ] <EOL> subparseargs = { } <EOL> for x1 in v . _optionals . _actions : <EOL> if isinstance ( x1 , _HelpAction ) : <EOL> continue <EOL> n = x1 . dest <EOL> if hasattr ( res , n ) : <EOL> subparseargs [ n ] = getattr ( res , n ) <EOL> delattr ( res , n ) <EOL> res . __setattr__ ( res . subparser_name , argparse . Namespace ( ** subparseargs ) ) <EOL> return res <EOL> class Bunch ( object ) : <EOL> def __init__ ( self , adict ) : <EOL> self . __dict__ . update ( adict ) <EOL> class suppress_stdout ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> while ( True ) : <EOL> try : <EOL> self . null_fds = os . open ( os . devnull , os . O_RDWR ) <EOL> break <EOL> except OSError : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> self . save_fds = os . dup ( <NUM_LIT:1> ) <EOL> def __enter__ ( self ) : <EOL> os . dup2 ( self . null_fds , <NUM_LIT:1> ) <EOL> os . close ( self . null_fds ) <EOL> def __exit__ ( self , * _ ) : <EOL> os . dup2 ( self . save_fds , <NUM_LIT:1> ) <EOL> os . close ( self . save_fds ) </s>
