ó
@K7]c           @   sË   d  d l  Z  d  d l Z d  d l Z d  d l 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 e j j d ƒ Z d „  Z d „  Z d „  Z d „  Z d d „ Z d	 „  Z d S(
   iÿÿÿÿN(   t   basenamet   dirnamet   isdirt   joint   isfilet   winc         C   s    t  |  ƒ s t j |  ƒ n  d  S(   N(   R   t   ost   makedirs(   R   (    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt
   _force_dir   s    c         C   s   t  j d |  ƒ d  S(   Ns   [noarch_python] %s(   t   syst   exit(   t   exit_message(    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt   _error_exit   s    c   	   	   C   s  t  | t r d n d |  ƒ } t j | d t j ƒ  ƒ9 } y | j ƒ  } Wn t k
 rm t d |  ƒ n XWd QXt	 j
 | ƒ j } t	 j | ƒ t rµ |  j d ƒ rµ |  d  }  n  t  | d ƒ } t | ƒ t  | |  ƒ } t | d	 ƒ  } | j | ƒ Wd QXt	 j | | ƒ |  S(
   s¬   Take a file from the bin directory and rewrite it into the python-scripts
    directory with the same permissions after it passes some sanity checks for
    noarch pacakgest   Scriptst   bint   encodings)   Noarch package contains binary script: %sNs
   -script.pyiöÿÿÿs   python-scriptst   w(   R   t   ISWINt   iot   opent   localet   getpreferredencodingt   readt   UnicodeDecodeErrorR   R   t   statt   st_modet   unlinkt   endswithR   t   writet   chmod(	   t   fnt   prefixt   srct   fit   datat   src_modet   dst_dirt   dstt   fo(    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt   rewrite_script   s"    
c   
      C   s˜  t  | |  ƒ } |  j d ƒ r. t j | ƒ nf|  j d ƒ rŠ t t j j  | |  d  d ƒ ƒ sz t |  d  ƒ | d k rŠ t j | ƒ n
d |  k rt  | d ƒ } t | ƒ |  |  j d ƒ } t  | | ƒ } t	 | ƒ } t | ƒ t
 j | | ƒ | d j | d	 ƒ n… |  j d ƒ rMt | ƒ } t | | ƒ } | d j | ƒ nG |  j d ƒ rt| d j |  d ƒ n  t j t ƒ }	 |	 j d |  ƒ d S(   s=   Process a file for inclusion in a noarch python package.
    s	   .egg-infos   .pycs   .pyos   .exeiüÿÿÿs
   -script.pys   python-scriptss   site-packagesi   s   bin/R   s	   Examples/s	   Examples\t   Examplesi	   s7   Don't know how to handle file: %s.  Including it as-is.N(   s	   .egg-infos   .pycs   .pyo(   s   bin/R   (   s	   Examples/s	   Examples\(   R   R   R   R   R   t   pathR    R   t   findR   t   shutilt   movet   appendt
   startswithR'   t   loggingt	   getLoggert   __name__t   debug(
   t   ft   dR   R)   t   nspt   gR%   R$   R   t   log(    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt   handle_file3   s.    2

c         C   só   i |  j  ƒ  d 6g  d 6g  d 6g  d 6} x | D] } t | | | ƒ q/ Wt r¤ xR | d | d f D]9 } x0 t | ƒ D]" \ } } | j d d ƒ | | <qw Wqd Wn  | rï xB | D]7 }	 t | |	 ƒ }
 t j j |
 ƒ r± t j	 |
 ƒ q± q± Wn  | S(   Nt   dists   site-packagess   python-scriptsR(   s   \t   /(
   R9   R8   R   t	   enumeratet   replaceR   R   R)   R   R   (   t   mt   filesR   t   entry_point_scriptsR4   R3   t   fnst   iR   t   entry_pointR    (    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt   populate_files\   s     
!c         C   s°  t  | d ƒ } t | ƒ t  | d ƒ } t | ƒ |  j ƒ  } t t  | d | ƒ d ƒ  } | j d j d ƒ ƒ Wd  QXt t  | d | ƒ d ƒ ) } | j d j d	 d
 ƒ j d ƒ ƒ Wd  QXt |  | | ƒ } t t	 ƒ } | d rx3 d D]( }	 t
 j t  | |	 ƒ t  | |	 ƒ ƒ qï Wn  t t  | d ƒ ƒ  }
 |
 j ƒ  } Wd  QXt t  | d ƒ d ƒ J } | j d ƒ t j | | d d d t ƒ| j d ƒ | j | ƒ Wd  QXd  S(   NR   R   s   .%s-pre-link.sht   wbs?       #!/bin/bash
    $PREFIX/bin/python $SOURCE_DIR/link.py
    s   utf-8s   .%s-pre-link.batsC       @echo off
    "%PREFIX%\python.exe" "%SOURCE_DIR%\link.py"
    s   
s   
s   python-scriptss
   cli-32.exes
   cli-64.exes   _link.pys   link.pyR   s   DATA = t   indenti   t	   sort_keyss   
## END DATA

(   s
   cli-32.exes
   cli-64.exe(   R   R   t   nameR   R   t   encodeR<   RC   R   t   __file__R+   t   copyfileR   t   jsont   dumpt   True(   R=   R>   R   t   bin_dirt   scripts_dirRG   R&   R4   t   this_dirR   R!   t	   link_code(    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt	   transformu   s.    

"
)(   R   RK   R   R/   R   t   os.pathR    R   R   R   R   R+   R	   t   platformR.   R   R   R   R'   R8   t   NoneRC   RR   (    (    (    s8   lib/python2.7/site-packages/conda_build/noarch_python.pyt   <module>   s   (				)