<s> """<STR_LIT>""" <EOL> import sys <EOL> from optparse import OptionParser <EOL> class Flags ( object ) : <EOL> """<STR_LIT>""" <EOL> PARSER = OptionParser ( ) <EOL> PARSED_OPTIONS = None <EOL> @ classmethod <EOL> def parse_args ( cls ) : <EOL> """<STR_LIT>""" <EOL> ( options , argv ) = Flags . PARSER . parse_args ( ) <EOL> sys . argv = [ sys . argv [ <NUM_LIT:0> ] ] + argv <EOL> Flags . PARSED_OPTIONS = options <EOL> def __getattr__ ( self , name ) : <EOL> if Flags . PARSED_OPTIONS and hasattr ( Flags . PARSED_OPTIONS , name ) : <EOL> return getattr ( Flags . PARSED_OPTIONS , name ) <EOL> for option in Flags . PARSER . option_list : <EOL> if option . dest == name : <EOL> return option . default <EOL> raise AttributeError ( '<STR_LIT>' % name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> if Flags . PARSED_OPTIONS and hasattr ( Flags . PARSED_OPTIONS , name ) : <EOL> setattr ( Flags . PARSED_OPTIONS , name , value ) <EOL> return <EOL> for option in Flags . PARSER . option_list : <EOL> if option . dest == name : <EOL> option . default = value <EOL> return <EOL> object . __setattr__ ( self , name , value ) <EOL> OPTIONS = Flags ( ) <EOL> def init ( ) : <EOL> """<STR_LIT>""" <EOL> OPTIONS . parse_args ( ) <EOL> def add ( flagname , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> Flags . PARSER . add_option ( '<STR_LIT>' % flagname , <EOL> dest = flagname , ** kwargs ) <EOL> def add_bool ( flagname , default = True , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> Flags . PARSER . add_option ( '<STR_LIT>' % flagname , <EOL> dest = flagname , default = default , <EOL> action = "<STR_LIT:store_true>" , ** kwargs ) <EOL> Flags . PARSER . add_option ( '<STR_LIT>' % flagname , <EOL> dest = flagname , <EOL> action = "<STR_LIT>" , ** kwargs ) </s>
