<s> """<STR_LIT>""" <EOL> import sys <EOL> import logging <EOL> try : <EOL> from argparse import ArgumentParser as _ArgumentParser <EOL> _argparse_success = True <EOL> except : <EOL> class _ArgumentParser : pass <EOL> _argparse_success = False <EOL> from . debugging import bacpypes_debugging , LoggingFormatter , ModuleLogger <EOL> from ConfigParser import ConfigParser as _ConfigParser <EOL> _debug = <NUM_LIT:0> <EOL> _log = ModuleLogger ( globals ( ) ) <EOL> def ConsoleLogHandler ( loggerRef = '<STR_LIT>' , level = logging . DEBUG , color = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( loggerRef , logging . Logger ) : <EOL> pass <EOL> elif isinstance ( loggerRef , str ) : <EOL> if not loggerRef : <EOL> loggerRef = _log <EOL> elif loggerRef not in logging . Logger . manager . loggerDict : <EOL> raise RuntimeError ( "<STR_LIT>" % ( loggerRef , ) ) <EOL> loggerRef = logging . getLogger ( loggerRef ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" % ( loggerRef , ) ) <EOL> if hasattr ( loggerRef , '<STR_LIT>' ) : <EOL> loggerRef . globs [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> elif hasattr ( loggerRef . parent , '<STR_LIT>' ) : <EOL> loggerRef . parent . globs [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> hdlr = logging . StreamHandler ( ) <EOL> hdlr . setLevel ( level ) <EOL> hdlr . setFormatter ( LoggingFormatter ( color ) ) <EOL> loggerRef . addHandler ( hdlr ) <EOL> loggerRef . setLevel ( level ) <EOL> class ArgumentParser ( _ArgumentParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if _debug : ArgumentParser . _debug ( "<STR_LIT>" ) <EOL> if not _argparse_success : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> _ArgumentParser . __init__ ( self , ** kwargs ) <EOL> self . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> ) <EOL> self . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> self . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> ) <EOL> def parse_args ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if _debug : ArgumentParser . _debug ( "<STR_LIT>" ) <EOL> result_args = _ArgumentParser . parse_args ( self , * args , ** kwargs ) <EOL> if result_args . buggers : <EOL> loggers = sorted ( logging . Logger . manager . loggerDict . keys ( ) ) <EOL> for loggerName in loggers : <EOL> sys . stdout . write ( loggerName + '<STR_LIT:\n>' ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if result_args . debug is None : <EOL> bug_list = [ ] <EOL> elif not result_args . debug : <EOL> bug_list = [ "<STR_LIT:__main__>" ] <EOL> else : <EOL> bug_list = result_args . debug <EOL> if result_args . color : <EOL> for i , debug_name in enumerate ( bug_list ) : <EOL> ConsoleLogHandler ( debug_name , color = ( i % <NUM_LIT:6> ) + <NUM_LIT:2> ) <EOL> else : <EOL> for debug_name in bug_list : <EOL> ConsoleLogHandler ( debug_name ) <EOL> return result_args <EOL> bacpypes_debugging ( ArgumentParser ) <EOL> class ConfigArgumentParser ( ArgumentParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if _debug : ConfigArgumentParser . _debug ( "<STR_LIT>" ) <EOL> ArgumentParser . __init__ ( self , ** kwargs ) <EOL> self . add_argument ( '<STR_LIT>' , <EOL> help = "<STR_LIT>" , <EOL> default = "<STR_LIT>" , <EOL> ) <EOL> def parse_args ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if _debug : ConfigArgumentParser . _debug ( "<STR_LIT>" ) <EOL> result_args = ArgumentParser . parse_args ( self , * args , ** kwargs ) <EOL> config = _ConfigParser ( ) <EOL> config . read ( result_args . ini ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , config ) <EOL> if not config . has_section ( '<STR_LIT>' ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> ini_obj = type ( '<STR_LIT>' , ( object , ) , dict ( config . items ( '<STR_LIT>' ) ) ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , ini_obj ) <EOL> setattr ( result_args , '<STR_LIT>' , ini_obj ) <EOL> return result_args <EOL> bacpypes_debugging ( ConfigArgumentParser ) </s>
