ó
è¾bc           @   s  d  Z  d Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z m Z m Z m Z d d l m Z d d	 l m Z m Z m Z d d
 l m Z d d l
 m Z d d l m Z d „  Z d e	 f d „  ƒ  YZ d S(   sa   distutils.command.sdist

Implements the Distutils 'sdist' command (create a source distribution).s   $Id$iÿÿÿÿN(   t   glob(   t   warn(   t   Command(   t   dir_utilt   dep_utilt	   file_utilt   archive_util(   t   TextFile(   t   DistutilsPlatformErrort   DistutilsOptionErrort   DistutilsTemplateError(   t   FileList(   t   log(   t   convert_pathc          C   s€   d d l  m }  d d l m } g  } x6 | j ƒ  D]( } | j d | d | | d f ƒ q3 W| j ƒ  |  | ƒ j d ƒ d S(   so   Print all possible values for the 'formats' option (used by
    the "--help-formats" command-line option).
    iÿÿÿÿ(   t   FancyGetopt(   t   ARCHIVE_FORMATSs   formats=i   s.   List of available source distribution formats:N(	   t   distutils.fancy_getoptR   t   distutils.archive_utilR   t   keyst   appendt   Nonet   sortt
   print_help(   R   R   t   formatst   format(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   show_formats   s    
t   sdistc           B   s6  e  Z d  Z d „  Z d< d= d? d@ dA dB dC dD dE d d d d f dF dG dH dI g Z d d d d d d g Z d' d> d( e f g Z i d d
 6d d 6Z	 i d) d* 6d+ d, 6Z
 d- e f g Z d. „  Z d/ „  Z d0 „  Z d1 „  Z d2 „  Z d3 „  Z d4 „  Z d5 „  Z d6 „  Z d7 „  Z d8 „  Z d9 „  Z d: „  Z d; „  Z RS(J   s6   create a source distribution (tarball, zip file, etc.)c         C   s   |  j  S(   sY   Callable used for the check sub-command.

        Placed here so user_options can view it(   t   metadata_check(   t   self(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   checking_metadata(   s    s	   template=t   ts5   name of manifest template file [default: MANIFEST.in]s	   manifest=t   ms)   name of manifest file [default: MANIFEST]s   use-defaultssR   include the default file set in the manifest [default; disable with --no-defaults]s   no-defaultss"   don't include the default file sett   prunes‰   specifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune]s   no-prunes$   don't automatically exclude anythings   manifest-onlyt   osE   just regenerate the manifest and then stop (implies --force-manifest)s   force-manifestt   fsk   forcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.s   formats=s6   formats for source distribution (comma-separated list)s	   keep-tempt   ks1   keep the distribution tree around after creating s   archive file(s)s	   dist-dir=t   dsF   directory to put the source distribution archive(s) in [default: dist]s   metadata-checks[   Ensure that all required elements of meta-data are supplied. Warn if any missing. [default]s   owner=t   us@   Owner name used when creating a tar file [default: current user]s   group=t   gsA   Group name used when creating a tar file [default: current group]s   help-formatss#   list available distribution formatst   gztart   posixt   zipt   ntt   checkc         C   sy   d  |  _ d  |  _ d |  _ d |  _ d |  _ d |  _ d  |  _ d |  _ d  |  _	 d  |  _
 d |  _ d  |  _ d  |  _ d  S(   Ni   i    (   R   t   templatet   manifestt   use_defaultsR    t   manifest_onlyt   force_manifestR   t	   keep_tempt   dist_dirt   archive_filesR   t   ownert   group(   R   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   initialize_optionsf   s    												c         C   sÞ   |  j  d  k r d |  _  n  |  j d  k r6 d |  _ n  |  j d ƒ |  j d  k r— y |  j t j g |  _ Wq— t k
 r“ t	 d d t j ‚ q— Xn  t
 j |  j ƒ } | r¿ t d | ‚ n  |  j d  k rÚ d |  _ n  d  S(   Nt   MANIFESTs   MANIFEST.inR   s.   don't know how to create source distributions s   on platform %ss   unknown archive format '%s't   dist(   R-   R   R,   t   ensure_string_listR   t   default_formatt   ost   namet   KeyErrorR   R   t   check_archive_formatsR	   R2   (   R   t
   bad_format(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   finalize_options}   s$    c         C   sU   t  ƒ  |  _ x! |  j ƒ  D] } |  j | ƒ q W|  j ƒ  |  j rG d  S|  j ƒ  d  S(   N(   R   t   filelistt   get_sub_commandst   run_commandt   get_file_listR/   t   make_distribution(   R   t   cmd_name(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   run”   s    
	c         C   s7   t  d t ƒ |  j j d ƒ } | j ƒ  | j ƒ  d S(   s   Deprecated API.sa   distutils.command.sdist.check_metadata is deprecated,               use the check command insteadR+   N(   R   t   PendingDeprecationWarningt   distributiont   get_command_objt   ensure_finalizedRG   (   R   R+   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   check_metadataª   s
    

c         C   så   t  j j |  j ƒ } | rP |  j ƒ  rP |  j ƒ  |  j j ƒ  |  j j ƒ  d S| sq |  j	 d d |  j ƒ n  |  j j
 ƒ  |  j r” |  j ƒ  n  | r§ |  j ƒ  n  |  j r½ |  j ƒ  n  |  j j ƒ  |  j j ƒ  |  j ƒ  d S(   sC  Figure out the list of files to include in the source
        distribution, and put it in 'self.filelist'.  This might involve
        reading the manifest template (and writing the manifest), or just
        reading the manifest, or just using the default file set -- it all
        depends on the user's options.
        Ns&   manifest template '%s' does not exist s   (using default file list)(   R;   t   patht   isfileR,   t   _manifest_is_not_generatedt   read_manifestRA   R   t   remove_duplicatesR   t   findallR.   t   add_defaultst   read_templateR    t   prune_file_listt   write_manifest(   R   t   template_exists(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRD   ²   s(    
			c         C   s  d |  j  j g } xÅ | D]½ } t | t ƒ r  | } d } x: | D]2 } t j j | ƒ rA d } |  j j | ƒ PqA qA W| sÖ |  j	 d t
 j | d ƒ ƒ qÖ q t j j | ƒ rÅ |  j j | ƒ q |  j	 d | ƒ q Wd d	 g } xB | D]: } t t j j t | ƒ ƒ } | rí |  j j | ƒ qí qí W|  j d
 ƒ } |  j  j ƒ  rb|  j j | j ƒ  ƒ n  xM | j D]B \ }	 }
 } } x- | D]% } |  j j t j j |
 | ƒ ƒ q…WqlW|  j  j ƒ  rlx¨ |  j  j D]— } t | t ƒ rt | ƒ } t j j | ƒ re|  j j | ƒ qeqÎ| \ } } x? | D]7 } t | ƒ } t j j | ƒ r*|  j j | ƒ q*q*WqÎWn  |  j  j ƒ  r£|  j d ƒ } |  j j | j ƒ  ƒ n  |  j  j ƒ  rÚ|  j d ƒ } |  j j | j ƒ  ƒ n  |  j  j ƒ  r|  j d ƒ } |  j j | j ƒ  ƒ n  d S(   s9  Add all the default files to self.filelist:
          - README or README.txt
          - setup.py
          - test/test*.py
          - all pure Python modules mentioned in setup script
          - all files pointed by package_data (build_py)
          - all files defined in data_files.
          - all files defined as scripts.
          - all C sources listed as part of extensions or C libraries
            in the setup script (doesn't catch C headers!)
        Warns if (README or README.txt) or setup.py are missing; everything
        else is optional.
        t   READMEs
   README.txti    i   s,   standard file not found: should have one of s   , s   standard file '%s' not founds   test/test*.pys	   setup.cfgt   build_pyt	   build_extt
   build_clibt   build_scriptsN(   RX   s
   README.txt(   RI   t   script_namet
   isinstancet   tupleR;   RM   t   existsRA   R   R   t   stringt   joint   filterRN   R    t   extendt   get_finalized_commandt   has_pure_modulest   get_source_filest
   data_filest   has_data_filest   strR   t   has_ext_modulest   has_c_librariest   has_scripts(   R   t	   standardst   fnt   altst   got_itt   optionalt   patternt   filesRY   t   pkgt   src_dirt	   build_dirt	   filenamest   filenamet   itemt   dirnameR"   RZ   R[   R\   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRS   Ú   s^    	'c         C   sÏ   t  j d |  j ƒ t |  j d d d d d d d d d d d d ƒ} zw xp | j ƒ  } | d
 k rh Pn  y |  j j | ƒ WqL t t	 f k
 r· } |  j
 d	 | j | j | f ƒ qL XqL WWd
 | j ƒ  Xd
 S(   sÈ   Read and parse manifest template file named by self.template.

        (usually "MANIFEST.in") The parsing and processing is done by
        'self.filelist', which updates itself accordingly.
        s   reading manifest template '%s't   strip_commentsi   t   skip_blankst
   join_linest	   lstrip_wst	   rstrip_wst   collapse_joins   %s, line %d: %sN(   R   t   infoR,   R   t   readlineR   RA   t   process_template_lineR
   t
   ValueErrorR   Ry   t   current_linet   close(   R   R,   t   linet   msg(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRT   ,  s(    	c         C   s¼   |  j  d ƒ } |  j j ƒ  } |  j j d d | j ƒ|  j j d d | ƒt j d k re d } n d } d d d d	 d
 d d g } d | d j	 | ƒ | f } |  j j | d d ƒd S(   sv  Prune off branches that might slip into the file list as created
        by 'read_template()', but really don't belong there:
          * the build tree (typically "build")
          * the release tree itself (only an issue if we ran "sdist"
            previously with --keep-temp, or it aborted)
          * any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
        t   buildt   prefixt   win32s   /|\\t   /t   RCSt   CVSs   \.svns   \.hgs   \.gits   \.bzrt   _darcss   (^|%s)(%s)(%s).*t   |t   is_regexi   N(
   Re   RI   t   get_fullnameRA   t   exclude_patternR   t
   build_baset   syst   platformRb   (   R   RŠ   t   base_dirt   sepst   vcs_dirst   vcs_ptrn(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRU   M  s    		c         C   sk   |  j  ƒ  r$ t j d |  j ƒ d S|  j j } | j d d ƒ |  j t j	 |  j | f d |  j ƒ d S(   s²   Write the file list in 'self.filelist' (presumably as filled in
        by 'add_defaults()' and 'read_template()') to the manifest file
        named by 'self.manifest'.
        s5   not writing to manually maintained manifest file '%s'Ni    s*   # file GENERATED by distutils, do NOT edits   writing manifest file '%s'(
   RO   R   R‚   R-   RA   Rt   t   insertt   executeR   t
   write_file(   R   t   content(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRV   g  s    	c         C   sS   t  j j |  j ƒ s t St |  j d ƒ } z | j ƒ  } Wd  | j ƒ  X| d k S(   Nt   rUs+   # file GENERATED by distutils, do NOT edit
(   R;   RM   RN   R-   t   Falset   openRƒ   R‡   (   R   t   fpt
   first_line(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRO   v  s    c         C   sy   t  j d |  j ƒ t |  j ƒ } xF | D]> } | j ƒ  } | j d ƒ s) | rW q) n  |  j j | ƒ q) W| j ƒ  d S(   sª   Read the manifest file (named by 'self.manifest') and use it to
        fill in 'self.filelist', the list of files to include in the source
        distribution.
        s   reading manifest file '%s't   #N(	   R   R‚   R-   R¢   t   stript
   startswithRA   R   R‡   (   R   R-   Rˆ   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRP   ‚  s    c         C   sô   |  j  | ƒ t j | | d |  j ƒt t d ƒ rH d } d | } n d } d | } | sn t j d ƒ n t j	 | ƒ x_ | D]W } t j
 j | ƒ s® t j d | ƒ q‚ t j
 j | | ƒ } |  j | | d | ƒq‚ W|  j j j | ƒ d S(	   sÆ  Create the directory tree that will become the source
        distribution archive.  All directories implied by the filenames in
        'files' are created under 'base_dir', and then we hard link or copy
        (if hard linking is unavailable) those files into place.
        Essentially, this duplicates the developer's source tree, but in a
        directory named after the distribution, containing only the files
        to be distributed.
        t   dry_runt   linkt   hards   making hard links in %s...s   copying files to %s...s)   no files to distribute -- empty manifest?s#   '%s' not a regular file -- skippingN(   t   mkpathR   t   create_treeR¨   t   hasattrR;   R   R   R   R‚   RM   RN   Rb   t	   copy_fileRI   t   metadatat   write_pkg_info(   R   R˜   Rt   R©   R‰   t   filet   dest(    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   make_release_tree‘  s     	
c      
   C   s  |  j  j ƒ  } t j j |  j | ƒ } |  j | |  j j ƒ g  } d |  j	 k r} |  j	 j
 |  j	 j |  j	 j d ƒ ƒ ƒ n  xd |  j	 D]Y } |  j | | d | d |  j d |  j ƒ} | j
 | ƒ |  j  j j
 d d | f ƒ q‡ W| |  _ |  j st j | d |  j ƒn  d S(	   s¯  Create the source distribution(s).  First, we create the release
        tree with 'make_release_tree()'; then, we create all required
        archive files (according to 'self.formats') from the release tree.
        Finally, we clean up by blowing away the release tree (unless
        'self.keep_temp' is true).  The list of archive files created is
        stored so it can be retrieved later by 'get_archive_files()'.
        t   tarR˜   R4   R5   R   t    R¨   N(   RI   R“   R;   RM   Rb   R2   R³   RA   Rt   R   R   t   popt   indext   make_archiveR4   R5   t
   dist_filesR3   R1   R   t   remove_treeR¨   (   R   R˜   t	   base_nameR3   t   fmtR±   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyRE   »  s    
+ 		c         C   s   |  j  S(   sz   Return the list of archive files created when the command
        was run, or None if the command hasn't run yet.
        (   R3   (   R   (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   get_archive_filesÙ  s    (   s	   template=R   s5   name of manifest template file [default: MANIFEST.in](   s	   manifest=R   s)   name of manifest file [default: MANIFEST]N(   s   use-defaultsNsR   include the default file set in the manifest [default; disable with --no-defaults](   s   no-defaultsNs"   don't include the default file set(   R    Ns‰   specifically exclude files/directories that should not be distributed (build tree, RCS/CVS dirs, etc.) [default; disable with --no-prune](   s   no-pruneNs$   don't automatically exclude anything(   s   manifest-onlyR!   sE   just regenerate the manifest and then stop (implies --force-manifest)(   s   force-manifestR"   sk   forcibly regenerate the manifest and carry on as usual. Deprecated: now the manifest is always regenerated.(   s   formats=Ns6   formats for source distribution (comma-separated list)(   s	   dist-dir=R$   sF   directory to put the source distribution archive(s) in [default: dist](   s   metadata-checkNs[   Ensure that all required elements of meta-data are supplied. Warn if any missing. [default](   s   owner=R%   s@   Owner name used when creating a tar file [default: current user](   s   group=R&   sA   Group name used when creating a tar file [default: current group](   t   __name__t
   __module__t   descriptionR   R   t   user_optionst   boolean_optionsR   t   help_optionst   negative_optR:   t   sub_commandsR6   R@   RG   RL   RD   RS   RT   RU   RV   RO   RP   R³   RE   R½   (    (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyR   $   sn   	             	



					(	R	!					*	(   t   __doc__t   __revision__R;   Ra   R–   R    t   warningsR   t   distutils.coreR   t	   distutilsR   R   R   R   t   distutils.text_fileR   t   distutils.errorsR   R	   R
   t   distutils.filelistR   R   t   distutils.utilR   R   R   (    (    (    s-   /usr/lib/python2.7/distutils/command/sdist.pyt   <module>   s   "	