σ
έ²k^c           @` sΉ  d  Z  d d l m Z m Z m Z m 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 d d l m Z m Z m Z m Z m Z m Z d d l 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! d d l" m# Z# d d l$ m% Z% d d l& m' Z' m( Z( e' Z' e j) e*  Z+ e Z, d   Z- e rld   Z. n  d d  Z0 d   Z1 e2 d  Z3 e2 d  Z4 d   Z5 e6 d d e j7 d S(   ur   This module contains:
  * all low-level code for extracting, linking and unlinking packages
  * a very simple CLI

These API functions have argument names referring to:

    dist:        canonical package name (e.g. 'numpy-1.6.2-py26_0')

    pkgs_dir:    the "packages directory" (e.g. '/opt/anaconda/pkgs' or
                 '/home/joe/envs/.pkgs')

    prefix:      the prefix of a particular environment, which may also
                 be the "default" environment (i.e. sys.prefix),
                 but is otherwise something like '/opt/anaconda/envs/foo',
                 or even any prefix, e.g. '/home/joe/myenv'
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   EACCESt   EEXISTt   ENOENTt   EPERMt   EROFSN(   t   dirnamet   isdirt   isfilet   joint   normcaset   normpathi   (   t   PREFIX_PLACEHOLDER(   t
   itervaluest   on_wint   opent	   iteritems(   t   rm_rf(   t   Dist(   t   PackageType(   t	   MatchSpec(   t
   rm_fetchedt   PackageCacheDatac          C` s   d t  f d     Y}  |    S(   Nt   package_cachec           B` s#   e  Z d    Z d   Z d   Z RS(   c         S` s(   t  t j   j t |  j   d    S(   N(   t   boolR   t   first_writablet   getR   t   to_package_reft   None(   t   selft   dist(    (    s,   lib/python2.7/site-packages/conda/install.pyt   __contains__1   s    c         S` s   d   t  t j    D S(   Nc         s` s   |  ] } t  |  Vq d  S(   N(   R   (   t   .0t   v(    (    s,   lib/python2.7/site-packages/conda/install.pys	   <genexpr>5   s    (   R   R   R   (   R    (    (    s,   lib/python2.7/site-packages/conda/install.pyt   keys4   s    c         S` s#   t  j   j t |  j    d  S(   N(   R   R   t   removeR   R   (   R    R!   (    (    s,   lib/python2.7/site-packages/conda/install.pyt   __delitem__7   s    (   t   __name__t
   __module__R"   R%   R'   (    (    (    s,   lib/python2.7/site-packages/conda/install.pyR   /   s   		(   t   object(   R   (    (    s,   lib/python2.7/site-packages/conda/install.pyR   .   s    c      
   C` ss  d d l  m } y t j t |   Wn: t k
 rc } | j t k r] t t |   r] qd   n Xt	 | d  s€ t
 | d d   } | j d |   Wd QXn  | s³ d } n  t	 |  sot
 | d  h } | j d  |  j d	  r| j d
 | | d |  d   n | j d | | d |    Wd QXt j |  j } | | d @d ?O} t j | |  n  d S(   u-  Special function for Windows XP where the `CreateSymbolicLink`
        function is not available.

        Simply creates a `.bat` file at `dst` which calls `src` together with
        all command line arguments.

        Works of course only with callable files, e.g. `.bat` or `.exe` files.
        i   (   t   shellsu   .batu   wu   @echo off
call "%s" %%*
Nu   bash.exeu   #!/usr/bin/env bash 
u   condau   %s "$@"u   path_tou   .exeu   source %s "$@"i$  i   (   t   utilsR+   t   ost   makedirsR	   t   OSErrort   errnoR   R
   R   R   t   writet   endswitht   statt   st_modet   chmod(   t   srct   dstt   shellR+   t   exct   ft   mode(    (    s,   lib/python2.7/site-packages/conda/install.pyt   win_conda_bat_redirect>   s*    	!	&%c         C` s    t  t |    t  t |   k r( d  St rL d } t j t d | } n d } t j } t t	 |  |   s t j
 t	 |  |   n  t |  | | |  d  S(   Nu   ScriptsR8   u   bin(   R   R   R   t	   functoolst   partialR<   R-   t   symlinkR
   R   R.   t   symlink_conda_hlp(   t   prefixt   root_dirR8   t   wheret
   symlink_fn(    (    s,   lib/python2.7/site-packages/conda/install.pyt   symlink_condal   s    $	c   
      C` ss  d d d g } t  |  |  } t |  s: t j |  n  x2| D]*} t  | | |  } t  | |  } yE t j j |  r t |  n  t j j |  s¬ | | |  n  WqA t t f k
 rj}	 t j j |  r|	 j	 t
 t t t f k rt j d j | |   qk|	 j	 t k r9t j d j | |   qk|	 j	 t k rdt j d j | |   qk  qA XqA Wd  S(   Nu   condau   activateu
   deactivateu>   Cannot symlink {0} to {1}. Ignoring since link already exists.ub   Problem with symlink management {0} {1}. File may have been removed by another concurrent process.ub   Problem with symlink management {0} {1}. File may have been created by another concurrent process.(   R   R
   R-   R.   t   patht   lexistsR   t   IOErrorR/   R0   R   R   R   R   t   logt   debugt   formatR   (
   RA   RB   RC   RD   t   scriptst   prefix_whereR:   t	   root_filet   prefix_filet   e(    (    s,   lib/python2.7/site-packages/conda/install.pyR@   |   s.    -c         ` sI   d d l  m } d d l m   | |   }   f d   t | j  D S(   u?   
    Return a dictionary of the linked packages in prefix.
    i   (   t
   PrefixData(   R   c         ` s   i  |  ] } |   |   q S(    (    (   R#   t   prefix_record(   R   (    s,   lib/python2.7/site-packages/conda/install.pys
   <dictcomp>    s   	 (   t   core.prefix_dataRQ   t   models.distR   R   t   _prefix_records(   RA   t   ignore_channelsRQ   t   pd(    (   R   s,   lib/python2.7/site-packages/conda/install.pyt   linked_data   s    c         ` s>   t  j     t t |  d |  } t   f d   | D  S(   u8   
    Return the Dists of linked packages in prefix.
    RV   c         3` s*   |  ]  \ } } | j    k r | Vq d  S(   N(   t   package_type(   R#   R!   t
   prefix_rec(   t   conda_package_types(    s,   lib/python2.7/site-packages/conda/install.pys	   <genexpr>©   s    (   R   R[   R   RX   t   set(   RA   RV   t   ld(    (   R[   s,   lib/python2.7/site-packages/conda/install.pyt   linked£   s    c         C` sb   d d l  m } | |   } | j | j d  } | d k rA d St |  j |  rZ | Sd Sd S(   u   
    Return the install metadata for a linked package in a prefix, or None
    if the package is not linked in the prefix.
    i   (   RQ   N(   RS   RQ   R   t   nameR   R   t   match(   RA   R!   RQ   RW   RR   (    (    s,   lib/python2.7/site-packages/conda/install.pyt	   is_linked­   s    uX   WARNING: The conda.install module is deprecated and will be removed in a future release.t   file(8   t   __doc__t
   __future__R    R   R   R   R0   R   R   R   R   R   R=   t   loggingR-   t   os.pathR	   R
   R   R   R   R   t   syst   base.constantsR   t   common.compatR   R   R   R   t   gateways.disk.deleteR   RT   R   t   models.enumsR   t   models.match_specR   t   core.package_cache_dataR   R   t	   getLoggerR(   RI   t   prefix_placeholderR   R<   R   RE   R@   t   FalseRX   R^   Ra   t   printt   stderr(    (    (    s,   lib/python2.7/site-packages/conda/install.pyt   <module>   s6   "(."	.	

		