σ
έ²k^c           @` s°  d  d l  m Z m Z m Z m 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 m Z m 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 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$ d   Z% d   Z& d   Z' d   Z( e j) d e j*  Z+ d   Z, d   Z- d d  Z/ d d d  d d  Z0 d   Z1 d   Z2 d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   abspatht   basenamet   dirnamet   isdirt   isfilet   islinkt   joini   (   t   EntityEncoder(   t   CONDA_PACKAGE_EXTENSION_V1(   t   context(   t   PY3(   t   paths_equal(   t
   PrefixData(   t   rmtree(   t   PREFIX_PLACEHOLDER(   t	   untrackedc         C` s   t    } x= | D]5 } t |  |  } | j t |   t j |  q WxE t | d t d t D]+ } y t j	 |  Wqb t
 k
 r qb Xqb Wd S(   u*   
    Remove files for a given prefix.
    t   keyt   reverseN(   t   setR
   t   addR   t   ost   unlinkt   sortedt   lent   Truet   rmdirt   OSError(   t   prefixt   filest   dst_dirst   ft   dstt   path(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   remove   s    	c      	   C` s  t  j } |  j r[ xB |  j D]7 } x. t |  D]  } t d | | j   f  q/ Wq Wd  St d |  |  j r t | t |   d  S|  j rΦ t	 t |   } t d t
 |   x | D] } t |  qΎ Wd  St | d |  j j   d |  j d t |  j  d  S(   Nu	   %-50s  %su	   # prefix:u   # untracked files: %dt   namet   versiont   build_number(   R   t   target_prefixt   whicht   which_packaget   printt   dist_strt   resetR%   R   R   R   t   make_tarbz2t   pkg_namet   lowert   pkg_versiont   intt	   pkg_build(   t   argst   parserR   R$   t   precR    t   fn(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   execute*   s(    		"				c         C` s?   x8 t  |   j   D]$ } | d | k r t | d  Sq Wd  S(   Nu   nameu   version(   R   t   iter_recordst   strt   None(   R   R&   t   info(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   get_installed_versionG   s    c         C` s}   t  d |  d | d t j d t j d t |  d t |  d g   } | ry d | | d	 | d	 <| d
 j d |  n  | S(   NR&   R'   t   platformt   archR(   t   buildt   dependsu   py%d%d_u   buildu   dependsu   python %d.%d*(   t   dictR   R?   t	   arch_nameR3   R;   t   append(   R&   R'   R(   t   requires_pyt   d(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   create_infoN   s    			u   ^#!.+$c         C` sα   t  | d  j d  d k r" t St  |   } | j   } Wd  QXt j |  } | og d | j   k sn t St j d t | d d } t |  t	 |   } t  | d   } | j
 |  Wd  QXt j | t d	 d
   t S(   Nu   rbi   u   #!u   pythonu   #!%s/bin/pythont   counti   u   wu   755i   (   t   opent   readt   Falset   shebang_patt   matcht   groupt   subR   R
   R   t   writeR   t   chmodR3   R   (   t   tmp_dirR$   t   fit   datat   mt   tmp_patht   fo(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   fix_shebang_   s    c   	      C` s)  t  | d  } t j |  t t  | d  d  ) } x | D] } | j | d  q> WWd  QXt t  | d  d  ) } t j | | d d d t d	 t Wd  QX| rξ t t  | d
  d  ) } x | D] } | j | d  qΚ WWd  QXn  x4 t j	 |  D]# } |  j
 t  | |  d |  qώ Wd  S(   Nu   infou   filesu   wu   
u
   index.jsont   indenti   t	   sort_keyst   clsu
   has_prefixu   info/(   R
   R   t   mkdirRJ   RQ   t   jsont   dumpR   R   t   listdirR   (	   t   tRS   R    t
   has_prefixR=   t   info_dirRX   R"   R8   (    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   _add_info_dirr   s    (c         C` s?  t  |  } g  } g  } t j   } t j | d  } t j d  }	 x¦| D]}
 |
 j d  p |
 j d  p d |
 k p |
 d k s t	 |
   t
 |  |
  } |
 j d  rη t | |  rη t
 | t |   } | j |
  n  | j | |
  |	 j |
 j d   |	 j d  t |  rt j |  } t rct | t  rc|	 j t | d   n |	 j |  | j d  rκ| j d	 |
 | f  qκqL t |  rL |	 j t | d
  j    | j d  rκ| j d |
  qκqL qL W|	 j   | d <| r| |  n  t | | | | |  | j   t |  | S(   u   
    create a conda package with `files` (in `prefix` and `info` metadata)
    at `tar_path`, and return a list of warning strings
    u   w:bz2u   sha1u   /u   \u    u   bin/u   utf-8s    u(   found symlink to absolute path: %s -> %su   rbu	   .egg-linku   found egg link: %su	   file_hash(   R   t   tempfilet   mkdtempt   tarfileRJ   t   hashlibt   newt
   startswitht   endswitht   AssertionErrorR
   RY   R   RE   R   t   updatet   encodeR	   R   t   readlinkR   t
   isinstanceR;   t   bytesR   RK   t	   hexdigestRd   t   closeR   (   R   R    R=   t   tar_patht   update_infot   warningsRb   RS   Ra   t   hR"   R$   t   link(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   create_conda_pkg   sD    C	

u   unknownu   0.0c   	      C` s   | d  k r t |   } n  t d t |   t |  d k rO t d  d  St d   | D  r¬ t |  d  } | d  k	 s t  t d   | d  j d  D  } n t	 } t
 | | | |  } d	 | t } t |  | | |  t d
  t |  | S(   Nu   # files: %di    u   # failed: nothing to doc         s` s   |  ] } d  | k Vq d S(   u   /site-packages/N(    (   t   .0R"   (    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pys	   <genexpr>Ή   s    u   pythonc         s` s   |  ] } t  |  Vq d  S(   N(   R3   (   Rz   t   x(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pys	   <genexpr>Ό   s    i   u   .u   %(name)s-%(version)s-%(build)su	   # success(   R<   R   R,   R   t   anyR>   Rl   t   tuplet   splitRL   RH   R   Ry   (	   R   R&   R'   R(   R    t   python_versionRF   R=   t	   tarbz2_fn(    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyR/   °   s"    
&

c         #` s   t       t      d k rG d d l m } | d     n  xK t   j   D]7 } t    f d   | d p d D  rZ | VqZ qZ Wd S(   u­   
    given the path (of a (presumably) conda installed file) iterate over
    the conda packages the file came from.  Usually the iteration yields
    only one package.
    i   (   t   CondaVerificationErroru)   could not determine conda prefix from: %sc         3` s'   |  ] } t  t  |     Vq d  S(   N(   R   R
   (   Rz   R"   (   R$   R   (    s5   lib/python2.7/site-packages/conda/cli/main_package.pys	   <genexpr>Υ   s    u   filesN(    (   R   t   which_prefixR<   t
   exceptionsR   R   R:   R|   (   R$   R   R7   (    (   R$   R   s5   lib/python2.7/site-packages/conda/cli/main_package.pyR+   Θ   s    )c         C` sX   t  |   } xE t rS t t | d   r. | S| t |  k rD d St |  } q Wd S(   u   
    given the path (to a (presumably) conda installed file) return the
    environment prefix in which the file in located
    u
   conda-metaN(   R   R   R   R
   R   R<   (   R$   R   (    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyR   Ω   s    	(3   t
   __future__R    R   R   R   Rh   R^   R   t   os.pathR   R   R   R   R   R	   R
   t   reRg   Re   t   _vendor.auxlib.entityR   t   base.constantsR   t   base.contextR   t   common.compatR   t   common.pathR   t   core.prefix_dataR   t   gateways.disk.deleteR   t   installR   t   miscR   R%   R9   R>   RH   t   compilet   MRM   RY   Rd   R<   Ry   R/   R+   R   (    (    (    s5   lib/python2.7/site-packages/conda/cli/main_package.pyt   <module>   s8   "4						+		