
ݲk^c           @` s  d  d l  m Z m Z m Z m Z d  d l Z d  d l m Z m Z m	 Z	 d  d l
 m Z d  d l m Z d  d l Z d  d l m Z m Z m Z m Z m Z m Z d  d l 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  m! Z! d d l" m# Z# 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/ m0 Z0 d d l1 m2 Z2 d d l3 m4 Z4 d d l5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d d l: m; Z; d d l< m= Z= m> Z> m? Z? d d l@ mA ZA mB ZB d eC f d     YZD e eE  ZF e d  ZG e Z e- d  ZH e- d  ZI d   ZJ d   ZK d   ZL d  eC f d!     YZM d d d"  ZO eP d#  ZQ d$   ZR d%   ZS d&   ZT d'   ZU d(   ZV d)   ZW eB jX eP d*  ZY d+   ZZ d,   Z[ d-   Z\ d S(.   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   EACCESt   EPERMt   EROFS(   t   open(   t	   getLogger(   t   basenamet   dirnamet   isdirt   isfilet   joint   splitext(   t   copyfileobjt   copystati   (   t   mkdir_p(   t   path_is_cleant   rm_rf(   t   islinkt   lexistst   linkt   readlinkt   symlink(   t   make_executable(   t   touchi   (   t
   CondaError(   t   dals(   t   CONDA_PACKAGE_EXTENSION_V1t   PACKAGE_CACHE_MAGIC_FILE(   t   context(   t   on_win(   t
   ensure_padt   expandt   win_path_double_escapet   win_path_ok(   t	   json_dump(   t   BasicClobberErrort   CondaOSErrort   maybe_raise(   t   FileModet   LinkTypet   TemporaryDirectoryc           B` s_   e  Z d  Z d	 Z e Z d d d	 d  Z d   Z d   Z	 e e
 d  Z d   Z d   Z RS(
   u+  Create and return a temporary directory.  This has the same
    behavior as mkdtemp but can be used as a context manager.  For
    example:

        with TemporaryDirectory() as tmpdir:
            ...

    Upon exiting the context, the directory and everything contained
    in it are removed.
    u    u   tmpc         C` s   t  j | | |  |  _ d  S(   N(   t   tempfilet   mkdtempt   name(   t   selft   suffixt   prefixt   dir(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   __init__3   s    c         C` s   d j  |  j j |  j  S(   Nu	   <{} {!r}>(   t   formatt	   __class__t   __name__R.   (   R/   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   __repr__6   s    c         C` s   |  j  S(   N(   R.   (   R/   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt	   __enter__9   s    c         C` s   d d l  m } |  j r |  j r y | |  j  Wn? t t f k
 ru } d d | f k re   n  | |  j  n Xt |  _ n  d  S(   Ni   (   R   u   Noneu   %s(   t   deleteR   R.   t   _closedt	   TypeErrort   AttributeErrort   True(   R/   t   _warnt	   _warningst   _rm_rft   ex(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   cleanup<   s    c         C` s   |  j    d  S(   N(   RB   (   R/   t   exct   valuet   tb(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   __exit__G   s    c         C` s   |  j  d t  d  S(   NR>   (   RB   R=   (   R/   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   __del__J   s    N(   R6   t
   __module__t   __doc__t   NoneR.   t   FalseR:   R3   R7   R8   R?   RB   RF   RG   (    (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR+   #   s   
			u   conda.stdoutlogu   
# -*- coding: utf-8 -*-
import re
import sys

from %(module)s import %(import_name)s

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(%(func)s())
u   
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    import os
    import sys
    args = ["%(source_full_path)s"]
    if len(sys.argv) > 1:
        args += sys.argv[1:]
    os.execv(args[0], args)
c         C` sQ   t  j d |   t j |  d d d d   } t |  } | j |  Wd  QXd  S(   Nu   writing json to file %st   modeu   wbt   encodingu   utf-8(   t   logt   tracet   codecsR   R%   t   write(   t	   file_patht   objt   fot   json_str(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   write_as_json_to_filem   s    c   	      C` s  t  |   r1 t t d d  d |  d t  t  n  | j d  d } t i | d 6| d 6| d 6} | d  k	 r d	 | } d
 d l m } | t	 j
 |  } n d  } t j |  d d d d 9 } | d  k	 r | j | j d   n  | j |  Wd  QX| d  k	 rt |   n  |  S(   Nt   source_patht   target_pathR   u   .i    u   moduleu   funcu   import_nameu   #!%s
i   (   t   replace_long_shebangRL   u   wbRM   u   utf-8(   R   R(   R&   RJ   R   t   splitt   python_entry_point_templatet   core.portabilityRY   R)   t   textRP   R   RQ   t   decodeR   (	   t   target_full_patht   python_full_patht   modulet   funct   import_namet   pyscriptt   shebangRY   RT   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_python_entry_pointt   s.    	

c         C` s   t  |  r1 t t d d  d | d t  t  n  t i t |   d 6} t t |   sm t	 t |   n  t
 | t d   C } d | k r t | d  } n  | j d |  | j |  Wd  QXt |  d  S(	   NRW   RX   R   u   source_full_pathu   wu    u   "u   #!%s
(   R   R(   R&   RJ   R   t    application_entry_point_templateR#   R   R
   R   R   t   strR!   RQ   R   (   t   source_full_pathR_   R`   t   entry_pointRT   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_application_entry_point   s     	
t   ProgressFileWrapperc           B` s8   e  Z d    Z d   Z d   Z d d  Z d   Z RS(   c         C` sC   | |  _  | |  _ t d t j | j    j  |  _ d |  _ d  S(   Ni   i    (	   t   progress_filet   progress_update_callbackt   maxt   ost   fstatt   filenot   st_sizet   progress_file_sizet   progress_max_pos(   R/   t   fileobjRn   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR3      s    		$c         C` s   t  |  j |  S(   N(   t   getattrRm   (   R/   R.   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   __getattr__   s    c         C` sB   | j  d  r+ t t |   j | |  n t |  j | |  d  S(   Nu	   progress_(   t
   startswitht   superRl   t   __setattr__t   setattrRm   (   R/   R.   RD   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR{      s    ic         C` s    |  j  j |  } |  j   | S(   N(   Rm   t   readt   progress_update(   R/   t   sizet   data(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR}      s    
c         C` sT   t  |  j |  j j    } t | |  j  } | |  _ | |  j } |  j |  d  S(   N(   Ro   Ru   Rm   t   tellt   minRt   Rn   (   R/   t   post   rel_pos(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR~      s
    	(   R6   RH   R3   Rx   R{   R}   R~   (    (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyRl      s
   			c   	      C` s  d d  l  } | d  k rH |  d t k r5 |  d  } qH |  j   d } n  t j d |  |  t |  sz t j d |  n  | j j |  d | t	 j
 j d  rt j   d k rxV t j |  D]B \ } } } x0 | D]( } t | |  } t j | d d  q Wq Wn  d  S(   Ni    iu   extracting %s
  to %su9   package folder %s was not empty, but we're writing there.t   dest_diru   linux(   t   conda_package_handling.apiRJ   R   R   RN   t   debugR   t   apit   extractt   syst   platformRy   Rp   t   getuidt   walkR   t   lchown(	   t   tarball_full_patht   destination_directoryRn   t   conda_package_handlingt   roott   dirst   filest   fnt   p(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   extract_tarball   s    	
$c         C` s   t  s
 d St |   j d  r0 t j d  d Sy2 d d l } | j t |  t |   | |   Wn$ t	 k
 r t
 j d d t n Xd S(   u   
    Create cross-platform menu items (e.g. Windows Start Menu)

    Passes all menu config files %PREFIX%/Menu/*.json to ``menuinst.install``.
    ``remove=True`` will remove the menu items.
    Nu   _uH   Environment name starts with underscore '_'. Skipping menu installation.i    u   menuinst Exceptiont   exc_info(   R    R	   Ry   RN   t   warnt   menuinstt   installR   R$   t	   Exceptiont	   stdoutlogt   errorR=   (   R1   RR   t   removeR   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt	   make_menu   s    &c         C` s   t  |   r9 t d i |  d 6| d 6 } t |   n  y$ t j d |  |  t |  |  Wn7 t t f k
 r t j d |  |  t	 |  |  n Xd  S(   Nu|   
        Cannot hard link a soft link
          source: %(source_path)s
          destination: %(destination_path)s
        u   source_pathu   destination_pathu   creating hard link %s => %su%   hard link failed, so copying %s => %s(
   R   R   R'   RN   RO   R   t   IOErrort   OSErrort   infot   _do_copy(   t   srct   dstt   message(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_hard_link_or_copy   s    c         C` s:   t  r
 t St |   o5 t |   o5 t j |  t j  Sd  S(   N(   R    RK   R   R   Rp   t   accesst   X_OK(   t   path(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt    _is_unix_executable_using_ORIGIN  s    c         C` s@   t  |   r t |  |  n  t j d |  |  t |  |  d  S(   Nu   soft linking %s => %s(   R   t   copyRN   RO   R   (   R   R   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   _do_softlink  s    c         C` sK   t  s t  t |   \ } } t | d   } | j d |  Wd  QX| S(   Nu   wu   @echo off
call "%s" %%*
(   R    t   AssertionErrorR   R   RQ   (   R   R   t   src_roott   _t   f(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_fake_executable_softlink"  s    	c         C` sf   t  rU t |   rU t |   } | j d  sU t j d |  |  t | |  d  Sn  t |  |  d  S(   Nu   /u   soft linking %s => %s(   R    R   R   Ry   RN   RO   R   R   (   R   R   t   src_points_to(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR   -  s    c         C` s   t  j d |  |  d } t |  d  / } t | d   } t | | |  Wd  QXWd  QXy t |  |  Wn) t t f k
 r } t  j d |  n Xd  S(   Nu   copying %s => %si  @ u   rbu   wbu   %r(   RN   RO   R   R   R   R   R   R   (   R   R   t   buffer_sizet   fsrct   fdstt   e(    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyR   9  s    c         C` s  | t  j k rv t |  rh t |  rh | sJ t t |  | t  t  n  t j d |  t	 |  n  t
 |  d  St |   s t d |    n  t |  r | s t t |  | t  t  n  t j d |  t	 |  n  | t  j k rt |   rt d |    n  y$ t j d |  |  t |  |  Wqt t f k
 r} t j d |  t j d | |  |  t |  |  qXnN | t  j k rt |  |  n/ | t  j k rt |  |  n t d |   d  S(	   Nu-   file exists, but clobbering for directory: %rug   Cannot link a source that does not exist. %s
Running `conda clean --packages` may resolve your problem.u   file exists, but clobbering: %ru    Cannot hard link a directory. %su   hard linking %s => %su   %ruF   hard-link failed. falling back to copy
  error: %r
  src: %s
  dst: %su   Did not expect linktype=%r(   R*   t	   directoryR   R   R(   R&   R   RN   R   R   R   R   t   hardlinkRO   R   R   R   R   R   t   softlinkR   (   R   R   t	   link_typet   forceR   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_linkN  s@    
	c      	   C` s  t  |  } t  |  } t |  d k r. g  St j   \ } } z#xd | D]\ } t j j | |  } t | d  r | j t	 j
   d d } n  t j | | d  qJ Wt j |  d d d d	 d
 d | g } t | d  d k rt | j d  d  d k r| j d d g  n  |  g | d d +t j |  d d l m }	 |	 | |  \ }
 } } Wd  t j |  Xg  } xd t | |  D]S \ } } t |  st d  } t j | |  | | | |
 |  q| j |  qW| S(   Ni    u   encodet   errorsu   replaces   
u   -Wiu   -mu
   compileallu   -qu   -lu   -ii   u   .i   i   u   -ju   0(   t   any_subprocessu  
            pyc file failed to compile successfully (run_command failed)
            python_exe_full_path: %s
            py_full_path: %s
            pyc_full_path: %s
            compile rc: %s
            compile stdout: %s
            compile stderr: %s
            (   t   tuplet   lenR,   t   mkstempRp   R   t   relpatht   hasattrt   encodeR   t   getfilesystemencodingRQ   t   closet   intRZ   t   extendRN   RO   t   conda.gateways.subprocessR   R   t   zipR   R   R   t   append(   t   python_exe_full_patht   py_full_pathst   pyc_full_pathsR1   t   py_vert   fdt   filenameR   t   commandR   t   stdoutt   stderrt   rct   created_pyc_pathst   py_full_patht   pyc_full_pathR   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   compile_multiple_pycz  s:    5	c         C` s   yg t  j d |   t |   j t d   } t t |  t  d t d | t t |  d  d | WnH t t	 f k
 r } | j
 t t t f k r t  j d |   t S  n Xt S(   Nu%   creating package cache directory '%s'u   ~t   mkdirt	   sudo_safeu   urlsu*   cannot create package cache directory '%s'(   RN   RO   R"   Ry   R   R   R   R=   R   R   t   errnoR   R   R   RK   (   t   pkgs_dirR   R   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_package_cache_directory  s    c         C` s   t  |  d  } yN t j d |   t |   j t d   } t t  |  |  d t d | WnH t t f k
 r } | j	 t
 t t f k r t j d |   t S  n Xt S(   Nu   .conda_envs_dir_testu   creating envs directory '%s'u   ~R   R   u!   cannot create envs directory '%s'(   R   RN   RO   R"   Ry   R   R=   R   R   R   R   R   R   RK   (   t   envs_dirt   envs_dir_magic_fileR   R   (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   create_envs_directory  s    #(]   t
   __future__R    R   R   R   RP   R   R   R   R   t   ioR   t   loggingR   Rp   t   os.pathR	   R
   R   R   R   R   t   shutilR   R   R   R,   t   warningsR?   t    R   R9   R   R   R   R   R   R   R   t   permissionsR   t   updateR   R   t   _vendor.auxlib.ishR   t   base.constantsR   R   t   base.contextR   t   common.compatR    t   common.pathR!   R"   R#   R$   t   common.serializeR%   t
   exceptionsR&   R'   R(   t   models.enumsR)   R*   t   objectR+   R6   RN   R   R[   Rg   RV   Rf   Rk   Rl   RJ   R   RK   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/conda/gateways/disk/create.pyt   <module>   s`   ".(",
					!							,	4	