
@K7]c           @` s
  d  d l  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
 Z
 d  d l m Z d  d l Z 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 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! Z! d  d l" Z" d  d l# Z# d  d l$ Z$ d  d l% m& Z& d  d l' Z' y d  d l( m) Z) Wn e* k
 re+ Z) n Xd  d l, Z, d  d l- Z- d  d l. Z/ y d  d l0 m1 Z1 Wn* e2 k
 rd  d	 l0 m3 Z3 e3 f Z1 n Xd  d
 l4 m5 Z5 d d l6 m7 Z7 m8 Z8 m9 Z9 m: Z: d d l6 m; Z; m< Z< d d l6 m= Z= m> Z> d d l6 m? Z? d d l6 m@ Z@ d d l6 mA ZA d d l6 mB ZB mC ZC d d l6 mD ZD d d l6 mE ZE mF ZF mG ZG d d l6 mH ZH d d l6 mI ZI mJ ZJ mK ZK mL ZL d  d lM mN ZO d  d lP mQ ZQ d  d lR mS ZS e; rd  d lT mT ZU eV d  ZT d  d lW jX ZY d  d lZ j[ Z\ d  d l m] Z] e^ Z^ e_ Z_ nP d  d l` mT Za eV d  ZT d  d lY ZY d  d l\ Z\ d  d lb m] Z] ec Z^ ec Z_ e! jd d k Ze e   pd Zf e! jd d k Ze e jg j e= ee r)d  n d!  Zh ee r>d  n e ji Zj ee rSd  n e jk Zl ee rhd  n e jm Zn d" d# d$ d% d& d' d( d) d* d+ d, h Zo d- Zp y d  d. l mq Zq mr Zr Wn! e* k
 rd  d/ lq mr Zr n Xe@ d0    Zs d1   Zt d2   Zu d3 ev f d4     YZw d5   Zx d6 ev f d7     YZy d8   Zz d9   Z{ d:   Z| d;   Z} d<   Z~ e j d=    Z d>   Z d?   Z d@ e d eV e dA  Z dB   Z e d e dC  Z e d@ d eV e dD  Z e jg j e= dE  e jg j e jg j dF dG   f Z d@ dH  Z eV d d@ dI  Z dJ dK  Z d Z dY dZ  Z d[   Z d\   Z d]   Z d^   Z d_   Z d`   Z da   Z db   Z dc   Z dd   Z de   Z df   Z dg   Z dh   Z di   Z e dj  Z e j dk    Z e j dl    Z e! jd d k rd  n d! Z e j dm  Z dn   Z do   Z dp   Z dq   Z i  Z dr   Z ds   Z e dt  Z du   Z e j dv    Z dw   Z dx   Z dy ev f dz     YZ d{   Z d|   Z d} e f d~     YZ d   Z e, j e e  e j d    Z e j d d   Z d   Z d   Z d d d  Z d d  Z d   Z d d  ZN d e j f d     YZ d e j f d     YZ d e j f d     YZ e   a e e j  Z e e j  Z e j d  j e j  e j d  j e j  e j d  j e j  e j d  j e j  d   Z e j eV eV d  Z d   Z d eV e eV d  Z d   Z d   Z d d  el en Bd d  d  Z d   Z d d  Z e j d  Z e j d  Z e d  Z d   Z d d  Z d   Z d d  Z d   Z i  a d   Z d S(   i    (   t   absolute_importt   divisiont   print_function(   t   OrderedDictt   defaultdictN(   t   getpreferredencoding(
   t   dirnamet   getmtimet   getsizet   isdirt   joint   isfilet   abspatht   islinkt
   expandusert
   expandvars(   t   Thread(   t   JSONDecodeError(   t   CONDA_TARBALL_EXTENSIONS(   t   CONDA_TARBALL_EXTENSION(   t   PackageCacheDatai   (   t   hashsum_filet   md5_filet   unix_path_to_wint   win_path_to_unix(   t   PY3t	   iteritems(   t   root_dirt	   pkgs_dirs(   t   string_types(   t   memoized(   t   StringIO(   t   VersionOrdert	   MatchSpec(   t   cc_conda_build(   t   conda_43t   conda_46t   Dist(   t   context(   t   downloadt   TemporaryDirectoryt   get_conda_channelt   CondaHTTPError(   t   rm_rf(   t   BuildLockError(   t   external(   t   globc         C` s   t  |  d | S(   Nt	   recursive(   t	   glob_glob(   t   pathnameR/   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR.   A   s    (   t	   ExitStackc         C` s   t  |  d | S(   NR/   (   t
   glob2_glob(   R1   R/   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR.   M   s    t   win32s   utf-8t   Scriptst   bins   linux-64s   linux-32s   linux-ppc64les   linux-armv6ls   linux-armv7ls   linux-aarch64s   win-64s   win-32s   osx-64s   zos-zt   noarchs   
# -*- 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())
(   t   scandirt   walk(   R9   c         C` s   t  j |   S(   N(   t   ost   stat(   t   path(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt	   stat_file   s    c         C` s   d } t    } x t |   D] \ } } } xv | D]n } y t t j j | |   } Wn t k
 rm q2 n X| j | k r q2 n  | j | j  | | j	 7} q2 Wq W| S(   Ni    (
   t   setR9   R=   R:   R<   R
   t   OSErrort   st_inot   addt   st_size(   R<   t
   total_sizet   seent   roott   _t   filest   fR;   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   directory_size_slow   s    	c         C` s  y6t  r0 d } t j | j |   d t } n- d } t j | j |   j   d t j } t | d  r y | j d d  } Wq t	 t
 f k
 r t  r d Sq Xn  t  r%| j   j d	 d
  d } d } t j | | j    j d  j   } | j d d  j d d  j d d  } n | j   d } Wn  t j k
 rXt |   } n Xy t |  SWn t k
 r{d SXd S(   s   
    s   dir /s "{}"t   shells   du -s {}t   stderrt   decodet   errorst   ignorei    s   
i   is   \s([\d\W]+).+i   t   ,t    t   .t    N(   t   on_wint
   subprocesst   check_outputt   formatt   Truet   splitt   PIPEt   hasattrRL   t   UnicodeDecodeErrort
   IndexErrort   stript   rsplitt   ret   searcht   groupt   replacet   CalledProcessErrorRI   t   intt
   ValueError(   R<   t   commandt   outt   pattern(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   directory_size   s2    !''-t   DummyPsutilProcessc           B` s   e  Z d    Z RS(   c         O` s   g  S(   N(    (   t   selft   argst   kwargs(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   children   s    (   t   __name__t
   __module__Rn   (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRj      s   c         ` s   t     x9 t |  j   d d   d t D] \ } } |  | <q+ Wt j   \ }  t j | d    t j d k r d  n d       f d   } t	 d	 |  } t | _
 | j    S(
   s  Rewrite values of env variables back to $ENV in stdout

    Takes output on the pipe and finds any env value
    and rewrites it as the env key

    Useful for replacing "~/conda/conda-bld/pkg_<date>/_h_place..." with "$PREFIX"

    Returns an FD to be passed to Popen(stdout=...)
    t   keyc         S` s   t  |  d  S(   Ni   (   t   len(   t   kv(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   <lambda>   RP   t   reverset   rtR4   s   %{}%s   ${}c          ` s   x t  r yy   j   }  |  s9   j   t j   d  Sx5  j   D]' \ } } |  j |  j |   }  qF Wt j j	 |   Wq t
 k
 r y, t j   d  } t j j	 | p d  Wq t k
 r q Xq Xq Wd  S(   Ni'  RP   (   RW   t   readlinet   closeR:   t   itemsRb   RV   t   syst   stdoutt   writeR[   t   readt	   TypeError(   t   linet   sRq   t   txt(   t   rt   replacement_tt   replacementst   w_fd(    s0   lib/python2.7/site-packages/conda_build/utils.pyt   rewriter   s     	
t   target(   R   t   sortedRy   RW   R:   t   pipet   fdopenRz   t   platformR   t   daemont   start(   t   envt   kt   vt   r_fdR   t   t(    (   R   R   R   R   s0   lib/python2.7/site-packages/conda_build/utils.pyt   _setup_rewrite_pipe   s    	.		
t   PopenWrapperc           B` s#   e  Z d    Z d   Z d   Z RS(   c         O` sX   d  |  _ d |  _ d |  _ d  |  _ d |  _ d |  _ |  j | |   \ |  _ |  _	 d  S(   Ni    i   (
   t   Nonet   elapsedt   rsst   vmst
   returncodet   diskt	   processest   _executeRg   t   err(   Rk   Rl   Rm   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   __init__   s    						c         O` s  y( d d  l  } | j | j | j f } WnT t k
 r~ } d  } t t f } t t  } | j	 d j
 |   | j	 d  n X| j d d  } | j d t j  } | r | j t j    n t   }	 t t  }
 t j   } | r | j | |   n t j | |   } yx|  j d  k rd } d } d } x |	 j d t  D] } |
 j | j i   } y] | j   } | | j 7} | | j 7} | j   } | j | d <| j  | d	 <| |
 | j <Wn | k
 rqFn X| d
 7} qFWt! | |  j  |  _ t! | |  j"  |  _" t# d   |
 j$   D  |  _% t# d   |
 j$   D  |  _& t! | |  j'  |  _' t! t( |  |  j)  |  _) t j* |  t j   | |  _+ | j,   |  _ qWWn t- k
 r| j.     n Xt! t( |  |  j)  |  _) t j   | |  _+ | j/ | j0 f S(   Ni    s#   psutil import failed.  Error was {}ss   only disk usage and time statistics will be available.  Install psutil to get CPU time and memory usage statistics.t   time_inti   t   cwdR/   Rz   t   useri   c         s` s   |  ] } | d  Vq d S(   Rz   N(    (   t   .0t   child(    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>;  s    c         s` s   |  ] } | d  Vq d S(   R   N(    (   R   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr><  s    (1   t   psutilt   NoSuchProcesst   AccessDeniedt   ImportErrorR   R?   Re   t
   get_loggerRo   t   warnRV   t   popt   getRz   t   prefixt   ProcessR:   t   getpidRj   R   t   dictt   timet   PopenRT   R   Rn   RW   t   pidt   memory_infoR   t	   cpu_timest   systemR   t   maxR   t   sumt   valuest   cpu_syst   cpu_userR   Ri   R   t   sleepR   t   pollt   KeyboardInterruptt   killR{   RK   (   Rk   Rl   Rm   R   t   psutil_exceptionst   et   logR   t   disk_usage_dirt   parentt	   cpu_usaget
   start_timet   _popenR   R   R   R   t   child_cpu_usaget   memt	   cpu_stats(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s`    $*
c         C` sZ   t  i |  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6 S(	   NR   R   R   R   R   R   R   R   (	   t   strR   R   R   R   R   R   R   R   (   Rk   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   __repr__N  s    





(   Ro   Rp   R   R   R   (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR      s   	
	Kc   
      O` s_  d | k r> | j    } t j j    } | j i | d 6 n  d   | d j   D | d <g  } d | k r~ t j | d <n  x | D] } t j j	 d k  r t
 | d  r | j t  } n3 t j j	 d k r t
 | d  r | j t  } n  | j t |   q W| j d  } d | k r-| d =n  | j d d   } | rXt |  | d	 <n  d  } | d  k	 rt | |  }	 |  d
 k r|	 j j   } n  |	 j d k rt j |	 j |   n  | j i |	 j d 6|	 j d 6|	 j d 6|	 j d 6|	 j d 6|	 j d 6|	 j d 6 nG |  d k r3t j  | |  n( d	 | k rI| d	 =n  t j! | |  } | S(   NR   c         S` s+   i  |  ]! \ } } t  |  t  |   q S(    (   R   (   R   Rq   t   value(    (    s0   lib/python2.7/site-packages/conda_build/utils.pys
   <dictcomp>^  s   	 t   stdini   t   encodeRL   t   statst   rewrite_stdout_envR{   t   outputi    R   R   R   R   R   R   R   t   call("   t   copyR:   t   environt   updateRy   RT   RY   Rz   t   version_infot   majorRZ   R   t   codecRL   t   appendR   R   R   R   R   R   Rg   R}   R   Rc   R   R   R   R   R   R   R   t
   check_callRU   (
   t   funct	   popenargsRm   t   env_copyt   _argst   argR   R   Rg   t   proc(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt"   _func_defaulting_env_to_os_environY  sP    !!






c         K` s   t  d |  |  S(   NR   (   R   (   R   Rm   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   check_call_env  s    c         K` s   t  d d t j |  | j   S(   NR   R{   (   R   RT   RY   t   rstrip(   R   Rm   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   check_output_env  s    c         C` s   d } i  } x0 t  |  D]" \ } } d	 | d	 d
 >| | <q WxF t |  D]8 } |  | | k rL t |   | | } d | | f SqL Wd |  S(   Nt   Kt   Mt   Gt   Tt   Pt   Et   Zt   Yi   i
   s   %.1f%ss   %sB(   R   R   R   R   R   R   R   R   (   t	   enumeratet   reversedt   float(   t   nt   symbolsR   t   iR   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   bytes2human  s    c         C` s,  t  s! |  j t   p d  }  n  t |   r |  j   j t  sW |  j   j t  r t j	   } t
 |  |  t j j | d d  } t |  r t
 | t j j | d   n  t } q t d |   d Sn' t t j j t j   |    } t } t j j |  s"t d j |    n  | | f S(   s  resolve recipe dir as absolute path.  If recipe is a tarball rather than a folder,
    extract it and return the extracted directory.

    Returns the absolute path, and a boolean flag that is true if a tarball has been extracted
    and needs cleanup.
    s   utf-8t   infos
   recipe.tars   Ignoring non-recipe: %ss,   Package or recipe at path {0} does not existN(   NN(   R   RL   R   R   t   lowert   endswitht   decompressible_extsR   t   tempfilet   mkdtempt   tar_xfR:   R<   R
   RW   t   printR   R   t   getcwdt   Falset   existsRe   RV   (   t   recipet
   recipe_dirt   recipe_tarfilet   need_cleanup(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_recipe_abspath  s"    *	!c         c` s   t  j    } x~ t  j    | | k  r y% x |  D] } | j d d  q/ WWn/ t j k
 r{ x |  D] } | j   qd Wq XPq Wt d   z	 d VWd x |  D] } | j   q WXd S(   s2  Try to acquire all locks.

    If any lock can't be immediately acquired, free all locks.
    If the timeout is reached withou acquiring all locks, free all locks and raise.

    http://stackoverflow.com/questions/9814008/multiple-mutex-locking-strategies-and-why-libraries-dont-use-address-comparison
    t   timeoutg?s   Failed to acquire all locksN(   R   t   acquiret   filelockt   Timeoutt   releaseR,   (   t   locksR  R   t   lock(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   try_acquire_locks  s    		c         C` s   t  } xX t j t j t j f D]> } y | |  |  t } PWq t t t f k
 r\ q q Xq W| s y5 t	 j
 d j |  |  d t d t	 j d t	 j Wq t	 j k
 r } t j j |  s t d j |  | |    q q Xn  d  S(   Ns   cp -a {} {}RJ   RK   R{   s'   Failed to copy {} to {}.  Error was: {}(   R   t   shutilt   copy2R   t   copyfileRW   t   IOErrorR?   t   PermissionErrorRT   R   RV   RY   Rc   R:   R<   R   (   t   srct   dstt	   is_copiedR   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   _copy_with_shell_fallback  s    c         C` s{   |  j  t j j  } | j  t j j  } x, | rX | d | d k rX | d =| d =q- Wt j j |   t j j |   f S(   Ni(   RX   R:   R<   t   sepR
   (   R  R  t   ssplitt   dsplit(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_prefix_replacement_paths  s    i  c         C` s  t  t  } | r t |   r y t j t j j |   Wn t k
 rN n Xt j j |  rq t j	 |  n  t
 |  |  \ } }	 t j |   }
 |
 j | |	  } t j | |  y5 t j |   } t j | j  } t j | |  WqqXnt |   r0t |  | | d | d | d | d | nt |  r`t j j | t j j |    } n | } t j j |   rt j j |   } nU t j j | k rt j j |  } t j j |  st j |  qn t j   } t j j |   r't j j t j j |    r'| j d |   d S| rI| rIt | d | } n  | rX| g n g  } t | |   t j j |  } | rt j j |  ry t j |  Wqt k
 rqXn  y t |  |  Wn3 t  j! k
 r| j" d t j j |   |  n XWd QXd S(   s>   Copy all the files and directories in src to the directory dstR  R
  t   lockingt   clobbers+   path %s is a broken symlink - ignoring copyNs"   skipping %s - already exists in %s(#   R   Ro   R   R:   t   makedirsR<   R   R?   t   lexistst   removeR  t   readlinkRb   t   symlinkt   lstatR;   t   S_IMODEt   st_modet   lchmodR	   t
   merge_treeR
   t   basenamet   isabsR  R   R   t   realpathR   t   get_lockR  R  R  t   Errort   debug(   R  R  R  t   symlinksR
  R  R  R   t   src_baset   dst_baset
   src_targett   src_replacedt   stt   modet   dst_fnt
   src_folderR	  t
   dst_folder(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt	   copy_into  s`    +$1	c         C` s{   y t  j |  |  Wn` t k
 rv t |  |  y t j |   Wqw t k
 rr t t  } | j d |   qw Xn Xd  S(   Ns8   Failed to clean up temp path due to permission error: %s(	   R  t   moveR  R5  R:   t   unlinkR   Ro   R*  (   R  R  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   move_with_fallbackJ  s    c         C` s  t  j j |  s2 t  j |  t j |  |  n  t  j |   } | r~ | |  |  } g  | D] } | | k r] | ^ q] } n  d | k r | j d  n  g  | D] } t  j j | |  ^ q }	 | sxt	 |  D] \ }
 } t  j j |  |  } |	 |
 } | rt  j j
 |  rt  j j |  r:t  j |  n  t  j t  j |  |  y5 t  j |  } t j | j  } t  j | |  WqqXq t  j j |  rt | | | |  q t | |  q Wn  |	 S(   Ns   .conda_lock(   R:   R<   R   R  R  t   copystatt   listdirR  R
   R   R   R  R  R  R   R;   R!  R"  R#  R	   t   copytreeR  (   R  R  R+  RN   t   dry_runt   lstt   exclt   xt   itemt   dst_lstt   idxR   t   dR0  R1  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR;  W  s8    ((
c      	   C` s3  t  j j t  j j |   } t  j j t  j j |    }  | j |   sd t d j |  |    t |  | d | d t } g  | D] } t	 |  r | ^ q }	 |	 r | r t
 d j |  | |	 d    n  g  }
 | r| s t |  d | } n  | g }
 n  t |
 |   t |  | d | Wd QXd S(   s   
    Merge src into dst recursively by copying all files from src into dst.
    Return a list of all files copied.

    Like copytree(src, dst), but raises an error if merging the two trees
    would overwrite any files.
    s{   Can't merge/copy source into subdirectory of itself.  Please create separate spaces for these things.
  src: {0}
  dst: {1}R+  R<  s*   Can't merge {0} into {1}: file exists: {2}i    R  N(   R:   R<   t   normpatht   normcaset
   startswitht   AssertionErrorRV   R;  RW   R   R  R(  R  (   R  R  R+  R  R
  R  R  t	   new_filesRH   t   existingR	  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR$  |  s     %	R	  t   ~s   .conda_build_locksc   	      C` sS  d  } y" t j j t j j |    } Wn t k
 rA |  } n X| } t | d  rf | j   } n  t j	 |  j
   } t | d  r | j   } n  x t D] } ys t j j |  s t j |  n  t j j | |  } t | d   } | j d  Wd  QXt j | |  } PWq t t f k
 r5q q Xq Wt d j t     | S(   NR   RL   t   wRP   s^   Could not write locks folder to either system location ({0})or user location ({1}).  Aborting.(   R   R:   R<   R   RD  R?   RZ   R   t   hashlibt   sha256t	   hexdigestRL   t   _lock_foldersR	   R  R
   t   openR|   R  t   FileLockR  t   RuntimeErrorRV   (	   t   folderR  t   flt   locationt
   b_locationt   lock_filenamet	   locks_dirt	   lock_fileRH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR(    s2    "
	c         C` s   g  } t  |  } |  r t d  } | t |  } xO | D]G } t j j |  sa t j |  n  t | d | } | j |  q9 W| j t d d |  n  | S(   Ni   R  s   conda-operation(	   t   ensure_listR   t   listR:   R<   R	   R  R(  R   (   R  t   bldpkgs_dirsR  R	  t
   _pkgs_dirst   locked_foldersRS  R
  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_conda_operation_locks  s    
t   libc         C` s  |  j  d  s t |    | j  d  s8 t |   | j d  j d  } | d g k rh g  } n  t |   j d  }  |  d g k r g  }  n  x> | r |  r | d |  d k r | j d  |  j d  q Wd j |  r d g t |   n d g |  S(   Nt   /RQ   RP   i    s   ..(   RF  RG  R]   RX   R   R   R
   Rr   (   RH   RC  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   relative  s    		#s   .7zs   .tars   .tar.bz2s   .tar.gzs	   .tar.lzmas   .tar.xzs   .tar.zs   .tar.zsts   .tgzs   .whls   .zips   .rpms   .debs   r:*c   	      C` s  |  j    j d  rr t j d  } | s< t j d  } n  | sR t j d  n  t | d |  g  |  d  }  n  t r |  j d  r t j d  } | s t j d	  n  t | d d
 |  g  |  d  }  n  t j	 |  |  } | j
   } x t | d  D] \ } } t j j | j  r=t j j | j d  | _ n  t j j | j  j t j    s|| j j d d  | _ n  t j j | j  j t j    st j d | j  n  | | | <q Wt s| j d | j t   n | j d |  | j   d  S(   Ns   .tar.zt
   uncompresst   gunzipsA   uncompress (or gunzip) is required to unarchive .z source files.
s   -fis   .tar.xzt   unxzs0   unxz is required to unarchive .xz source files.
s   -kii    Ra  s   ../RP   s   tarball contains unsafe path: R<   (   R   R   R-   t   find_executableRz   t   exitR   R   t   tarfileRP  t
   getmembersR   R:   R<   R&  t   namet   relpathR'  RF  R   Rb   t
   extractallR   R   Rx   (	   t   tarballt   dir_pathR1  Rc  Re  R   t   membersR   t   member(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   _tar_xf_fallback  s<    

$$c         C` s   d d l  m } | |  } t j j |   sL t j j t j   |   }  n  d  } d } t j	 |   q } xg | D]_ } | j
 | k rq | d 7} x9 | j   D]+ } | d  k r t |  } q | | 7} q WPqq qq WWd  QX| t |  k r t    n  | S(   Ni    (   RZ  i   (   t   conda_build.utilsRZ  R:   R<   R&  R
   R   R   t
   libarchivet   file_readerRj  t
   get_blockst   bytesRr   t   KeyError(   Rm  t   entriesRZ  t   resultt   n_foundt   archivet   entryt   block(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   tar_xf_file  s$    
c         C` ss   t  j j |   s0 t  j j t  j   |   }  n  g  } t j |   ( } x | D] } | j | j  qO WWd  QX| S(   N(	   R:   R<   R&  R
   R   Rs  Rt  R   Rj  (   Rm  Ry  R{  R|  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   tar_xf_getnames$  s    c         C` s   t  j j t  j j Bt  j j Bt  j j Bt  j j B} t j j	 |   sd t j j
 t j   |   }  n  y' t |   t  j |  |  Wd  QXWn9 t  j j k
 r |  j d  r t |  |  q   n Xd  S(   Ns   .tars   .tar.gzs   .tgzs   .tar.bz2s   .tar.zs   .tar.xz(   s   .tars   .tar.gzs   .tgzs   .tar.bz2s   .tar.zs   .tar.xz(   Rs  t   extractt   EXTRACT_TIMEt   EXTRACT_PERMt   EXTRACT_SECURE_NODOTDOTt   EXTRACT_SECURE_SYMLINKSt   EXTRACT_SECURE_NOABSOLUTEPATHSR:   R<   R&  R
   R   t	   tmp_chdirt   extract_filet	   exceptiont   ArchiveErrorR   Rq  (   Rm  Rn  t   flags(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR   .  s    'c         C` s;   i t  |   d 6t |   d 6t |  d  d 6t |   d 6S(   Nt   sizet   md5RM  t   mtime(   R   R   R   R   (   R<   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt	   file_infoC  s    c         C` s   t  |   s t |   }  n  t d    } x" | D] } | |  |  |  q1 Wi  } x' t |  D] \ } } | j | | <qb W| S(   s   Group a collection by a key function
    >>> names = ['Alice', 'Bob', 'Charlie', 'Dan', 'Edith', 'Frank']
    >>> groupby(len, names)  # doctest: +SKIP
    {3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
    >>> iseven = lambda x: x % 2 == 0
    >>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8])  # doctest: +SKIP
    {False: [1, 3, 5, 7], True: [2, 4, 6, 8]}
    Non-callable keys imply grouping on a member.
    >>> groupby('gender', [{'name': 'Alice', 'gender': 'F'},
    ...                    {'name': 'Bob', 'gender': 'M'},
    ...                    {'name': 'Charlie', 'gender': 'M'}]) # doctest:+SKIP
    {'F': [{'gender': 'F', 'name': 'Alice'}],
     'M': [{'gender': 'M', 'name': 'Bob'},
           {'gender': 'M', 'name': 'Charlie'}]}
    See Also:
        countby
    c           S` s   g  j  S(   N(   R   (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRt   `  RP   (   t   callablet   getterR   R   t   __self__(   Rq   t   seqRC  R@  t   rvR   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   groupbyL  s    c         ` sf   t    t  rU t    d k r8   d     f d   S  rK t j     Sd   Sn t j    Sd  S(   Ni   i    c         ` s   |    f S(   N(    (   R?  (   t   index(    s0   lib/python2.7/site-packages/conda_build/utils.pyRt   m  RP   c         S` s   d S(   N(    (    (   R?  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRt   q  RP   (   t
   isinstanceR[  Rr   t   operatort
   itemgetter(   R  (    (   R  s0   lib/python2.7/site-packages/conda_build/utils.pyR  i  s    

c         C` s<   t  |   d k r d j |   Sd j |  d   d |  d S(   s   
    Like ', '.join(items) but with and

    Examples:

    >>> comma_join(['a'])
    'a'
    >>> comma_join(['a', 'b'])
    'a and b'
    >>> comma_join(['a', 'b', 'c])
    'a, b, and c'
    i   s    and s   , is   , and (   Rr   R
   (   Ry   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt
   comma_joinv  s    c          O` s   | j  d d  } | j  d d  } | j  d d  } t rN t j j j } n t j j } | j |   | } t j j p| d } | | j | |   d S(	   sG  
    prints unicode strings to stdout using configurable `errors` handler for
    encoding errors

    :param args: unicode strings to print to stdout
    :param sep: separator (defaults to ' ')
    :param end: ending character (defaults to '
')
    :param errors: error handler for encoding errors (defaults to 'replace')
    R  u    t   endu   
RM   Rb   t   utf8N(	   R   R   Rz   R{   t   bufferR|   R
   t   encodingR   (   Rl   Rm   R  R  RM   R   R   R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   safe_print_unicode  s    
c         C` s   g  } x t  |   D]v } g  } x+ | D]# } | j t j | d |   q& W| r | j g  | D] } t j j | d |  ^ q`  q q W| S(   Ni   i    (   R9   t   extendt   fnmatcht   filterR:   R<   R
   (   R<   t   patternsRy  t   d_ft   mRh   RH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   rec_glob  s    !:c         C` sm   t  j d  r] d j |   } t r6 t j |  }  qi t j | j    j   j d  }  n t	 |   }  |  S(   Nt   cygpaths   cygpath -w {0}s   \(
   R-   Rf  RV   R   RT   t	   getoutputRU   RX   R   R   (   R<   t   cmd(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   convert_unix_path_to_win  s    'c         C` sm   t  j d  r] d j |   } t r6 t j |  }  qi t j | j    j   j d  }  n t	 |   }  |  S(   NR  s   cygpath -u {0}s   \(
   R-   Rf  RV   R   RT   R  RU   RX   R   R   (   R<   R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   convert_win_path_to_unix  s    'c         C` s   t  j d t j |    S(   Ns   file:(   t   urlparset   urljoint   urllibt   pathname2url(   R<   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   path2url  s    c         C` s   t  j d k r' t j j |  d  } np t j j |  d  } t t j j | d   } | ry t j j | | d  } n t j j | d j |   } | S(   NR4   t   LibR`  s	   python?.*i    s   python{}(   Rz   R   R:   R<   R
   R.   RV   (   R   t   py_vert   lib_dirt   python_folder(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_stdlib_dir  s    c         C` s   t  j j t |  |  d  S(   Ns   site-packages(   R:   R<   R
   R  (   R   R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_site_packages  s    c         C` s%   t  t j j |  d d d d   S(   Nt   *s   [0-9]i
   (   R.   R:   R<   R
   (   t   croot(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_build_folders  s    c         C` s   t  | t  t j |  d |  d <t j d k r t  | d d d  t j t  | d d d  t j t j t  | d d  t j t  | d  t j |  d |  d <t } n  | r | t j |  d |  d <n  |  S(   Nt   PATHR4   t   Librarys	   mingw-w64R6   t   usrR5   (   R
   t   bin_dirnameR:   t   pathsepRz   R   RW   (   R   R   t   prepend_prefix(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   prepend_bin_path  s    "e	c         c` s   t  j } t r8 t  j j d t j j |  d d   ne t j j |  d  } t t j j | d   } | r | d } t  j j d t j j | d   n  z	 d  VWd  | t  _ Xd  S(   Ni   R`  s   site-packagess   python[0-9\.]*i    (   Rz   R<   RS   t   insertR:   R
   R.   (   R   t   path_backupR  t
   python_dir(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   sys_path_prepended  s    
(
%	c         c` sQ   t  j d } t t  j j   |  t  d t  j d <z	 d  VWd  | t  j d <Xd  S(   NR  (   R:   R   R  R   RW   (   R   t   old_path(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   path_prepended  s
    &	s*   \s*([\w\-\.]+)\s*=\s*([\w.]+):([\w.]+)\s*$c         c` sO   xH |  D]@ } t  j |  } | d  k r< t j d |  n  | j   Vq Wd  S(   Ns%   Error cound not match entry point: %r(   t	   entry_patt   matchR   Rz   Rg  t   groups(   Ry   R@  R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   iter_entry_points  s
    c      
   C` sK  | j  d  d } t i | d 6| d 6| d 6} t r t |  d d   } t j j t j j | j d   r | j	 d	  n  | j	 |  t
 t t t  d
 j t | j    |  d | j  Wd  QXnw t j j |   r t j |   n  t |  d  4 } | j s$| j	 d | j  n  | j	 |  Wd  QXt j |  d  d  S(   NRQ   i    t   moduleR   t   import_names
   -script.pyRK  s   python_d.exes   #!python_d
s
   cli-{}.exes   .exes   #!%s
i  (   RX   t   PY_TMPLRS   RP  R:   R<   R   R
   t   host_prefixR|   R5  R   t   __file__RV   R   t	   host_archR  R   R  R7   t   host_pythont   chmod(   R<   R  R   t   configR  t   pyscriptt   fo(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   create_entry_point  s"    $'	c         C` sx   |  s
 d  St  | j t  } t |  s8 t j |  n  x9 t |   D]+ \ } } } t t  | |  | | |  qE Wd  S(   N(   R
   R  R  R	   R:   t   mkdirR  R  (   Ry   R  t   bin_dirR  R  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   create_entry_points/  s    c         c` s[   xT t  |   D]F \ } } } x4 | D], } | j |  r# t j j | |  Vq# q# Wq Wd  S(   N(   R9   R   R:   R<   R
   (   t
   start_pathRh   RE   RF   RG   RH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_ext_files:  s    c         C` s   t  j d k r | S|  t k rn t |  d  ; } | j   } t j d |  } | r[ t n t t |  <Wd QXn  t |  r y/ t	 d d | g  j
   d j t    } Wq t k
 r t t  } | j d  q Xn  | S(	   sK   If exe is a Cygwin or MSYS2 executable then filters it through `cygpath -u`R4   t   rbs   (cygwin1.dll|msys-2.0.dll)NR  s   -ui    sJ   cygpath executable not found.  Passing native path.  This is OK for msys2.(   Rz   R   t   _posix_exes_cacheRP  R}   R_   t   findallRW   R   R   t
   splitlinesRL   R   t   WindowsErrorR   Ro   R*  (   t   exeR<   t   exe_filet
   exe_binaryt   msys2_cygwinR   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt    convert_path_for_cygwin_or_msys2D  s    
	&c         ` s2   d j    j     j   f d     j   D  S(   NsC   Skipped: {} from {} defines build/skip for this configuration ({}).c         ` s#   i  |  ] }   j  j | |  q S(    (   R  t   variant(   R   R   (   R  (    s0   lib/python2.7/site-packages/conda_build/utils.pys
   <dictcomp>Z  s   	 (   RV   Rj  R<   t   get_used_vars(   R  (    (   R  s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_skip_messageW  s    c   
   	   C` s  t    } t j j t j j |    } | t k r9 | n d } t | d d it j j t j j	 |    } y t
 j   j } Wn t k
 r t d } n X| r t j j | |  n | } t j j | |  } t j j | |  } t j j |  s| rC| j d  r-t j j |  | d  qCt j j |  |  n  t j j |  sYt Sy% t |   } | j   }	 Wd  QXWn5 t k
 rt | d   } | j   }	 Wd  QXn XWd  QX|	 S(   NRP   R  i  i    R   R  (   R_  R:   R<   R%  R   t   DEFAULT_SUBDIRSR  t   conda_package_handlingt   apit   get_default_extracted_folderR   t   first_writablet   pkgs_dirt   AttributeErrorR   R
   R   RF  R  R   RP  R}   R[   (
   t   package_patht	   file_patht   refreshR	  t   possible_subdirt   folder_namet
   cache_patht   resolved_file_pathRH   t   content(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   package_has_file]  s2    	!c         C` sD   t  |  t  s t |  d  r@ |  d  k	 r7 |  g }  q@ g  }  n  |  S(   Nt   __iter__(   R  R   RZ   R   (   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRZ  ~  s
    	c         c` s7   t  j   } z t  j |   d  VWd  t  j |  Xd  S(   N(   R:   R   t   chdir(   t   destt   curdir(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR    s
    	c         C` sV  g  } x |  D] } t  j j |  s= t  j j | |  } n  t  j j |  r_ | j |  q t  j j |  r | j |  q t  j j |  r | j d   t	 |  D  q t
 |  } | s t t  } | j d j | |   n  | j |  q Wt j d t j d | t  j j f   } g  | D] } | j d | d  ^ q1} | S(   Nc         s` s:   |  ]0 \ } } } | D] } t  j j | |  Vq q d  S(   N(   R:   R<   R
   (   R   RE   RF   t   fsRH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>  s    s$   Glob {} did not match in root_dir {}t   ^s   %s%sRP   i   (   R:   R<   R&  R
   R   R   R   R	   R  R9   R.   R   Ro   t   errorRV   R_   t   compilet   escapeR  t   sub(   t	   path_listR   RG   R<   t
   glob_filesR   t   prefix_path_reRH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   expand_globs  s$     ,(c         C` s   t  j j |   r: t  j j |   d k r: t  j j |   St |  d d g  } t |  d k r t  j j |  d  } | | k r t t	  j
 d  | g } q t d |    n | s t d |    n  | d S(	   s   recurse through a folder, locating meta.yaml.  Raises error if more than one is found.

    Returns folder containing meta.yaml, to be built.

    If we have a base level meta.yaml and other supplemental ones, use that firsts	   meta.yamls
   conda.yamli   sV   Multiple meta.yaml files found. The meta.yaml file in the base directory will be used.s)   More than one meta.yaml files found in %ss,   No meta.yaml or conda.yaml files found in %si    (   s	   meta.yamls
   conda.yaml(   R:   R<   R   R%  R   R  Rr   R
   R   Ro   R   R  (   R<   t   resultst   base_recipe(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   find_recipe  s    *t   LoggingContextc           B` sk   e  Z d  d d d d d d d d d	 d
 d d d d d d g Z e j d e d d  Z d   Z d   Z	 RS(   t   condat   binstart   installs   conda.installt   fetchs   conda.instructionss   fetch.progressR   t   progresst	   dotupdatet	   stdoutlogt   requestss   conda.core.package_caches
   conda.plans   conda.gateways.disk.deletet   conda_builds   conda_build.indexc         C` sR   | |  _  i  |  _ | |  _ | |  _ t j |  _ | sE t j |  _ n	 | |  _ d  S(   N(	   t   levelt
   old_levelst   handlerRx   R&   t   quietR	  t   default_loggerst   loggers(   Rk   R  R  Rx   R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s    				c         C` s   x} |  j  D]r } t | t  r1 t j |  } n  | j |  j | <| j d | k se |  j t j k  rn |  j n
 |  j d  q
 W|  j	 r |  j
 j |  j	  n  t t _ d  S(   NR  i
   (   R  R  R   t   loggingt	   getLoggerR  R  t   setLevelt   INFOR  t   loggert
   addHandlerRW   R&   R  (   Rk   R  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt	   __enter__  s    -	c         C` s   x3 |  j  j   D]" \ } } t j |  j |  q W|  j rU |  j j |  j  n  |  j rw |  j rw |  j j   n  |  j	 t
 _	 d  S(   N(   R  Ry   R  R  R  R  R  t   removeHandlerRx   R  R&   (   Rk   t   ett   evt   tbR  R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   __exit__  s    	N(
   Ro   Rp   R  R  t   WARNR   RW   R   R  R$  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR	    s   		c      	   C` sh   t    } xX t t j j |  d d   D]8 } t |  $ } t j |  } | | | d <Wd QXq( W| S(   s   
    Scan all json files in 'path' and return a dictionary with their contents.
    Files are assumed to be in 'index.json' format.
    s
   conda-metas   *.jsonRj  N(   R   R.   R:   R<   R
   RP  t   jsont   load(   R<   t	   installedt   filenamet   filet   data(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   get_installed_packages  s    	%c         C` s   x |  j    D] \ } } t | d  rA t t |   |  | <q t | d  r t | t  r y  t t t |    |  | <Wq t	 k
 r t t t d   | D    |  | <q Xq q W|  S(   Nt   keysR  c         s` s   |  ] } t  |  Vq d  S(   N(   t   tuple(   R   RF   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>  s    (
   Ry   RZ   t   HashableDictt   _convert_lists_to_setsR  R   R   R[  R>   R~   (   t   _dictR   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR0    s     1R/  c           B` s    e  Z d  Z d   Z d   Z RS(   sb   use hashable frozen dictionaries for resources and resource types so that they can be in sets
    c         O` s)   t  t |   j | |   t |   }  d  S(   N(   t   superR/  R   R0  (   Rk   Rl   Rm   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s    c         C` s   t  t j |  d t  S(   Nt	   sort_keys(   t   hashR&  t   dumpsRW   (   Rk   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   __hash__	  s    (   Ro   Rp   t   __doc__R   R6  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR/    s   	c         C` sg   g  } xK | j    D]= \ } } |  j |  } |  j |  } | j | | f  q Wt j j d |  S(   Nu   tag:yaml.org,2002:map(   Ry   t   represent_dataR   t   yamlt   nodest   MappingNode(   t   dumperR+  R   t   item_keyt
   item_valuet   node_keyt
   node_value(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   represent_hashabledict  s    c          c` s   d d  l  }  |  j |  j } } z- t   t   g } | \ |  _ |  _ | VWd  | | |  _ |  _ | d j   | d <| d j   | d <Xd  S(   Ni    i   (   Rz   R{   RK   R   t   getvalue(   Rz   t   oldoutt   olderrRg   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   capture  s    	c         c` s   t  |   t  |  }  } t j j |   } z& | t j |  <| rK |   n  d  VWd  | rj | t j |  <n
 t j |  =| r |   n  Xd  S(   N(   R   R:   R   R   (   Rj  R   t   callbackt   saved_env_var(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   env_var,  s    
	
c         C` s  t    } d } x |  j   D] \ } } t | d  rD t |  n  | t   k sz | d k sz | d  k sz | t   k r | j |  n  | r | | k r | j |  q q Wd |  k r t d   |  d D  r | j d  n  x | D] } |  | =q Wd  S(   Nt   finalt   noarch_pythont   zip_keysR-  RP   c         s` s   |  ] } | Vq d  S(   N(    (   R   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>M  s    (   RI  RJ  RK  (	   R>   Ry   RZ   t   trim_empty_keysR[  R   R   RA   t   any(   t   dict_t	   to_removet   negative_means_emptyR   R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRL  @  s    	6'c         C` sa   y3 | r d } n d } t  t |   d  | } Wn' t k
 r\ t t |   d  } n X| S(   Nt   as   .0a0i   (   R   Rd   Re   t   chrt   ord(   t   versiont	   alpha_vert   suffixt   last_version(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt
   _incrementS  s    	s   x.x.x.x.x.x.xR?  c         C` sN  g  | | f D]' } | r. t  | j d   n d  ^ q } t |   j d } d  } g  } xL t |  D]> \ } }	 t |	 t  r | } | j |	  qf | j	 |	  qf W| r t  | j d   t  |  k r t  |  | d <n  d d g }
 x t |  D] \ } } | r x t | |   D] \ } } | d k r| | d k rt
 | t | t  |  d   j   } t | |  } n  |
 | c t
 |  7<| | k r|
 | c d 7<qqW|
 | d d k r|
 | d  |
 | <qq q W|
 d r	d |
 d |
 d <n  |
 d r(d |
 d |
 d <n  d j g  |
 D] } | r5| ^ q5 S(	   NRQ   i   RP   ii    s   >=t   <RO   (   Rr   RX   R   R    RT  R   R  R[  R  R   R   t   mint   isalphaRX  R
   (   RT  t   min_pint   max_pint   pt   pinst   parsed_versiont   nesting_positiont	   flat_listRB  R@  t   versionst   p_idxt   pint   v_idxR   RU  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   apply_pin_expressions_  s8    :')

s   (.*[\\/])?\.git[\\/].*s   (.*[\\/])?\.git$s   (.*)?\.DS_Store.*s   .*\.la$s   conda-meta.*s   .*\.conda_trash(?:_\d+)*$c         C` s   x? | D]7 } t  j |  } t |   t t | j |    }  q Wg  |  D]O } t j j t j j | |   s t j j	 t j j | |   rI | ^ qI S(   sI   Remove things like the .git directory from the list of files to be copied(
   R_   R  R>   R  R  R:   R<   R	   R
   R   (   t
   files_listR   t   filter_patternsRh   R   RH   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   filter_files  s    &"c         C` s   t  |  | d d S(   NRi  s   info[\\/]index.jsons   info[\\/]filess   info[\\/]paths.jsons   info[\\/]about.jsons   info[\\/]has_prefixs   info[\\/]hash_input_filess   info[\\/]hash_input.jsons   info[\\/]run_exports.yamls   info[\\/]run_exports.jsons   info[\\/]gits   info[\\/]recipe[\\/].*s   info[\\/]recipe_log.jsons   info[\\/]recipe.tars   info[\\/]test[\\/].*s   info[\\/]LICENSE.txts   info[\\/]licenses[\\/]*s   info[\\/]requiress   info[\\/]metas   info[\\/]platforms   info[\\/]no_links   info[\\/]link.jsons   info[\\/]icon.png(   s   info[\\/]index.jsons   info[\\/]filess   info[\\/]paths.jsons   info[\\/]about.jsons   info[\\/]has_prefixs   info[\\/]hash_input_filess   info[\\/]hash_input.jsons   info[\\/]run_exports.yamls   info[\\/]run_exports.jsons   info[\\/]gits   info[\\/]recipe[\\/].*s   info[\\/]recipe_log.jsons   info[\\/]recipe.tars   info[\\/]test[\\/].*s   info[\\/]LICENSE.txts   info[\\/]licenses[\\/]*s   info[\\/]requiress   info[\\/]metas   info[\\/]platforms   info[\\/]no_links   info[\\/]link.jsons   info[\\/]icon.png(   Rj  (   Rh  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   filter_info_files  s.                         c         C` s   t  r t |   St j j |   r y t rJ t j d j |   d t	 nX y t j
 d  Wn n Xd } t j | j |   j    y t j d  Wn n XWq q Xn  t j } | r | j r t j } n  t |   t |   Wd  QXd  S(   Ns   rd /s /q {}RJ   s   .emptys   rsync -a --delete .empty {}/(   R$   t   _rm_rfR:   R<   R	   RS   RT   R   RV   RW   R  RX   R  t   rmtreeR  R%  R*  t   DEBUGR	  (   R<   R  t   del_dir_cmdt   conda_log_level(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR+     s.    
	t   LessThanFilterc           B` s   e  Z d  d  Z d   Z RS(   RP   c         C` s#   t  t |   j |  | |  _ d  S(   N(   R2  Rq  R   t	   max_level(   Rk   t   exclusive_maximumRj  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s    c         C` s   | j  |  j k  r d Sd S(   Ni   i    (   t   levelnoRr  (   Rk   t   record(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR    s    (   Ro   Rp   R   R  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRq    s   t   GreaterThanFilterc           B` s   e  Z d  d  Z d   Z RS(   RP   c         C` s#   t  t |   j |  | |  _ d  S(   N(   R2  Rv  R   t	   min_level(   Rk   t   exclusive_minimumRj  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s    c         C` s   | j  |  j k r d Sd S(   Ni   i    (   Rt  Rw  (   Rk   Ru  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR    s    (   Ro   Rp   R   R  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRv    s   t   DuplicateFilterc           B` s   e  Z d    Z d   Z RS(   c         C` s   t    |  _ d  S(   N(   R>   t   msgs(   Rk   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s    c         C` s/   | j  |  j k } |  j j | j   t |  S(   N(   t   msgRz  RA   Rd   (   Rk   Ru  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR    s    (   Ro   Rp   R   R  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyRy    s   	R  s   conda.core.linked_datas   conda.gateways.disk.deletes   conda.gateways.disk.testc           C` s   t    a d S(   s   Most of the time, we want the deduplication.  There are some cases (tests especially)
    where we want to be able to control the duplication.N(   Ry  t   dedupe_filter(    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   reset_deduplicator  s    c   
      C` s[  d  } t j d  r9 t t t t j d     } n  | r t |   } t j |  } Wd  QXt	 j
 j |  | j d i   j |  i   j d |  } n  t	 j |   } | j |  | r | j t  n  | j rW| rWt	 j t j  } t	 j t j  }	 | j t  |	 j t  | j |  |	 j |  | j |  | j |	  n  | S(   Nt   log_config_fileR  R  (   R   R"   R   R   R   R   RP  R9  t	   safe_loadR  R  t
   dictConfigR  R  t	   addFilterR|  t   handlerst   StreamHandlerRz   R{   RK   t   info_debug_stdout_filtert   warning_error_stderr_filterR  (
   Rj  R  t   dedupet   add_stdout_stderr_handlerst   config_fileRH   t   config_dictR   t   stdout_handlert   stderr_handler(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR     s,    $-c         C` s   | |  k } t  | t  r t  |  t  r t j j |   sl t j j t j j t j j | |     }  n  t j j |  s t j j t j j t j j | |    } n  | |  | k O} n  | S(   N(   R  R   R:   R<   R&  R   RD  R
   (   t
   base_valueR   R<   t
   equivalent(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   _equivalent   s    00RP   c   
      C` s  |  | k r |  St  t  } x| j   D]\ } } | |  k sG | r) |  j | |  }	 t | d  r t |	 | | | d | }	 |	 |  | <qt | d  r7t | t  r7| r*|	 | k r y |	 j |  Wq t	 t
 f k
 r | }	 q Xn  y t |	  |  | <Wq4t	 k
 r&|	 |  | <q4Xq| |  | <q|	 r{| r{t |	 | |  r{| r{| j d j | |	 |   n  | d  k r| |  k r|  | =q| |  | <q) q) W|  S(   NR-  t   raise_on_clobberR  s3   clobbering key {} (original value {}) with value {}(   R   Ro   Ry   R   RZ   t   merge_or_update_dictR  R   R  R~   R  R[  R  R*  RV   R   (
   t   baset   newR<   t   mergeR  t   add_missing_keysR   Rq   R   R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR  +  s<    	
c         ` s;   t     j   } g   t     f d   | D  S(   sI   
    From Alex Martelli: https://stackoverflow.com/a/1495821/3257826
    c         3` s7   |  ]- } |   j  |    j  |   f Vq d  S(   N(   R   (   R   R   (   t   dol1t   dol2t   no(    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>U  s    (   R>   t   unionR   (   R  R  R-  (    (   R  R  R  s0   lib/python2.7/site-packages/conda_build/utils.pyt   merge_dicts_of_listsO  s    c   	      C` s   t    } |  t j j } x t |   D] \ } } } x3 | D]+ } | j t | |  j | d d   q< Wxa | D]Y } t | |  } t |  rr | j | j | d d   | j	 t
 | f |    qr qr Wq& W| S(   s/   
    Returns a set of all files in prefix.
    RP   i   (   R>   R:   R<   R  R9   RA   R
   Rb   R   R   R  (	   R   t   rest
   prefix_repRE   t   dirsRG   t   fnt   dnR<   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   prefix_filesX  s    	)$c         C` s   t  rG | r. t j |  | d | d | d | St j |  | d | SnJ | ru t j |  | d | d | d | d | St j |  | d | d | Sd S(   s;  
    Hides the differences between mmap.mmap on Windows and Unix.
    Windows has `tagname`.
    Unix does not, but makes up for it with `flags` and `prot`.
    On both, the default value for `access` is determined from how the file
    was opened so must not be passed in at all to get this default behaviour.
    t   tagnamet   accesst   offsetR  t   protN(   RS   t   mmap(   t   filenot   lengthR  R  R  R  R  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt	   mmap_mmapj  s    	"(c         C` s   t  r t j j |  d  } n t j j |  d  } t j j |  r x t j |  D] } t j j | |  } t j j |  r | j t j  d k r t j	 |  qU t j j
 |  rU | j d  rU t j |  qU qU Wn  d S(   s9   Remove pip created pycache directory from bin or Scripts.R5   R6   t   __pycache__s   .pycN(   RS   R:   R<   R
   R	   R:  R]   R  R  Rm  R   R   R  (   t   build_prefixt   scripts_pathR|  t
   entry_path(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   remove_pycache_from_scripts  s    *!c         C` s  x|  j    D]
\ } } t | t  r x | j   D]z } |  | | } t | t  re t |  q5 t | t  r5 d j | |  | k r5 t d   | D  r5 | j   q5 q5 Wq t | t  r x* | D]" } t | t  r t |  q q Wy | j   Wqt	 k
 rqXq q Wd S(   s6  Recurse through a nested dictionary and sort any lists that are found.

    If the list that is found contains anything but strings, it is skipped
    as we can't compare lists containing different types. The omissions argument
    allows for certain sections of the dictionary to be omitted from sorting.
    s   {}/{}c         s` s   |  ] } t  | t  Vq d  S(   N(   R  R   (   R   R@  (    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>  s    N(
   Ry   R  R   R-  t   sort_list_in_nested_structureR[  RV   t   allt   sortR~   (   t
   dictionaryt	   omissionst   fieldR   Rq   t   sectiont   element(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyR    s$    sD   ([\w\d\.\-\_]+)\s+((?<![><=])[\w\d\.\-\_]+?(?!\*))(\s+[\w\d\.\_]+)?$s   ^([0-9a-zA-Z\.]+)$c         C` s  t  |  t  r t |  d  r{|  j r{|  j d d  r{t j t |  j   r{t |  j  d k s| t |  j  d k r t d j	 t |  j  t |  j  d   }  q q{n t
 j |   } | r{| j d	  r{| j d
  d k r| j d  d k rt
 j d |   }  q{d |  k r{| j d
  d k rc| rct t  } | j d j	 |    n  t
 j d |   }  q{n  |  S(   NRT  t   buildRP   t   pythont   numpys   x.xs   {} {}s   .*i   i   i   s   \1 \2R  t   vcs`  Adding .* to spec '{}' to ensure satisfiability.  Please consider putting {{{{ var_name }}}}.* or some relational operator (>/</>=/<=) on this spec in meta.yaml, or if req is also a build req, using {{{{ pin_compatible() }}}} jinja2 function instead.  See https://conda.io/docs/user-guide/tasks/build-packages/variants.html#pinning-at-the-variant-levels   \1 \2.*(   R  R  (   R  R  (   R  R  (   R  R!   RZ   RT  R   t   spec_ver_needing_star_reR  R   Rj  RV   t   spec_needing_star_reRa   R  R   Ro   R   (   t   specR   R  R   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   ensure_valid_spec  s     +*7*c      	   C` s  t  |  j d   t  |  j d   } t  |  j |   } x| j   D] \ } } t j d | j d d   } g  | D] } | j |  ^ q| }	 t |	  rJ x t |	  D] \ }
 } | r | d
 k s | j	 d  | k r | |
 =t
 | t  s| d } n  | j |
 t d j | j	 d  | f    q q WqJ qJ Wt j d	  } g  | D] } | j |  ^ qX}	 t |	  rxm t |	  D]\ \ }
 } | r| |
 =| j |
 t d j | j	 d  | j | j	 d   f    qqWn  | r| |  | <n  d  S(   NR  t   hosts   ^(%s)(?:\s*$)RF   s   [-_]i   i    RR   s   ([0-9a-zA-Z\.\-\_]+)\s+x\.x(   R  R  (   RZ  R   Ry   R_   R  Rb   R  RM  R   Ra   R  R   R  R  R
   (   t   requirements_dictR  R   t
   build_depst   reqsRq   t   valt   regext   pkgt   matchesR   R?  t   xx_re(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   insert_variant_versions  s,    "'<"Jc         C` s  i | j    d 6| j   d 6d d 6} t r t d | d d d j | d | d | d f  d | d d | d d t | j   p d	  d
 d  } n  |  j |  } t	 } | r| j
   } xJ | j
   D]9 } | | k r | | j j | | j j | k M} q q Wn  | o| S(   s  target_matchspec comes from the recipe.  target_variant is the variant from the recipe whose
    deps we are matching.  m is the peer job, which must satisfy conda and also have matching keys
    for any keys that are shared between target_variant and m.config.variantRj  RT  RP   R  t	   dist_namet   -t   build_stringt   build_numberi    t   channelN(   Rj  RT  R#   R%   R
   Rd   R  R   R  RW   t   get_used_loop_varsR  R  (   t   target_matchspect   other_mt   this_mt
   match_dictt   matchspec_matchest   variant_matchest   other_m_used_varsR   (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   match_peer_job  s(    


.c         C` st   t  |  d  sK t |   } | rB i t |  d 6t |  d 6n i  }  n% x" |  D] } t |  |  |  | <qR W|  S(   NR-  R  t   run(   RZ   RZ  (   t
   reqs_entryt   originalt   sec(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   expand_reqs  s    /i   c         ` sq   t  |   s d  St j   } t |  d  :  x0 t    f d   d  D] } | j |  qJ WWd  QX| j   S(   NR  c           ` s    j     S(   N(   R}   (    (   t
   buffersizeRH   (    s0   lib/python2.7/site-packages/conda_build/utils.pyRt     RP   RP   (   R   R   RL  RM  RP  t   iterR   RN  (   R)  R  RM  R}  (    (   R  RH   s0   lib/python2.7/site-packages/conda_build/utils.pyt   sha256_checksum  s    "c         C` sT  t  r" |  j d j d t   n  | j r t | j j d d  } t |  s t	 t
 |   sw t j t
 |   n  t | d  j   n  t  r |  j d j d t d | j j   q |  j d j d t d | j j   |  j d	  |  j d
  n  t  r+|  j d j d t d | j j   n% |  j d j d t d | j j   d  S(   Ns/   call "{conda_root}\..\condabin\conda_hook.bat"
t
   conda_roots
   conda-metat   historyRQ  s>   call "{conda_root}\..\condabin\conda.bat" activate "{prefix}"
R   s,   call "{conda_root}\activate.bat" "{prefix}"
s+   set "PATH=%PATH:CONDA_PATH_PLACEHOLDER;=%"
s   set CONDA_MAX_SHLVL=2
sF   call "{conda_root}\..\condabin\conda.bat" activate --stack "{prefix}"
(   R$   R|   RV   t   root_script_dirt   is_crossR
   R  R  R   R	   R   R:   R  RP  Rx   R  (   t   file_handleR  t   history_file(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   write_bat_activation_text   s2    	c         C` s  |  j  d  s |  t k r t |   j   } t d   | D  } i  } x | D] } t   u } t j j | d  } y9 t	 | d |  t
 |   } t j |  } Wd  QXWn t t f k
 r i  } n XWd  QXt | |  qP W| t |  <n
 t |  } | S(   Ns   file://c         s` s%   |  ] } | j  d  d  d Vq d S(   Ra  i   i    N(   R^   (   R   t   url(    (    s0   lib/python2.7/site-packages/conda_build/utils.pys	   <genexpr>\  s    s   channeldata.jsons   /channeldata.json(   RF  t   channeldata_cacheR)   t   urlsR>   R(   R:   R<   R
   R'   RP  R&  R'  R   R*   R  (   t   channel_urlR  R+  R  t   tdt   tfRH   t   new_channeldata(    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   download_channeldataX  s"    
(   s   .7zs   .tars   .tar.bz2s   .tar.gzs	   .tar.lzmas   .tar.xzs   .tar.zs   .tar.zsts   .tgzs   .whls   .zips   .rpms   .deb(   s   (.*[\\/])?\.git[\\/].*s   (.*[\\/])?\.git$s   (.*)?\.DS_Store.*s   .*\.la$s   conda-meta.*s   .*\.conda_trash(?:_\d+)*$(   t
   __future__R    R   R   t   collectionsR   R   t
   contextlibR  RL  R&  t   localeR   Rs  R  t   logging.configR  R  R:   t   os.pathR   R   R   R	   R
   R   R   R   R   R   R_   R;   RT   Rz   R  Rh  R   t	   threadingR   R   t   json.decoderR   R   Re   R9  R  t   conda_package_handling.apiR  t   conda.base.constantsR   t	   ExceptionR   t	   conda.apiR   t   conda_interfaceR   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   t   conda_build.conda_interfaceR+   Rl  t   conda_build.exceptionsR,   t   conda_build.os_utilsR-   R.   R0   RW   t   urllib.parset   parseR  t   urllib.requestt   requestR  R2   R  t   FileNotFoundErrort   glob2R3   t   contextlib2R?   R   RS   R   R<   R  t   MAP_PRIVATEt   mmap_MAP_PRIVATEt	   PROT_READt   mmap_PROT_READt
   PROT_WRITEt   mmap_PROT_WRITER  R  R8   R9   R=   RI   Ri   t   objectRj   R   R   R   R   R   R   R  t   contextmanagerR  R  R  R   R   R5  R8  R;  R$  RO  R(  R_  Rb  R   Rq  R~  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  RZ  R  R  R  R	  R,  R0  R   R/  RA  t   add_representerRE  RH  RL  RX  Rg  Rj  Rk  t   FilterRq  Rv  Ry  R|  t   WARNINGR  R  R  R  R  R%  R}  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s0   lib/python2.7/site-packages/conda_build/utils.pyt   <module>   s  F
""	!			%	2d	3				.			=	%"$  &		
														
						!		
		*					%     
	"

			$				&		
	5