<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import sys , os , string <EOL> from types import * <EOL> from glob import glob <EOL> from distutils . core import Command <EOL> from distutils import dir_util , dep_util , file_util , archive_util <EOL> from distutils . text_file import TextFile <EOL> from distutils . errors import * <EOL> from distutils . filelist import FileList <EOL> from distutils import log <EOL> def show_formats ( ) : <EOL> """<STR_LIT>""" <EOL> from distutils . fancy_getopt import FancyGetopt <EOL> from distutils . archive_util import ARCHIVE_FORMATS <EOL> formats = [ ] <EOL> for format in ARCHIVE_FORMATS . keys ( ) : <EOL> formats . append ( ( "<STR_LIT>" + format , None , <EOL> ARCHIVE_FORMATS [ format ] [ <NUM_LIT:2> ] ) ) <EOL> formats . sort ( ) <EOL> pretty_printer = FancyGetopt ( formats ) <EOL> pretty_printer . print_help ( <EOL> "<STR_LIT>" ) <EOL> class sdist ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:t>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:m>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:o>' , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:f>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:k>' , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> help_options = [ <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" , show_formats ) , <EOL> ] <EOL> negative_opt = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> default_format = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def initialize_options ( self ) : <EOL> self . template = None <EOL> self . manifest = None <EOL> self . use_defaults = <NUM_LIT:1> <EOL> self . prune = <NUM_LIT:1> <EOL> self . manifest_only = <NUM_LIT:0> <EOL> self . force_manifest = <NUM_LIT:0> <EOL> self . formats = None <EOL> self . keep_temp = <NUM_LIT:0> <EOL> self . dist_dir = None <EOL> self . archive_files = None <EOL> def finalize_options ( self ) : <EOL> if self . manifest is None : <EOL> self . manifest = "<STR_LIT>" <EOL> if self . template is None : <EOL> self . template = "<STR_LIT>" <EOL> self . ensure_string_list ( '<STR_LIT>' ) <EOL> if self . formats is None : <EOL> try : <EOL> self . formats = [ self . default_format [ os . name ] ] <EOL> except KeyError : <EOL> raise DistutilsPlatformError , "<STR_LIT>" + "<STR_LIT>" % os . name <EOL> bad_format = archive_util . check_archive_formats ( self . formats ) <EOL> if bad_format : <EOL> raise DistutilsOptionError , "<STR_LIT>" % bad_format <EOL> if self . dist_dir is None : <EOL> self . dist_dir = "<STR_LIT>" <EOL> def run ( self ) : <EOL> self . filelist = FileList ( ) <EOL> self . check_metadata ( ) <EOL> self . get_file_list ( ) <EOL> if self . manifest_only : <EOL> return <EOL> self . make_distribution ( ) <EOL> def check_metadata ( self ) : <EOL> """<STR_LIT>""" <EOL> metadata = self . distribution . metadata <EOL> missing = [ ] <EOL> for attr in ( '<STR_LIT:name>' , '<STR_LIT:version>' , '<STR_LIT:url>' ) : <EOL> if not ( hasattr ( metadata , attr ) and getattr ( metadata , attr ) ) : <EOL> missing . append ( attr ) <EOL> if missing : <EOL> self . warn ( "<STR_LIT>" + <EOL> string . join ( missing , "<STR_LIT:U+002CU+0020>" ) ) <EOL> if metadata . author : <EOL> if not metadata . author_email : <EOL> self . warn ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> elif metadata . maintainer : <EOL> if not metadata . maintainer_email : <EOL> self . warn ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . warn ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> def get_file_list ( self ) : <EOL> """<STR_LIT>""" <EOL> template_exists = os . path . isfile ( self . template ) <EOL> if template_exists : <EOL> template_newer = dep_util . newer ( self . template , self . manifest ) <EOL> self . debug_print ( "<STR_LIT>" % <EOL> ( self . distribution . script_name , self . manifest ) ) <EOL> setup_newer = dep_util . newer ( self . distribution . script_name , <EOL> self . manifest ) <EOL> manifest_outofdate = ( template_exists and <EOL> ( template_newer or setup_newer ) ) <EOL> force_regen = self . force_manifest or self . manifest_only <EOL> manifest_exists = os . path . isfile ( self . manifest ) <EOL> neither_exists = ( not template_exists and not manifest_exists ) <EOL> if manifest_outofdate or neither_exists or force_regen : <EOL> if not template_exists : <EOL> self . warn ( ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) % <EOL> self . template ) <EOL> self . filelist . findall ( ) <EOL> if self . use_defaults : <EOL> self . add_defaults ( ) <EOL> if template_exists : <EOL> self . read_template ( ) <EOL> if self . prune : <EOL> self . prune_file_list ( ) <EOL> self . filelist . sort ( ) <EOL> self . filelist . remove_duplicates ( ) <EOL> self . write_manifest ( ) <EOL> else : <EOL> self . read_manifest ( ) <EOL> def add_defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> standards = [ ( '<STR_LIT>' , '<STR_LIT>' ) , self . distribution . script_name ] <EOL> for fn in standards : <EOL> if type ( fn ) is TupleType : <EOL> alts = fn <EOL> got_it = <NUM_LIT:0> <EOL> for fn in alts : <EOL> if os . path . exists ( fn ) : <EOL> got_it = <NUM_LIT:1> <EOL> self . filelist . append ( fn ) <EOL> break <EOL> if not got_it : <EOL> self . warn ( "<STR_LIT>" + <EOL> string . join ( alts , '<STR_LIT:U+002CU+0020>' ) ) <EOL> else : <EOL> if os . path . exists ( fn ) : <EOL> self . filelist . append ( fn ) <EOL> else : <EOL> self . warn ( "<STR_LIT>" % fn ) <EOL> optional = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for pattern in optional : <EOL> files = filter ( os . path . isfile , glob ( pattern ) ) <EOL> if files : <EOL> self . filelist . extend ( files ) <EOL> if self . distribution . has_pure_modules ( ) : <EOL> build_py = self . get_finalized_command ( '<STR_LIT>' ) <EOL> self . filelist . extend ( build_py . get_source_files ( ) ) <EOL> if self . distribution . has_ext_modules ( ) : <EOL> build_ext = self . get_finalized_command ( '<STR_LIT>' ) <EOL> self . filelist . extend ( build_ext . get_source_files ( ) ) <EOL> if self . distribution . has_c_libraries ( ) : <EOL> build_clib = self . get_finalized_command ( '<STR_LIT>' ) <EOL> self . filelist . extend ( build_clib . get_source_files ( ) ) <EOL> if self . distribution . has_scripts ( ) : <EOL> build_scripts = self . get_finalized_command ( '<STR_LIT>' ) <EOL> self . filelist . extend ( build_scripts . get_source_files ( ) ) <EOL> def read_template ( self ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" , self . template ) <EOL> template = TextFile ( self . template , <EOL> strip_comments = <NUM_LIT:1> , <EOL> skip_blanks = <NUM_LIT:1> , <EOL> join_lines = <NUM_LIT:1> , <EOL> lstrip_ws = <NUM_LIT:1> , <EOL> rstrip_ws = <NUM_LIT:1> , <EOL> collapse_join = <NUM_LIT:1> ) <EOL> while <NUM_LIT:1> : <EOL> line = template . readline ( ) <EOL> if line is None : <EOL> break <EOL> try : <EOL> self . filelist . process_template_line ( line ) <EOL> except DistutilsTemplateError , msg : <EOL> self . warn ( "<STR_LIT>" % ( template . filename , <EOL> template . current_line , <EOL> msg ) ) <EOL> def prune_file_list ( self ) : <EOL> """<STR_LIT>""" <EOL> build = self . get_finalized_command ( '<STR_LIT>' ) <EOL> base_dir = self . distribution . get_fullname ( ) <EOL> self . filelist . exclude_pattern ( None , prefix = build . build_base ) <EOL> self . filelist . exclude_pattern ( None , prefix = base_dir ) <EOL> self . filelist . exclude_pattern ( r'<STR_LIT>' , is_regex = <NUM_LIT:1> ) <EOL> def write_manifest ( self ) : <EOL> """<STR_LIT>""" <EOL> self . execute ( file_util . write_file , <EOL> ( self . manifest , self . filelist . files ) , <EOL> "<STR_LIT>" % self . manifest ) <EOL> def read_manifest ( self ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" , self . manifest ) <EOL> manifest = open ( self . manifest ) <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> line = manifest . readline ( ) <EOL> if line == '<STR_LIT>' : <EOL> break <EOL> if line [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' : <EOL> line = line [ <NUM_LIT:0> : - <NUM_LIT:1> ] <EOL> self . filelist . append ( line ) <EOL> finally : <EOL> manifest . close ( ) <EOL> def make_release_tree ( self , base_dir , files ) : <EOL> """<STR_LIT>""" <EOL> self . mkpath ( base_dir ) <EOL> dir_util . create_tree ( base_dir , files , dry_run = self . dry_run ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> link = '<STR_LIT>' <EOL> msg = "<STR_LIT>" % base_dir <EOL> else : <EOL> link = None <EOL> msg = "<STR_LIT>" % base_dir <EOL> if not files : <EOL> log . warn ( "<STR_LIT>" ) <EOL> else : <EOL> log . info ( msg ) <EOL> for file in files : <EOL> if not os . path . isfile ( file ) : <EOL> log . warn ( "<STR_LIT>" % file ) <EOL> else : <EOL> dest = os . path . join ( base_dir , file ) <EOL> self . copy_file ( file , dest , link = link ) <EOL> self . distribution . metadata . write_pkg_info ( base_dir ) <EOL> def make_distribution ( self ) : <EOL> """<STR_LIT>""" <EOL> base_dir = self . distribution . get_fullname ( ) <EOL> base_name = os . path . join ( self . dist_dir , base_dir ) <EOL> self . make_release_tree ( base_dir , self . filelist . files ) <EOL> archive_files = [ ] <EOL> for fmt in self . formats : <EOL> file = self . make_archive ( base_name , fmt , base_dir = base_dir ) <EOL> archive_files . append ( file ) <EOL> self . distribution . dist_files . append ( ( '<STR_LIT>' , '<STR_LIT>' , file ) ) <EOL> self . archive_files = archive_files <EOL> if not self . keep_temp : <EOL> dir_util . remove_tree ( base_dir , dry_run = self . dry_run ) <EOL> def get_archive_files ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . archive_files </s>
