ó
?]c           @   s  d  Z  d d l Z d d l Z d d l m Z y  d d l m Z m Z m Z Wn- e	 k
 r} d d l m Z m Z m
 Z n Xd d l m Z d d l m Z d d	 l m Z d d
 l m Z m Z d Z d Z d   Z e j   d  Z d e f d     YZ d S(   s   The 'new' conda format, introduced in late 2018/early 2019.  Spec at
https://anaconda.atlassian.net/wiki/spaces/AD/pages/90210540/Conda+package+format+v2i˙˙˙˙N(   t   NamedTemporaryFile(   t   ZipFilet
   BadZipFilet
   ZIP_STORED(   R   R   t
   BadZipfilei   (   t   utils(   t   InvalidArchiveError(   t   AbstractBaseFormat(   t   create_compressed_tarballt   _tar_xfi   s   .tar.zstt   zstds   zstd:compression-level=22c         C   sM   |  j    } d j | | f  } g  | D] } | j |  r( | ^ q( } | S(   Nt   -(   t   namelistt   joint
   startswith(   t   zft   file_idt   component_namet   contentst   component_filename_without_extt   _t   component_filename(    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   _lookup_component_filename   s
    c         C   sÖ   y§ t  |  d t  } t j d |  t } t j |  \ t | | |  } | sp t d j | |     n  | d } | j |  t	 | |  Wd  QXWd  QXWd  QXWn( t
 k
 rÑ } t |  t |    n Xd  S(   Nt   compressiont   prefixs   didn't find {} component in {}i    (   R   R   R   t   TemporaryDirectoryt	   tmp_chdirR   t   RuntimeErrort   formatt   extractR	   R   R   t   str(   t   fnR   R   t   dest_dirR   t   tmpdirR   t   e(    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   _extract_component   s    	
#t   CondaFormat_v2c           B   sV   e  Z d  Z e d    Z e d d   Z e e j   d   Z	 e d    Z
 RS(   s   If there's another conda format or breaking changes, please create a new class and keep this
    one, so that handling of v2 stays working.c         K   sÂ   t  j | j d   p d } t j j |   j d d  } t j j |   sx t j j t j j	 t j
   |    }  n  t j j |  s t j |  n  x! | D] } t |  | | |  qĦ Wd  S(   Nt
   componentst   infot   pkgs   .condat    (   R&   R'   (   R   t   ensure_listt   gett   ost   patht   basenamet   replacet   isabst   normpathR   t   getcwdt   isdirt   makedirsR#   (   R   R    t   kwR%   R   t	   component(    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyR   2   s    *c         C   s   t  j |  | d d g S(   NR%   R&   (   R$   R   (   R   R    (    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   extract_info=   s    c         K   s¸  t  j j |  r9 t  j j |  } t  j j |  } n  t  j j | |  } | j d d  } t j | |   } t	 |  t	 |  } | j
 d  p t \ } }	 }
 t j d |  ú } t |  | | d | | |	 |
  } t |  | | d | | |	 |
  } i t d 6} t | d d	 t  } t d
 d d t  * } t j | |  | j | j d  Wd  QXx0 | | f D]" } | j | t  j j |   qrWt j | j  Wd  QXWd  QX| S(   Ns   .condaR(   t   compression_tupleR   s   info-s   pkg-t   conda_pkg_format_versiont   wR   t   modet   deletes   metadata.json(   R+   R,   R/   t   dirnameR-   R   R.   R   t   filter_info_filest   setR*   t   DEFAULT_COMPRESSION_TUPLER   R   t   CONDA_PACKAGE_FORMAT_VERSIONR   R   R    t   Falset   jsont   dumpt   writet   namet   rm_rf(   R   t	   file_listt   out_fnt
   out_folderR4   t   conda_pkg_fnt	   pkg_filest
   info_filest   extt   comp_filtert   filter_optsR!   t   info_tarballt   pkg_tarballt   pkg_metadataR   t   tfR'   (    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   createA   s,     c         C   s   t  j |   } | j } t |  d   } t j |  } Wd  QXt |  d   } t j |  } Wd  QXi | d 6| d 6| d 6S(   Nt   rbt   sizet   md5t   sha256(   R+   t   statt   st_sizet   openR   t   md5_checksumt   sha256_checksum(   t   in_filet   stat_resultRV   t   fRW   RX   (    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   get_pkg_details]   s    	N(   t   __name__t
   __module__t   __doc__t   staticmethodR   t   NoneR6   R+   R1   RT   Ra   (    (    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyR$   .   s   (   s   .tar.zstR
   s   zstd:compression-level=22(   Rd   RB   R+   t   tempfileR    t   zipfileR   R   R   t   ImportErrorR   R(   R   t
   exceptionsR   t	   interfaceR   t   tarballR   R	   R@   R?   R   R1   R#   R$   (    (    (    s?   lib/python2.7/site-packages/conda_package_handling/conda_fmt.pyt   <module>   s      	