ó
@K7]c           @   sC  d  Z  d d l Z d d l m Z m Z m Z m Z m Z d d l Z d d l	 Z	 d d l
 Z
 e rm d Z n  e e ƒ Z e e	 j ƒ Z e	 j d k r¯ e e d ƒ Z d Z n  e e d ƒ Z d e	 j d	  Z g  Z d
 Z d „  Z d „  Z e	 j d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z  e! d k r?e  ƒ  n  d S(   sZ   
This is code that is added to noarch Python packages. See
conda_build/noarch_python.py.

iÿÿÿÿN(   t   dirnamet   existst   isdirt   joint   normpatht   win32t   Scriptss   Lib/site-packagest   bins   lib/python%s/site-packagesi   s(   ^(#!(?:[ ]*)(/(?:\\ |[^ \n\r\t])*)(.*))$c         C   sB   y t  j |  | ƒ Wn' t t f k
 r= t j |  | ƒ n Xd  S(   N(   t   ost   linkt   OSErrort   AttributeErrort   shutilt   copy2(   t   srct   dst(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   _link&   s    c         C   s)   y t  j |  ƒ Wn t k
 r$ n Xd  S(   N(   R   t   unlinkR
   (   t   path(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   _unlink.   s    c         C   sP   | d d k r |  d S|  j  d d ƒ \ } } d | | d  | d | d f S(   Ni    i   t   ct   /i   s"   %s/__pycache__/%s.cpython-%d%d.pyciýÿÿÿ(   t   rsplit(   t   ft   version_infot   dnt   fn(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   pyc_f5   s
    c         C   sÉ   xÂ | D]º } t  t |  | ƒ } t  t | | ƒ } t | ƒ } t | ƒ sY t j | ƒ n  t | ƒ rr t | ƒ n  t	 | | ƒ d | | f } t
 j | ƒ | j d ƒ r t
 j t | ƒ ƒ q q Wd  S(   Ns   %s/%ss   .py(   R   t   THIS_DIRt   PREFIXR    R   R   t   makedirsR   R   R   t   FILESt   appendt   endswithR   (   t   src_roott   dst_roott   filesR   R   R   t   dst_dir(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt
   link_files=   s    c         C   sÛ   t  |  d ƒ r |  j ƒ  }  n  t j t |  t j ƒ } | r¹ | j ƒ  \ } } } t | ƒ d k r¹ | j d ƒ j	 d ƒ d } d | | j d ƒ f } |  j
 | | j d ƒ ƒ }  q¹ n  t  |  d ƒ r× |  j ƒ  }  n  |  S(   Nt   encodei   s   utf-8R   iÿÿÿÿs   #!/usr/bin/env %s%st   decode(   t   hasattrR'   t   ret   matcht   SHEBANG_REGEXt	   MULTILINEt   groupst   lenR(   t   splitt   replace(   t   datat   shebang_matcht   whole_shebangt
   executablet   optionst   executable_namet   new_shebang(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   replace_long_shebangN   s    !c      	   C   s"  t  t d |  ƒ } t  t |  ƒ } t j d k r‘ t j | | d ƒ t j d |  ƒ t j t  t d d t	 j
 ƒ | d ƒ t j d |  ƒ n t | ƒ  } | j ƒ  } Wd  QXt | d	 ƒ : } t d
 t t j ƒ ƒ } | j | ƒ | j | ƒ Wd  QXt j | d ƒ t j d |  ƒ d  S(   Ns   python-scriptsR   s
   -script.pys   Scripts/%s-script.pys
   cli-%d.exei   s   .exes   Scripts/%s.exet   ws   #!%s
iý  s   bin/%s(   R   R   t   BIN_DIRt   syst   platformR   R   R   R    t   tuplet   __itemsize__t   opent   readR9   R   R5   t   writeR   t   chmod(   R   R   R   t   fiR2   t   fot   shebang(    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   create_script^   s"    c         C   sE   |  s
 d  St  t ƒ s& t j t ƒ n  x |  D] } t | ƒ q- Wd  S(   N(   R   R;   R   t   mkdirRG   (   R$   R   (    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   create_scriptss   s    c          C   sˆ   t  t d ƒ t d t t d ƒ t d d t d ƒ t t t d d t d ƒ d ƒ ) }  x t D] } |  j d | ƒ qc WWd  QXd  S(	   Ns   python-scriptss   site-packagest   Exampless
   conda-metas   %s.filest   distR:   s   %s
(	   RI   t   DATAR&   t   SITE_PACKAGESR@   R   R   R   RB   (   RE   R   (    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   main|   s    t   __main__("   t   __doc__R   t   os.pathR    R   R   R   R   R*   R<   R   t   Falset   NoneRL   t   __file__R   t   prefixR   R=   R;   RM   t   versionR   R,   R   R   R   R   R&   R9   RG   RI   RN   t   __name__(    (    (    s0   lib/python2.7/site-packages/conda_build/_link.pyt   <module>   s4   (										