<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys , os , re <EOL> from email import message_from_file <EOL> try : <EOL> import warnings <EOL> except ImportError : <EOL> warnings = None <EOL> from distutils . errors import ( DistutilsOptionError , DistutilsArgError , <EOL> DistutilsModuleError , DistutilsClassError ) <EOL> from distutils . fancy_getopt import FancyGetopt , translate_longopt <EOL> from distutils . util import check_environ , strtobool , rfc822_escape <EOL> from distutils import log <EOL> from distutils . debug import DEBUG <EOL> PKG_INFO_ENCODING = '<STR_LIT:utf-8>' <EOL> command_re = re . compile ( r'<STR_LIT>' ) <EOL> class Distribution : <EOL> """<STR_LIT>""" <EOL> global_options = [ ( '<STR_LIT>' , '<STR_LIT:v>' , "<STR_LIT>" , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:q>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:n>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:h>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) , <EOL> ] <EOL> common_usage = """<STR_LIT>""" <EOL> display_options = [ <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT:name>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT:version>' , '<STR_LIT>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT:url>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT:description>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) <EOL> ] <EOL> display_option_names = map ( lambda x : translate_longopt ( x [ <NUM_LIT:0> ] ) , <EOL> display_options ) <EOL> negative_opt = { '<STR_LIT>' : '<STR_LIT>' } <EOL> def __init__ ( self , attrs = None ) : <EOL> """<STR_LIT>""" <EOL> self . verbose = <NUM_LIT:1> <EOL> self . dry_run = <NUM_LIT:0> <EOL> self . help = <NUM_LIT:0> <EOL> for attr in self . display_option_names : <EOL> setattr ( self , attr , <NUM_LIT:0> ) <EOL> self . metadata = DistributionMetadata ( ) <EOL> for basename in self . metadata . _METHOD_BASENAMES : <EOL> method_name = "<STR_LIT>" + basename <EOL> setattr ( self , method_name , getattr ( self . metadata , method_name ) ) <EOL> self . cmdclass = { } <EOL> self . command_packages = None <EOL> self . script_name = None <EOL> self . script_args = None <EOL> self . command_options = { } <EOL> self . dist_files = [ ] <EOL> self . packages = None <EOL> self . package_data = { } <EOL> self . package_dir = None <EOL> self . py_modules = None <EOL> self . libraries = None <EOL> self . headers = None <EOL> self . ext_modules = None <EOL> self . ext_package = None <EOL> self . include_dirs = None <EOL> self . extra_path = None <EOL> self . scripts = None <EOL> self . data_files = None <EOL> self . password = '<STR_LIT>' <EOL> self . command_obj = { } <EOL> self . have_run = { } <EOL> if attrs : <EOL> options = attrs . get ( '<STR_LIT>' ) <EOL> if options is not None : <EOL> del attrs [ '<STR_LIT>' ] <EOL> for ( command , cmd_options ) in options . items ( ) : <EOL> opt_dict = self . get_option_dict ( command ) <EOL> for ( opt , val ) in cmd_options . items ( ) : <EOL> opt_dict [ opt ] = ( "<STR_LIT>" , val ) <EOL> if '<STR_LIT>' in attrs : <EOL> attrs [ '<STR_LIT>' ] = attrs [ '<STR_LIT>' ] <EOL> del attrs [ '<STR_LIT>' ] <EOL> msg = "<STR_LIT>" <EOL> if warnings is not None : <EOL> warnings . warn ( msg ) <EOL> else : <EOL> sys . stderr . write ( msg + "<STR_LIT:\n>" ) <EOL> for ( key , val ) in attrs . items ( ) : <EOL> if hasattr ( self . metadata , "<STR_LIT>" + key ) : <EOL> getattr ( self . metadata , "<STR_LIT>" + key ) ( val ) <EOL> elif hasattr ( self . metadata , key ) : <EOL> setattr ( self . metadata , key , val ) <EOL> elif hasattr ( self , key ) : <EOL> setattr ( self , key , val ) <EOL> else : <EOL> msg = "<STR_LIT>" % repr ( key ) <EOL> if warnings is not None : <EOL> warnings . warn ( msg ) <EOL> else : <EOL> sys . stderr . write ( msg + "<STR_LIT:\n>" ) <EOL> self . want_user_cfg = True <EOL> if self . script_args is not None : <EOL> for arg in self . script_args : <EOL> if not arg . startswith ( '<STR_LIT:->' ) : <EOL> break <EOL> if arg == '<STR_LIT>' : <EOL> self . want_user_cfg = False <EOL> break <EOL> self . finalize_options ( ) <EOL> def get_option_dict ( self , command ) : <EOL> """<STR_LIT>""" <EOL> dict = self . command_options . get ( command ) <EOL> if dict is None : <EOL> dict = self . command_options [ command ] = { } <EOL> return dict <EOL> def dump_option_dicts ( self , header = None , commands = None , indent = "<STR_LIT>" ) : <EOL> from pprint import pformat <EOL> if commands is None : <EOL> commands = self . command_options . keys ( ) <EOL> commands . sort ( ) <EOL> if header is not None : <EOL> self . announce ( indent + header ) <EOL> indent = indent + "<STR_LIT:U+0020>" <EOL> if not commands : <EOL> self . announce ( indent + "<STR_LIT>" ) <EOL> return <EOL> for cmd_name in commands : <EOL> opt_dict = self . command_options . get ( cmd_name ) <EOL> if opt_dict is None : <EOL> self . announce ( indent + <EOL> "<STR_LIT>" % cmd_name ) <EOL> else : <EOL> self . announce ( indent + <EOL> "<STR_LIT>" % cmd_name ) <EOL> out = pformat ( opt_dict ) <EOL> for line in out . split ( '<STR_LIT:\n>' ) : <EOL> self . announce ( indent + "<STR_LIT:U+0020>" + line ) <EOL> def find_config_files ( self ) : <EOL> """<STR_LIT>""" <EOL> files = [ ] <EOL> check_environ ( ) <EOL> sys_dir = os . path . dirname ( sys . modules [ '<STR_LIT>' ] . __file__ ) <EOL> sys_file = os . path . join ( sys_dir , "<STR_LIT>" ) <EOL> if os . path . isfile ( sys_file ) : <EOL> files . append ( sys_file ) <EOL> if os . name == '<STR_LIT>' : <EOL> user_filename = "<STR_LIT>" <EOL> else : <EOL> user_filename = "<STR_LIT>" <EOL> if self . want_user_cfg : <EOL> user_file = os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , user_filename ) <EOL> if os . path . isfile ( user_file ) : <EOL> files . append ( user_file ) <EOL> local_file = "<STR_LIT>" <EOL> if os . path . isfile ( local_file ) : <EOL> files . append ( local_file ) <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( files ) ) <EOL> return files <EOL> def parse_config_files ( self , filenames = None ) : <EOL> from ConfigParser import ConfigParser <EOL> if filenames is None : <EOL> filenames = self . find_config_files ( ) <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" ) <EOL> parser = ConfigParser ( ) <EOL> for filename in filenames : <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" % filename ) <EOL> parser . read ( filename ) <EOL> for section in parser . sections ( ) : <EOL> options = parser . options ( section ) <EOL> opt_dict = self . get_option_dict ( section ) <EOL> for opt in options : <EOL> if opt != '<STR_LIT>' : <EOL> val = parser . get ( section , opt ) <EOL> opt = opt . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> opt_dict [ opt ] = ( filename , val ) <EOL> parser . __init__ ( ) <EOL> if '<STR_LIT>' in self . command_options : <EOL> for ( opt , ( src , val ) ) in self . command_options [ '<STR_LIT>' ] . items ( ) : <EOL> alias = self . negative_opt . get ( opt ) <EOL> try : <EOL> if alias : <EOL> setattr ( self , alias , not strtobool ( val ) ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> setattr ( self , opt , strtobool ( val ) ) <EOL> else : <EOL> setattr ( self , opt , val ) <EOL> except ValueError , msg : <EOL> raise DistutilsOptionError , msg <EOL> def parse_command_line ( self ) : <EOL> """<STR_LIT>""" <EOL> toplevel_options = self . _get_toplevel_options ( ) <EOL> self . commands = [ ] <EOL> parser = FancyGetopt ( toplevel_options + self . display_options ) <EOL> parser . set_negative_aliases ( self . negative_opt ) <EOL> parser . set_aliases ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> args = parser . getopt ( args = self . script_args , object = self ) <EOL> option_order = parser . get_option_order ( ) <EOL> log . set_verbosity ( self . verbose ) <EOL> if self . handle_display_options ( option_order ) : <EOL> return <EOL> while args : <EOL> args = self . _parse_command_opts ( parser , args ) <EOL> if args is None : <EOL> return <EOL> if self . help : <EOL> self . _show_help ( parser , <EOL> display_options = len ( self . commands ) == <NUM_LIT:0> , <EOL> commands = self . commands ) <EOL> return <EOL> if not self . commands : <EOL> raise DistutilsArgError , "<STR_LIT>" <EOL> return <NUM_LIT:1> <EOL> def _get_toplevel_options ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . global_options + [ <EOL> ( "<STR_LIT>" , None , <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> def _parse_command_opts ( self , parser , args ) : <EOL> """<STR_LIT>""" <EOL> from distutils . cmd import Command <EOL> command = args [ <NUM_LIT:0> ] <EOL> if not command_re . match ( command ) : <EOL> raise SystemExit , "<STR_LIT>" % command <EOL> self . commands . append ( command ) <EOL> try : <EOL> cmd_class = self . get_command_class ( command ) <EOL> except DistutilsModuleError , msg : <EOL> raise DistutilsArgError , msg <EOL> if not issubclass ( cmd_class , Command ) : <EOL> raise DistutilsClassError , "<STR_LIT>" % cmd_class <EOL> if not ( hasattr ( cmd_class , '<STR_LIT>' ) and <EOL> isinstance ( cmd_class . user_options , list ) ) : <EOL> raise DistutilsClassError , ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) % cmd_class <EOL> negative_opt = self . negative_opt <EOL> if hasattr ( cmd_class , '<STR_LIT>' ) : <EOL> negative_opt = negative_opt . copy ( ) <EOL> negative_opt . update ( cmd_class . negative_opt ) <EOL> if ( hasattr ( cmd_class , '<STR_LIT>' ) and <EOL> isinstance ( cmd_class . help_options , list ) ) : <EOL> help_options = fix_help_options ( cmd_class . help_options ) <EOL> else : <EOL> help_options = [ ] <EOL> parser . set_option_table ( self . global_options + <EOL> cmd_class . user_options + <EOL> help_options ) <EOL> parser . set_negative_aliases ( negative_opt ) <EOL> ( args , opts ) = parser . getopt ( args [ <NUM_LIT:1> : ] ) <EOL> if hasattr ( opts , '<STR_LIT>' ) and opts . help : <EOL> self . _show_help ( parser , display_options = <NUM_LIT:0> , commands = [ cmd_class ] ) <EOL> return <EOL> if ( hasattr ( cmd_class , '<STR_LIT>' ) and <EOL> isinstance ( cmd_class . help_options , list ) ) : <EOL> help_option_found = <NUM_LIT:0> <EOL> for ( help_option , short , desc , func ) in cmd_class . help_options : <EOL> if hasattr ( opts , parser . get_attr_name ( help_option ) ) : <EOL> help_option_found = <NUM_LIT:1> <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> func ( ) <EOL> else : <EOL> raise DistutilsClassError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( func , help_option ) ) <EOL> if help_option_found : <EOL> return <EOL> opt_dict = self . get_option_dict ( command ) <EOL> for ( name , value ) in vars ( opts ) . items ( ) : <EOL> opt_dict [ name ] = ( "<STR_LIT>" , value ) <EOL> return args <EOL> def finalize_options ( self ) : <EOL> """<STR_LIT>""" <EOL> for attr in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> value = getattr ( self . metadata , attr ) <EOL> if value is None : <EOL> continue <EOL> if isinstance ( value , str ) : <EOL> value = [ elm . strip ( ) for elm in value . split ( '<STR_LIT:U+002C>' ) ] <EOL> setattr ( self . metadata , attr , value ) <EOL> def _show_help ( self , parser , global_options = <NUM_LIT:1> , display_options = <NUM_LIT:1> , <EOL> commands = [ ] ) : <EOL> """<STR_LIT>""" <EOL> from distutils . core import gen_usage <EOL> from distutils . cmd import Command <EOL> if global_options : <EOL> if display_options : <EOL> options = self . _get_toplevel_options ( ) <EOL> else : <EOL> options = self . global_options <EOL> parser . set_option_table ( options ) <EOL> parser . print_help ( self . common_usage + "<STR_LIT>" ) <EOL> print ( '<STR_LIT>' ) <EOL> if display_options : <EOL> parser . set_option_table ( self . display_options ) <EOL> parser . print_help ( <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> print ( '<STR_LIT>' ) <EOL> for command in self . commands : <EOL> if isinstance ( command , type ) and issubclass ( command , Command ) : <EOL> klass = command <EOL> else : <EOL> klass = self . get_command_class ( command ) <EOL> if ( hasattr ( klass , '<STR_LIT>' ) and <EOL> isinstance ( klass . help_options , list ) ) : <EOL> parser . set_option_table ( klass . user_options + <EOL> fix_help_options ( klass . help_options ) ) <EOL> else : <EOL> parser . set_option_table ( klass . user_options ) <EOL> parser . print_help ( "<STR_LIT>" % klass . __name__ ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( gen_usage ( self . script_name ) ) <EOL> def handle_display_options ( self , option_order ) : <EOL> """<STR_LIT>""" <EOL> from distutils . core import gen_usage <EOL> if self . help_commands : <EOL> self . print_commands ( ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( gen_usage ( self . script_name ) ) <EOL> return <NUM_LIT:1> <EOL> any_display_options = <NUM_LIT:0> <EOL> is_display_option = { } <EOL> for option in self . display_options : <EOL> is_display_option [ option [ <NUM_LIT:0> ] ] = <NUM_LIT:1> <EOL> for ( opt , val ) in option_order : <EOL> if val and is_display_option . get ( opt ) : <EOL> opt = translate_longopt ( opt ) <EOL> value = getattr ( self . metadata , "<STR_LIT>" + opt ) ( ) <EOL> if opt in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> print ( '<STR_LIT:U+002C>' . join ( value ) ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> print ( '<STR_LIT:\n>' . join ( value ) ) <EOL> else : <EOL> print ( value ) <EOL> any_display_options = <NUM_LIT:1> <EOL> return any_display_options <EOL> def print_command_list ( self , commands , header , max_length ) : <EOL> """<STR_LIT>""" <EOL> print ( header + "<STR_LIT::>" ) <EOL> for cmd in commands : <EOL> klass = self . cmdclass . get ( cmd ) <EOL> if not klass : <EOL> klass = self . get_command_class ( cmd ) <EOL> try : <EOL> description = klass . description <EOL> except AttributeError : <EOL> description = "<STR_LIT>" <EOL> print ( "<STR_LIT>" % ( max_length , cmd , description ) ) <EOL> def print_commands ( self ) : <EOL> """<STR_LIT>""" <EOL> import distutils . command <EOL> std_commands = distutils . command . __all__ <EOL> is_std = { } <EOL> for cmd in std_commands : <EOL> is_std [ cmd ] = <NUM_LIT:1> <EOL> extra_commands = [ ] <EOL> for cmd in self . cmdclass . keys ( ) : <EOL> if not is_std . get ( cmd ) : <EOL> extra_commands . append ( cmd ) <EOL> max_length = <NUM_LIT:0> <EOL> for cmd in ( std_commands + extra_commands ) : <EOL> if len ( cmd ) > max_length : <EOL> max_length = len ( cmd ) <EOL> self . print_command_list ( std_commands , <EOL> "<STR_LIT>" , <EOL> max_length ) <EOL> if extra_commands : <EOL> print <EOL> self . print_command_list ( extra_commands , <EOL> "<STR_LIT>" , <EOL> max_length ) <EOL> def get_command_list ( self ) : <EOL> """<STR_LIT>""" <EOL> import distutils . command <EOL> std_commands = distutils . command . __all__ <EOL> is_std = { } <EOL> for cmd in std_commands : <EOL> is_std [ cmd ] = <NUM_LIT:1> <EOL> extra_commands = [ ] <EOL> for cmd in self . cmdclass . keys ( ) : <EOL> if not is_std . get ( cmd ) : <EOL> extra_commands . append ( cmd ) <EOL> rv = [ ] <EOL> for cmd in ( std_commands + extra_commands ) : <EOL> klass = self . cmdclass . get ( cmd ) <EOL> if not klass : <EOL> klass = self . get_command_class ( cmd ) <EOL> try : <EOL> description = klass . description <EOL> except AttributeError : <EOL> description = "<STR_LIT>" <EOL> rv . append ( ( cmd , description ) ) <EOL> return rv <EOL> def get_command_packages ( self ) : <EOL> """<STR_LIT>""" <EOL> pkgs = self . command_packages <EOL> if not isinstance ( pkgs , list ) : <EOL> if pkgs is None : <EOL> pkgs = '<STR_LIT>' <EOL> pkgs = [ pkg . strip ( ) for pkg in pkgs . split ( '<STR_LIT:U+002C>' ) if pkg != '<STR_LIT>' ] <EOL> if "<STR_LIT>" not in pkgs : <EOL> pkgs . insert ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> self . command_packages = pkgs <EOL> return pkgs <EOL> def get_command_class ( self , command ) : <EOL> """<STR_LIT>""" <EOL> klass = self . cmdclass . get ( command ) <EOL> if klass : <EOL> return klass <EOL> for pkgname in self . get_command_packages ( ) : <EOL> module_name = "<STR_LIT>" % ( pkgname , command ) <EOL> klass_name = command <EOL> try : <EOL> __import__ ( module_name ) <EOL> module = sys . modules [ module_name ] <EOL> except ImportError : <EOL> continue <EOL> try : <EOL> klass = getattr ( module , klass_name ) <EOL> except AttributeError : <EOL> raise DistutilsModuleError , "<STR_LIT>" % ( command , klass_name , module_name ) <EOL> self . cmdclass [ command ] = klass <EOL> return klass <EOL> raise DistutilsModuleError ( "<STR_LIT>" % command ) <EOL> def get_command_obj ( self , command , create = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> cmd_obj = self . command_obj . get ( command ) <EOL> if not cmd_obj and create : <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" "<STR_LIT>" % command ) <EOL> klass = self . get_command_class ( command ) <EOL> cmd_obj = self . command_obj [ command ] = klass ( self ) <EOL> self . have_run [ command ] = <NUM_LIT:0> <EOL> options = self . command_options . get ( command ) <EOL> if options : <EOL> self . _set_command_options ( cmd_obj , options ) <EOL> return cmd_obj <EOL> def _set_command_options ( self , command_obj , option_dict = None ) : <EOL> """<STR_LIT>""" <EOL> command_name = command_obj . get_command_name ( ) <EOL> if option_dict is None : <EOL> option_dict = self . get_option_dict ( command_name ) <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" % command_name ) <EOL> for ( option , ( source , value ) ) in option_dict . items ( ) : <EOL> if DEBUG : <EOL> self . announce ( "<STR_LIT>" % ( option , value , <EOL> source ) ) <EOL> try : <EOL> bool_opts = map ( translate_longopt , command_obj . boolean_options ) <EOL> except AttributeError : <EOL> bool_opts = [ ] <EOL> try : <EOL> neg_opt = command_obj . negative_opt <EOL> except AttributeError : <EOL> neg_opt = { } <EOL> try : <EOL> is_string = isinstance ( value , str ) <EOL> if option in neg_opt and is_string : <EOL> setattr ( command_obj , neg_opt [ option ] , not strtobool ( value ) ) <EOL> elif option in bool_opts and is_string : <EOL> setattr ( command_obj , option , strtobool ( value ) ) <EOL> elif hasattr ( command_obj , option ) : <EOL> setattr ( command_obj , option , value ) <EOL> else : <EOL> raise DistutilsOptionError , ( "<STR_LIT>" <EOL> % ( source , command_name , option ) ) <EOL> except ValueError , msg : <EOL> raise DistutilsOptionError , msg <EOL> def reinitialize_command ( self , command , reinit_subcommands = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> from distutils . cmd import Command <EOL> if not isinstance ( command , Command ) : <EOL> command_name = command <EOL> command = self . get_command_obj ( command_name ) <EOL> else : <EOL> command_name = command . get_command_name ( ) <EOL> if not command . finalized : <EOL> return command <EOL> command . initialize_options ( ) <EOL> command . finalized = <NUM_LIT:0> <EOL> self . have_run [ command_name ] = <NUM_LIT:0> <EOL> self . _set_command_options ( command ) <EOL> if reinit_subcommands : <EOL> for sub in command . get_sub_commands ( ) : <EOL> self . reinitialize_command ( sub , reinit_subcommands ) <EOL> return command <EOL> def announce ( self , msg , level = log . INFO ) : <EOL> log . log ( level , msg ) <EOL> def run_commands ( self ) : <EOL> """<STR_LIT>""" <EOL> for cmd in self . commands : <EOL> self . run_command ( cmd ) <EOL> def run_command ( self , command ) : <EOL> """<STR_LIT>""" <EOL> if self . have_run . get ( command ) : <EOL> return <EOL> log . info ( "<STR_LIT>" , command ) <EOL> cmd_obj = self . get_command_obj ( command ) <EOL> cmd_obj . ensure_finalized ( ) <EOL> cmd_obj . run ( ) <EOL> self . have_run [ command ] = <NUM_LIT:1> <EOL> def has_pure_modules ( self ) : <EOL> return len ( self . packages or self . py_modules or [ ] ) > <NUM_LIT:0> <EOL> def has_ext_modules ( self ) : <EOL> return self . ext_modules and len ( self . ext_modules ) > <NUM_LIT:0> <EOL> def has_c_libraries ( self ) : <EOL> return self . libraries and len ( self . libraries ) > <NUM_LIT:0> <EOL> def has_modules ( self ) : <EOL> return self . has_pure_modules ( ) or self . has_ext_modules ( ) <EOL> def has_headers ( self ) : <EOL> return self . headers and len ( self . headers ) > <NUM_LIT:0> <EOL> def has_scripts ( self ) : <EOL> return self . scripts and len ( self . scripts ) > <NUM_LIT:0> <EOL> def has_data_files ( self ) : <EOL> return self . data_files and len ( self . data_files ) > <NUM_LIT:0> <EOL> def is_pure ( self ) : <EOL> return ( self . has_pure_modules ( ) and <EOL> not self . has_ext_modules ( ) and <EOL> not self . has_c_libraries ( ) ) <EOL> class DistributionMetadata : <EOL> """<STR_LIT>""" <EOL> _METHOD_BASENAMES = ( "<STR_LIT:name>" , "<STR_LIT:version>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:url>" , <EOL> "<STR_LIT>" , "<STR_LIT:description>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ) <EOL> def __init__ ( self , path = None ) : <EOL> if path is not None : <EOL> self . read_pkg_file ( open ( path ) ) <EOL> else : <EOL> self . name = None <EOL> self . version = None <EOL> self . author = None <EOL> self . author_email = None <EOL> self . maintainer = None <EOL> self . maintainer_email = None <EOL> self . url = None <EOL> self . license = None <EOL> self . description = None <EOL> self . long_description = None <EOL> self . keywords = None <EOL> self . platforms = None <EOL> self . classifiers = None <EOL> self . download_url = None <EOL> self . provides = None <EOL> self . requires = None <EOL> self . obsoletes = None <EOL> def read_pkg_file ( self , file ) : <EOL> """<STR_LIT>""" <EOL> msg = message_from_file ( file ) <EOL> def _read_field ( name ) : <EOL> value = msg [ name ] <EOL> if value == '<STR_LIT>' : <EOL> return None <EOL> return value <EOL> def _read_list ( name ) : <EOL> values = msg . get_all ( name , None ) <EOL> if values == [ ] : <EOL> return None <EOL> return values <EOL> metadata_version = msg [ '<STR_LIT>' ] <EOL> self . name = _read_field ( '<STR_LIT:name>' ) <EOL> self . version = _read_field ( '<STR_LIT:version>' ) <EOL> self . description = _read_field ( '<STR_LIT>' ) <EOL> self . author = _read_field ( '<STR_LIT>' ) <EOL> self . maintainer = None <EOL> self . author_email = _read_field ( '<STR_LIT>' ) <EOL> self . maintainer_email = None <EOL> self . url = _read_field ( '<STR_LIT>' ) <EOL> self . license = _read_field ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in msg : <EOL> self . download_url = _read_field ( '<STR_LIT>' ) <EOL> else : <EOL> self . download_url = None <EOL> self . long_description = _read_field ( '<STR_LIT:description>' ) <EOL> self . description = _read_field ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in msg : <EOL> self . keywords = _read_field ( '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> self . platforms = _read_list ( '<STR_LIT>' ) <EOL> self . classifiers = _read_list ( '<STR_LIT>' ) <EOL> if metadata_version == '<STR_LIT>' : <EOL> self . requires = _read_list ( '<STR_LIT>' ) <EOL> self . provides = _read_list ( '<STR_LIT>' ) <EOL> self . obsoletes = _read_list ( '<STR_LIT>' ) <EOL> else : <EOL> self . requires = None <EOL> self . provides = None <EOL> self . obsoletes = None <EOL> def write_pkg_info ( self , base_dir ) : <EOL> """<STR_LIT>""" <EOL> pkg_info = open ( os . path . join ( base_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> try : <EOL> self . write_pkg_file ( pkg_info ) <EOL> finally : <EOL> pkg_info . close ( ) <EOL> def write_pkg_file ( self , file ) : <EOL> """<STR_LIT>""" <EOL> version = '<STR_LIT:1.0>' <EOL> if ( self . provides or self . requires or self . obsoletes or <EOL> self . classifiers or self . download_url ) : <EOL> version = '<STR_LIT>' <EOL> self . _write_field ( file , '<STR_LIT>' , version ) <EOL> self . _write_field ( file , '<STR_LIT:Name>' , self . get_name ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_version ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_description ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_url ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_contact ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_contact_email ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , self . get_license ( ) ) <EOL> if self . download_url : <EOL> self . _write_field ( file , '<STR_LIT>' , self . download_url ) <EOL> long_desc = rfc822_escape ( self . get_long_description ( ) ) <EOL> self . _write_field ( file , '<STR_LIT>' , long_desc ) <EOL> keywords = '<STR_LIT:U+002C>' . join ( self . get_keywords ( ) ) <EOL> if keywords : <EOL> self . _write_field ( file , '<STR_LIT>' , keywords ) <EOL> self . _write_list ( file , '<STR_LIT>' , self . get_platforms ( ) ) <EOL> self . _write_list ( file , '<STR_LIT>' , self . get_classifiers ( ) ) <EOL> self . _write_list ( file , '<STR_LIT>' , self . get_requires ( ) ) <EOL> self . _write_list ( file , '<STR_LIT>' , self . get_provides ( ) ) <EOL> self . _write_list ( file , '<STR_LIT>' , self . get_obsoletes ( ) ) <EOL> def _write_field ( self , file , name , value ) : <EOL> file . write ( '<STR_LIT>' % ( name , self . _encode_field ( value ) ) ) <EOL> def _write_list ( self , file , name , values ) : <EOL> for value in values : <EOL> self . _write_field ( file , name , value ) <EOL> def _encode_field ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> if isinstance ( value , unicode ) : <EOL> return value . encode ( PKG_INFO_ENCODING ) <EOL> return str ( value ) <EOL> def get_name ( self ) : <EOL> return self . name or "<STR_LIT>" <EOL> def get_version ( self ) : <EOL> return self . version or "<STR_LIT>" <EOL> def get_fullname ( self ) : <EOL> return "<STR_LIT>" % ( self . get_name ( ) , self . get_version ( ) ) <EOL> def get_author ( self ) : <EOL> return self . _encode_field ( self . author ) or "<STR_LIT>" <EOL> def get_author_email ( self ) : <EOL> return self . author_email or "<STR_LIT>" <EOL> def get_maintainer ( self ) : <EOL> return self . _encode_field ( self . maintainer ) or "<STR_LIT>" <EOL> def get_maintainer_email ( self ) : <EOL> return self . maintainer_email or "<STR_LIT>" <EOL> def get_contact ( self ) : <EOL> return ( self . _encode_field ( self . maintainer ) or <EOL> self . _encode_field ( self . author ) or "<STR_LIT>" ) <EOL> def get_contact_email ( self ) : <EOL> return self . maintainer_email or self . author_email or "<STR_LIT>" <EOL> def get_url ( self ) : <EOL> return self . url or "<STR_LIT>" <EOL> def get_license ( self ) : <EOL> return self . license or "<STR_LIT>" <EOL> get_licence = get_license <EOL> def get_description ( self ) : <EOL> return self . _encode_field ( self . description ) or "<STR_LIT>" <EOL> def get_long_description ( self ) : <EOL> return self . _encode_field ( self . long_description ) or "<STR_LIT>" <EOL> def get_keywords ( self ) : <EOL> return self . keywords or [ ] <EOL> def get_platforms ( self ) : <EOL> return self . platforms or [ "<STR_LIT>" ] <EOL> def get_classifiers ( self ) : <EOL> return self . classifiers or [ ] <EOL> def get_download_url ( self ) : <EOL> return self . download_url or "<STR_LIT>" <EOL> def get_requires ( self ) : <EOL> return self . requires or [ ] <EOL> def set_requires ( self , value ) : <EOL> import distutils . versionpredicate <EOL> for v in value : <EOL> distutils . versionpredicate . VersionPredicate ( v ) <EOL> self . requires = value <EOL> def get_provides ( self ) : <EOL> return self . provides or [ ] <EOL> def set_provides ( self , value ) : <EOL> value = [ v . strip ( ) for v in value ] <EOL> for v in value : <EOL> import distutils . versionpredicate <EOL> distutils . versionpredicate . split_provision ( v ) <EOL> self . provides = value <EOL> def get_obsoletes ( self ) : <EOL> return self . obsoletes or [ ] <EOL> def set_obsoletes ( self , value ) : <EOL> import distutils . versionpredicate <EOL> for v in value : <EOL> distutils . versionpredicate . VersionPredicate ( v ) <EOL> self . obsoletes = value <EOL> def fix_help_options ( options ) : <EOL> """<STR_LIT>""" <EOL> new_options = [ ] <EOL> for help_tuple in options : <EOL> new_options . append ( help_tuple [ <NUM_LIT:0> : <NUM_LIT:3> ] ) <EOL> return new_options </s>
