ó
è¾bc           @   s   d  Z  d 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 d d l m Z e j d	 ƒ Z d
 e f d „  ƒ  YZ d S(   sR   distutils.command.build_scripts

Implements the Distutils 'build_scripts' command.s   $Id$iÿÿÿÿN(   t   ST_MODE(   t   Command(   t   newer(   t   convert_path(   t   logs   ^#!.*python[0-9.]*([ 	].*)?$t   build_scriptsc           B   sS   e  Z d  Z d d d g Z d g Z d
 „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s(   "build" scripts (copy and fixup #! line)s
   build-dir=t   ds   directory to "build" (copy) tot   forcet   fs1   forcibly build everything (ignore file timestampss   executable=t   es*   specify final destination interpreter pathc         C   s1   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Nonet	   build_dirt   scriptsR   t
   executablet   outfiles(   t   self(    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyt   initialize_options   s
    				c         C   s)   |  j  d d d d ƒ |  j j |  _ d  S(	   Nt   buildR   R   R   R   (   R   R   (   R   R   (   R   R   (   t   set_undefined_optionst   distributionR   (   R   (    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyt   finalize_options%   s
    	c         C   s   |  j  S(   N(   R   (   R   (    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyt   get_source_files,   s    c         C   s   |  j  s d  S|  j ƒ  d  S(   N(   R   t   copy_scripts(   R   (    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyt   run/   s    	c      	   C   sß  t  d ƒ } |  j |  j ƒ g  } x|  j D]} d } t | ƒ } t j j |  j t j j | ƒ ƒ } | j	 | ƒ |  j
 r¥ t | | ƒ r¥ t j d | ƒ q, n  y t | d ƒ } Wn& t k
 rà |  j s× ‚  n  d } n] X| j ƒ  } | s
|  j d | ƒ q, n  t j | ƒ } | r=d } | j d ƒ p7d }	 n  | rt j d | |  j ƒ |  j st | d	 ƒ }
 | j ƒ  sš|
 j d
 |  j |	 f ƒ nK |
 j d
 t j j | j d ƒ d | j d ƒ | j d ƒ f ƒ |	 f ƒ |
 j | j ƒ  ƒ |
 j ƒ  n  | r>| j ƒ  q>q, | r.| j ƒ  n  |  j | | ƒ q, Wt j  d k rÛx‡ | D]| } |  j rzt j d | ƒ qXt j! | ƒ t" d @} | d Bd @} | | k rXt j d | | | ƒ t j# | | ƒ qXqXWn  d S(   s"  Copy each script listed in 'self.scripts'; if it's marked as a
        Python script in the Unix way (first line matches 'first_line_re',
        ie. starts with "\#!" and contains "python"), then adjust the first
        line to refer to the current Python interpreter as we copy.
        t	   sysconfigi    s   not copying %s (up-to-date)t   rs   %s is an empty file (skipping)i   t    s   copying and adjusting %s -> %st   ws   #!%s%s
t   BINDIRs
   python%s%st   VERSIONt   EXEt   posixs   changing mode of %siÿ  im  s!   changing mode of %s from %o to %oN($   t
   __import__t   mkpathR   R   R   t   ost   patht   joint   basenamet   appendR   R   R   t   debugt   opent   IOErrort   dry_runR
   t   readlinet   warnt   first_line_ret   matcht   groupt   infot   is_python_buildt   writeR   t   get_config_vart
   writelinest	   readlinest   closet	   copy_filet   namet   statR    t   chmod(   R   t
   _sysconfigR   t   scriptt   adjustt   outfileR   t
   first_lineR.   t   post_interpt   outft   filet   oldmodet   newmode(    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyR   5   sr    $	

						(   s
   build-dir=R   s   directory to "build" (copy) to(   R   R   s1   forcibly build everything (ignore file timestamps(   s   executable=R	   s*   specify final destination interpreter path(
   t   __name__t
   __module__t   descriptiont   user_optionst   boolean_optionsR   R   R   R   R   (    (    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyR      s   						(   t   __doc__t   __revision__R"   t   reR9   R    t   distutils.coreR   t   distutils.dep_utilR   t   distutils.utilR   t	   distutilsR   t   compileR-   R   (    (    (    s5   /usr/lib/python2.7/distutils/command/build_scripts.pyt   <module>   s   