
0]c           @   sy  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
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l 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  m! Z! d  d l" m# Z# d  d l$ Z% d  d l& m' Z' m( Z( y d  d	 l) m* Z* Wn! e+ k
 rgd  d	 l, m* Z* n Xe* d
 d  d    Z- d   Z. e  j/ d  Z0 d   Z1 d   Z2 d   Z3 y d  d l4 m5 Z5 d   Z6 Wn e+ k
 rd   Z6 n Xd   Z7 d   Z8 d   Z9 e: d  Z; d   Z< d d  Z= d e! f d     YZ> d   Z? d   Z@ d    ZA d!   ZB d" eC e: d#  ZD d S($   iN(   t   environt   getcwdt   listdirt   makedirst   renamet   rmdirt   unlink(   t   abspatht   basenamet   dirnamet   existst   isdirt   isfilet   joint   normpatht   splitt   islinkt   lexists(   t   check_outputt   CalledProcessErrort   STDOUT(   t   string_types(   t   Futuret   Executor(   t   Lock(   t   MAGIC_HEADERSt	   DLL_TYPES(   t	   lru_cachet   maxsizei    c         C   s(   t  j |   } | d  k r$ i  } n  | S(   N(   t   yamlt   loadt   None(   t   datat   res(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   yamlize   s    	c      3   C   s  d j  |  d |  d f  } t d j  |  d j d    } t d j  |  d j d    } t d t d	 t d
 | j d  d t | d k  d t | d k  d t | d k  d t | d k  d t | d k  d | j d  d | j d5  d | j d  d t | d k  d t | d k  d | j d6  d! | j d   d" | d# t d$ | k okd% k  n  d& t d' | k od$ k  n  d( t | d) k  d* t | d+ k  d, t | d- k  d. t | d/ k  d0 t | d1 k  d2 t | d3 k  d4 |  S(7   Nt   -t   platformt   archt    t   pythont   .t   numpyt   nomklt   debugt   linuxs   linux-t   linux32s   linux-32t   linux64s   linux-64t   armv7ls   linux-armv7lt   armt   ppc64les   linux-ppc64let   osxs   osx-t   unixt   wins   win-t   win32s   win-32t   win64s   win-64t   x86s   -32s   -64t   x86_64t   pyt   py3ki   i(   t   py2ki   t   py26i   t   py27i   t   py33i!   t   py34i"   t   py35i#   t   py36i$   t   np(   s   linux-s   osx-(   s   -32s   -64(   R   t   intR   t   dictt   Falset
   startswitht   boolt   endswith(   t   cfgt   platR9   RB   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   ns_cfg!   s:    """"s   (.+?)\s*\[(.+)\]$c         C   s   g  } x |  j    D]t } | j   } t j |  } | rz | j d  } t | | i   r | j | j d   q q n  | j |  q Wd j |  d S(   Ni   i   s   
(   t
   splitlinest   rstript   sel_patt   matcht   groupt   evalt   appendR   (   R    t	   namespacet   linest   linet   mt   cond(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   select_linesF   s    c         C   s4   | d  k	 r$ t |  t |   }  n  t t |    S(   N(   R   RX   RK   RD   R"   (   R    RI   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   parseT   s    c         C   sL   t  j |   g } t  j d t  j |   } | j d  } | j d |  S(   Nt   loaders	   meta.yamlt   environment(   t   jinja2t   FileSystemLoadert   Environmentt   ChoiceLoadert   get_or_select_templatet   render(   t
   recipe_dirt   loaderst   envt   template(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   render_jinja2[   s    (   t   apic         C   s<   t  j |  d t d t | r! | n i  d d } | j   S(   Nt   finalizet   bypass_env_checki    (   Rg   Ra   RE   t   Truet   get_rendered_recipe_text(   Rb   RI   RV   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   render_metadatag   s    !c         C   s   t  |   } t | |  S(   N(   Rf   RY   (   Rb   RI   R    (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyRl   p   s    c          c   s[   xT d D]L }  xC d D]; } | j  d	  \ } } t d
 | d | d |  d d  Vq Wq Wd  S(   Nt   27t   34t   35s   linux-64s   linux-32s   osx-64s   win-32s   win-64R#   R$   R%   R'   R)   s   1.11(   Rm   Rn   Ro   (   s   linux-64s   linux-32s   osx-64s   win-32s   win-64(   R   RD   (   R9   RJ   R$   R%   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt	   iter_cfgsu   s    c         C   s   |  d  } | t  k r d  St  j |  } | d k r |  j d  } | d k  rT d St j j |   }  |  | d d |  | d } d t j |  S| j d	  r | S| d
 k r d
 i d d 6d d 6j |  d  Sd  S(   Ni   t   DLLs   PE  i    s   <no PE header found>i   i   s   DLL t   MachOt   ELFt   32s   t   64s   (	   R   R   t   gett   findt   futuret   builtinst   bytesR   RF   (   R    t   headt   lookupt   post   i(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   get_object_type|   s    
c         C   s%   x d	 D] } | |  k r | Sq Wd  S(
   Ns   --s   -.s   -_s   .-s   ..s   ._s   _-s   _.(   s   --s   -.s   -_s   .-s   ..s   ._s   _-s   _.(   R   (   t   st   seq(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   get_bad_seq   s    c         C   s   d g } | r | j  d  n  x_ |  D]W } t j d d k rK t |  n | } | | k pv d | k ot d k  n s& t Sq& Wt S(   Ni
   i   i    i   i    i   (   RR   t   syst   version_infot   ordRE   Rj   (   R    t   allow_CRt   newlinet   ct   n(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt	   all_ascii   s    	%(c         C   s6   t  |  t  r |  St  |  t  r/ |  j d  S|  g S(   Nt   ,(   t
   isinstancet   listR   R   (   t   argument(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   ensure_list   s
    i    c         C   s   t  j d |  d | d | S(   sb   Emulate python-3.4 re.fullmatch().

    Credit: https://stackoverflow.com/questions/30212413/
    s   (?:s   )\Zt   flags(   t   reRO   (   t   regext   stringR   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt	   fullmatch   s    t   DummyExecutorc           B   s&   e  Z d    Z d   Z e d  Z RS(   c         C   s   t  |  _ t   |  _ d  S(   N(   RE   t	   _shutdownR   t   _shutdownLock(   t   self(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   __init__   s    	c      	   O   s|   |  j  m |  j r" t d   n  t   } y | | |   } Wn  t k
 r` } | j |  n X| j |  | SWd  QXd  S(   Ns*   cannot schedule new futures after shutdown(   R   R   t   RuntimeErrorR   t   BaseExceptiont   set_exceptiont
   set_result(   R   t   fnt   argst   kwargst   ft   resultt   e(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   submit   s    
		c         C   s   |  j   t |  _ Wd  QXd  S(   N(   R   Rj   R   (   R   t   wait(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   shutdown   s    
(   t   __name__t
   __module__R   R   Rj   R   (    (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyR      s   		c         C   s   d d l  m } | |   S(   Ni(   t   find_executable(   t   distutils.spawnR   (   t
   executableR   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   which   s    c         O   s2  t  |   }  t j d k ry% t d j |   d t d t } Wq!y+d  } d d l m	 } d d l
 m } | d d	 d
 d d t  h } | j d j | |  g    | j d  | j d j | |  g    | j d  | j } Wd  QXt | d  % } | j   }	 |  |	 k s$t  Wd  QXt d }
 d } t |
 d d | g d t d d  d d  d d  d | } Wqt k
 r} qXq!Xn y t d  Wn n Xt d  } | r!t d  r!y9 t | d d t t   d  d |  d g d t } Wn t k
 rn Xt j d  n  t j |   d  S(   NR5   s   RD /S /Q "{}" > NUL 2> NULt   shellt   stderri(   t   Utf8NamedTemporaryFile(   t   quote_for_shellt   modet   wt   suffixs   .batt   deletes	   RD /S {}
s   chcp 65001
s   EXIT 0
t   rt   COMSPECi   s   /ds   /ct   stdoutt   stdint   creationflagss   .emptyt   rsyncs   -as   --deletet   /(   R   R   R$   R   t   formatRj   R   R   t   conda._vendor.auxlib.compatR   t   conda.utilsR   RE   t   writet   namet   opent   readt   AssertionErrorR    R   R   R   R   R   R   t   shutilt   rmtree(   t   pathR   R   t   outR   R   R   t
   batch_filet   contentst   contentt   comspect   CREATE_NO_WINDOWR   R   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyR      sP    

)c         C   sO   y t  |   Wn: t k
 rJ y t |  |  d  WqK t k
 rF qK Xn Xd S(   s   If files are in use, especially on windows, we can't remove them.
    The fallback path is to rename them (but keep their folder the same),
    which maintains the file handle validity.  See comments at:
    https://serverfault.com/a/503769
    s   .conda_trashN(   R   t   EnvironmentErrorR   (   R   (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   unlink_or_rename_to_trash  s    c         C   sF   t  |   } x3 t |  rA t |  rA t |  t  |  } q Wd  S(   N(   R	   R   R   R   (   R   t   parent_path(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   remove_empty_parent_paths!  s    
i   c         O   s{   zO t  |   }  t |   r5 t |   r5 t |   n t |   rN t |   n  Wd t |   rb t SX| rw t |   t Sd S(   s   
    Completely delete path
    max_retries is the number of times to retry on failure. The default is 5. This only applies
    to deleting a directory.
    If removing path fails and trash is True, files will be moved to the trash directory.
    N(	   R   R   R   R   R   R   RE   R   Rj   (   R   t   max_retriest   trasht   clean_empty_parentsR   t   kw(    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   rm_rf)  s    
(E   R   R   t   osR    R   R   R   R   R   R   t   os.pathR   R   R	   R
   R   R   R   R   R   R   R   t
   subprocessR   R   R   R   R\   R   t   sixR   t   concurrent.futuresR   R   t	   threadingR   t   future.builtinsRx   t   conda_verify.constantsR   R   t	   functoolsR   t   ImportErrort   backports.functools_lru_cacheR"   RK   t   compileRN   RX   RY   Rf   t   conda_buildRg   Rl   Rp   R   R   RE   R   R   R   R   R   R   R   R   Rj   R   (    (    (    s5   lib/python2.7/site-packages/conda_verify/utilities.pyt   <module>   sN   4L		"										A		