ó
Ý²k^c           @` sƒ  d  d l  m Z m Z m Z m Z d  d l m Z d  d l Z d  d l m	 Z	 m
 Z
 m Z d  d l Z d  d l m Z d  d l Z d  d l m Z m Z m 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 m Z d d
 l m Z d d l m  Z  m! Z! d d l" m# Z# d d l$ m% Z% d d l& m' Z' m( Z( m) Z) m* Z* d d l+ m, Z, d d l- m. Z. d d l/ m0 Z0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 d d l6 m7 Z7 m8 Z8 d d l9 m: Z: e j; e< ƒ Z= d e> f d „  ƒ  YZ? d „  Z@ d „  ZA d „  ZB d „  ZC d eD f d „  ƒ  YZE e< d k rd  d lF mF ZF eE e jG ƒ ZH eF eH jI ƒ  ƒ eJ eH jK ƒ  ƒ n  d S(    i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   literal_evalN(   t   EACCESt   EPERMt   EROFS(   t
   itemgetter(   t   isdirt   isfilet   join(   t   dedenti   (   t   __version__(   t   dals(   t   groupbyt   take(   t   DEFAULTS_CHANNEL_NAME(   t   context(   t   ensure_text_typet	   iteritemst   opent	   text_type(   t   paths_equal(   t
   PrefixData(   t   CondaHistoryErrort   NotWritableError(   t   touch(   t   dist_str_to_quad(   t   VersionOrdert   version_relation_re(   t	   MatchSpect   CondaHistoryWarningc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   lib/python2.7/site-packages/conda/history.pyR    $   s   c         C` sq   |  j  d t j d ƒ ƒ |  j  d d j d „  t j Dƒ ƒ ƒ |  j  d d j t d t j d ƒ ƒ ƒ ƒ d  S(	   Nu   ==> %s <==
u   %Y-%m-%d %H:%M:%Su
   # cmd: %s
u    c         s` s   |  ] } t  | ƒ Vq d  S(   N(   R   (   t   .0t   s(    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>*   s    u   # conda version: %s
u   .i   (	   t   writet   timet   strftimeR   t   syst   argvR   t   CONDA_VERSIONt   split(   t   fo(    (    s,   lib/python2.7/site-packages/conda/history.pyt
   write_head(   s    'c         C` s   t  d „  |  Dƒ ƒ S(   Nc         s` s   |  ] } | j  d ƒ Vq d S(   u   -u   +N(   u   -u   +(   t
   startswith(   R#   R$   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>/   s    (   t   any(   t   content(    (    s,   lib/python2.7/site-packages/conda/history.pyt   is_diff.   s    c   
      c` sS  i  } i  } x‘ |  D]‰ } | d } t  | ƒ \ } } } } | t k rX | d | 7} n  | j d ƒ rz | | | j ƒ  <q | j d ƒ r | | | j ƒ  <q q Wt | ƒ t | ƒ @}	 x. t |	 ƒ D]  } d | | | | | f VqÃ Wx1 t t | ƒ |	 ƒ D] } d | | | f Vqþ Wx1 t t | ƒ |	 ƒ D] } d | | | f Vq2Wd  S(   Ni   u    (%s)u   -u   +u    %s  {%s -> %s}u   -%s-%su   +%s-%s(   R   R   R.   t   lowert   sett   sorted(
   t   difft   addedt   removedR$   t   fnt   namet   versiont   _t   channelt   changed(    (    s,   lib/python2.7/site-packages/conda/history.pyt   pretty_diff2   s$    
c         C` s*   t  |  ƒ r t |  ƒ St t |  ƒ ƒ Sd  S(   N(   R1   R>   t   iterR4   (   R0   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   pretty_contentG   s    
t   Historyc           B` sæ   e  Z e j d  ƒ Z e j d ƒ Z e j d ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z e d
 „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d d d d „ Z RS(   u   #\s*cmd:\s*(.+)u   #\s*(\w+)\s*specs:\s*(.+)?u   #\s*conda version:\s*(.+)c         C` s4   | |  _  t | d ƒ |  _ t |  j d ƒ |  _ d  S(   Nu
   conda-metau   history(   t   prefixR   t   meta_dirt   path(   t   selfRB   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   __init__T   s    	c         C` s   |  j  ƒ  |  S(   N(   t   init_log_file(   RE   (    (    s,   lib/python2.7/site-packages/conda/history.pyt	   __enter__Y   s    
c         C` s   |  j  ƒ  d  S(   N(   t   update(   RE   t   exc_typet	   exc_valuet	   traceback(    (    s,   lib/python2.7/site-packages/conda/history.pyt   __exit__]   s    c         C` s   t  |  j t ƒ d  S(   N(   R   RD   t   True(   RE   (    (    s,   lib/python2.7/site-packages/conda/history.pyRG   `   s    c         C` s   t  j |  j ƒ j d k S(   Ni    (   t   ost   statRD   t   st_size(   RE   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   file_is_emptyc   s    c         C` sÖ   y‰ y t  |  j ƒ  ƒ } Wn1 t k
 rL } t j d |  j | f t ƒ d SXt |  j ƒ } t  d „  | j	 ƒ  Dƒ ƒ } |  j
 | | ƒ WnF t k
 rÑ } | j t t t f k rË t |  j | j ƒ ‚ qÒ ‚  n Xd S(   uK   
        update the history file (creating a new one if necessary)
        u   Error in %s: %sNc         s` s   |  ] } | j  ƒ  Vq d  S(   N(   t   dist_str(   R#   t
   prefix_rec(    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>r   s    (   R3   t	   get_stateR   t   warningst   warnRD   R    R   RB   t   iter_recordst   write_changest   EnvironmentErrort   errnoR   R   R   R   (   RE   t   lastt   et   pdt   curr(    (    s,   lib/python2.7/site-packages/conda/history.pyRI   f   s    c         C` s
  g  } t  |  j ƒ s | St j d ƒ } t |  j ƒ  } | j ƒ  j ƒ  } Wd QXx± | D]© } | j ƒ  } | sw qY n  | j | ƒ } | r± | j	 | j
 d ƒ t ƒ  g  f ƒ qY | j d ƒ rØ | d d j	 | ƒ qY t | ƒ d k rY | d d j | ƒ qY qY W| S(   u„   
        parse the history file and return a list of
        tuples(datetime strings, set of distributions/diffs, comments)
        u   ==>\s*(.+?)\s*<==Ni   u   #iÿÿÿÿi   i    (   R
   RD   t   ret   compileR   t   readt
   splitlinest   stript   matcht   appendt   groupR3   R.   t   lent   add(   RE   t   rest   sep_patt   ft   linest   linet   m(    (    s,   lib/python2.7/site-packages/conda/history.pyt   parsez   s$    %c         C` sf   g  } xY |  j  d ƒ D]H } t j | ƒ rQ | rQ d j | d | g ƒ | d <q | j | ƒ q W| S(   uÖ   
        Parse specifications string that use conda<4.5 syntax.

        Examples
        --------
          - "param >=1.5.1,<2.0'"
          - "python>=3.5.1,jupyter >=1.0.0,<2.0,matplotlib >=1.5.1,<2.0"
        u   ,iÿÿÿÿ(   R+   R   Re   R   Rf   (   t   specs_stringt   specst   spec(    (    s,   lib/python2.7/site-packages/conda/history.pyt   _parse_old_format_specs_string’   s    
 c   	      C` sµ  i  } |  j  j | ƒ } | r` | j d ƒ j ƒ  } | d j d ƒ rS d | d <n  | | d <n  |  j j | ƒ } | rŽ | j d ƒ | d <n  |  j j | ƒ } | r±| j ƒ  \ } } | pÁ d } | | d <| j d ƒ rì t	 | ƒ } n d | k r
t
 j | ƒ } n  g  | D]" } | r| j d	 ƒ r| ^ q} | r`| d k r`| | d <| d <q±| r‡| d k r‡| | d <| d <q±| r±| d k r±| | d <| d <q±n  | S(   uH  
        Parse comment lines in the history file.

        These lines can be of command type or action type.

        Examples
        --------
          - "# cmd: /scratch/mc3/bin/conda install -c conda-forge param>=1.5.1,<2.0"
          - "# install specs: python>=3.5.1,jupyter >=1.0.0,<2.0,matplotlib >=1.5.1,<2.0"
        i   i    u   condau   cmdu   conda_versionu    u   actionu   [u   @u   updateu   installu   createu   update_specsu   specsu   removeu	   uninstallu   remove_specsu   neuteredu   neutered_specs(   u   updateu   installu   create(   u   removeu	   uninstall(   u   neutered(   t   com_patRe   Rg   R+   t   endswitht   conda_v_patt   spec_patt   groupsR.   R   RA   Rt   (	   t   clsRn   t   itemRo   R)   t   actionRq   Rr   Rs   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   _parse_comment_line¦   s6    
/c         C` sÒ  g  } x´ |  j  ƒ  D]¦ \ } } } i | d 6} x* | D]" } |  j | ƒ } | j | ƒ q6 Wd | k rx | j | ƒ n  t t d ƒ | ƒ } | j d d ƒ | d <| j d d ƒ | d <q Wt d „  | Dƒ ƒ }	 |	 rÎt j	 rÎt
 |	 d	 t ƒd
 }
 d j t d |
 j d ƒ ƒ ƒ } d j t d t j d ƒ ƒ ƒ } t | ƒ t | ƒ k  rÎt d ƒ i |  j d 6t d 6| d 6} t |  j t j ƒ s¸| t d ƒ i t j d 6| d 67} n  | t d ƒ 7} qÎn  | S(   u4  
        return a list of user requested items.  Each item is a dict with the
        following keys:
        'date': the date and time running the command
        'cmd': a list of argv of the actual command which was run
        'action': install/remove/update
        'specs': the specs being used
        u   dateu   cmdi    u   -u   unlink_distsu   +u
   link_distsc         s` s%   |  ] } d  | k r | d  Vq d S(   u   conda_versionN(    (   R#   t   x(    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>ë   s    t   keyiÿÿÿÿu   .i   u†  
                This environment has previously been operated on by a conda version that's newer
                than the conda currently being used. A newer version of conda is required.
                  target environment location: %(target_prefix)s
                  current conda version: %(conda_version)s
                  minimum conda version: %(minimum_version)s
                u   target_prefixu   conda_versionu   minimum_versionuŸ   
                    Update conda and try again.
                        $ conda install -p "%(base_prefix)s" "conda>=%(minimum_version)s"
                    u   base_prefixu­   
                To work around this restriction, one can also set the config parameter
                'allow_conda_downgrades' to False at their own risk.
                (    (    (   Rp   R}   RI   Rf   R   R   t   gett   tupleR   t   allow_conda_downgradesR4   R   R   R   R+   R*   R   RB   R   t   root_prefixR   (   RE   Rj   t   dtt   unused_contt   commentsR{   Rn   t   comment_itemst   distst   conda_versions_from_historyt   minimum_conda_versiont   minimum_major_minort   current_major_minort   message(    (    s,   lib/python2.7/site-packages/conda/history.pyt   get_user_requestsÔ   s<    	!!	
	
c         ` s  i  } xº |  j  ƒ  D]¬ } d „  | j d d ƒ Dƒ } x! | D] } | j | j d  ƒ q< Wd „  | j d d ƒ Dƒ } | j d „  | Dƒ ƒ d „  | j d d ƒ Dƒ } | j d „  | Dƒ ƒ q Wt d	 „  t |  j ƒ j	 ƒ  Dƒ ƒ ‰  t
 ‡  f d
 †  t | ƒ Dƒ ƒ S(   Nc         s` s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R#   Rs   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>  s    u   remove_specsc         s` s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R#   Rs   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>  s    u   update_specsc         s` s   |  ] } | j  | f Vq d  S(   N(   R9   (   R#   R$   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>  s    c         s` s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R#   Rs   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>  s    u   neutered_specsc         s` s   |  ] } | j  | f Vq d  S(   N(   R9   (   R#   R$   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>  s    c         s` s   |  ] } | j  Vq d  S(   N(   R9   (   R#   R;   (    (    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>!  s    c         3` s-   |  ]# \ } } | ˆ  k r | | f Vq d  S(   N(    (   R#   R9   Rs   (   t   prefix_recs(    s,   lib/python2.7/site-packages/conda/history.pys	   <genexpr>"  s    (    (    (    (   RŽ   R€   t   popR9   t   NoneRI   R3   R   RB   RX   t   dictR   (   RE   t   spec_mapt   requestt   remove_specsRs   t   update_specst   neutered_specs(    (   R   s,   lib/python2.7/site-packages/conda/history.pyt   get_requested_specs_map  s    %c         C` sË   g  } t  g  ƒ } x² |  j ƒ  D]¤ \ } } } t | ƒ sC | } ng xd | D]\ } | j d ƒ rs | j | d ƒ qJ | j d ƒ r– | j | d ƒ qJ t d | ƒ ‚ qJ W| j | | j ƒ  f ƒ q W| S(   uQ   
        return a list of tuples(datetime strings, set of distributions)
        u   -i   u   +u   Did not expect: %s(	   R3   Rp   R1   R.   t   discardRi   R   Rf   t   copy(   RE   Rj   t   curR„   t   contt
   unused_comR$   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   construct_states$  s    	iÿÿÿÿc         C` s6   |  j  ƒ  } | s t g  ƒ St | Œ  \ } } | | S(   ué   
        return the state, i.e. the set of distributions, for a given revision,
        defaults to latest (which is the same as the current state when
        the log file is up-to-date)

        Returns a list of dist_strs
        (   Rž   R3   t   zip(   RE   t   revt   statest   timest   pkgs(    (    s,   lib/python2.7/site-packages/conda/history.pyRU   8  s
    
c         C` ss   xl t  |  j ƒ  ƒ D]X \ } \ } } } t d | | f ƒ x" t | ƒ D] } t d | ƒ qI Wt d ƒ q Wd  S(   Nu   %s  (rev %d)u       %su    (   t	   enumerateRp   t   printR@   (   RE   t   it   dateR0   R   Rn   (    (    s,   lib/python2.7/site-packages/conda/history.pyt	   print_logF  s
    (c         C` sk  g  } x^t  |  j ƒ  ƒ D]J\ } \ } } } i | d 6| d 6g  d 6g  d 6g  d 6g  d 6} i  } i  } t | ƒ r.x€ | D]x }	 t |	 d ƒ \ }
 } } } |	 j d ƒ rÊ | | | f | |
 j ƒ  <q} |	 j d	 ƒ r} | | | f | |
 j ƒ  <q} q} Wt | ƒ t | ƒ @} x t | ƒ D] }
 | |
 } | |
 } i d	 j |
 f | ƒ d
 6d	 j |
 f | ƒ d 6} | | k rŠ| d j	 | ƒ q| d j	 | ƒ qWxC t t | ƒ | ƒ D]+ }
 | d j	 d	 j |
 f | |
 ƒ ƒ q¶Wxn t t | ƒ | ƒ D]+ }
 | d j	 d	 j |
 f | |
 ƒ ƒ qüWn( x% t | ƒ D] }	 | d j	 |	 ƒ q;W| j	 | ƒ q W| S(   Nu   dateu   revu   installu   removeu   upgradeu	   downgradei   u   +u   -u   oldu   new(
   R¤   Rp   R1   R   R.   R2   R3   R4   R   Rf   (   RE   t   resultR¦   R§   R0   R   t   eventR6   R7   t   pkgR9   R:   t   buildR<   R=   t   oldt   newt   details(    (    s,   lib/python2.7/site-packages/conda/history.pyt
   object_logM  sH    (
 

),c         C` s¯   t  |  j ƒ s" t j |  j ƒ n  t j |  j d d d d ƒi } t | ƒ x) t | | ƒ D] } | j	 d | ƒ q^ Wx) t | | ƒ D] } | j	 d | ƒ qŠ WWd  QXd  S(   Nt   modeu   abt   encodingu   utf-8u   -%s
u   +%s
(
   R	   RC   RO   t   makedirst   codecsR   RD   R-   R4   R%   (   RE   t
   last_statet   current_stateR,   R8   (    (    s,   lib/python2.7/site-packages/conda/history.pyRY   }  s    !
c         C` s   g  | D] } t  t | ƒ ƒ ^ q } g  | D] } t  t | ƒ ƒ ^ q, } g  | D] } t  t | ƒ ƒ ^ qQ } t | | | f ƒ rü t j |  j d d d d ƒU } | r¿ | j d | ƒ n  | rÙ | j d | ƒ n  | ró | j d | ƒ n  Wd  QXn  d  S(   NR±   u   abR²   u   utf-8u   # remove specs: %s
u   # update specs: %s
u   # neutered specs: %s
(   R   R   R/   R´   R   RD   R%   (   RE   R•   R–   R—   R$   t   fh(    (    s,   lib/python2.7/site-packages/conda/history.pyt   write_specs‡  s    %%%!(    (    (    (   R!   R"   R`   Ra   Ru   Rx   Rw   RF   RH   RM   RG   RR   RI   Rp   t   staticmethodRt   t   classmethodR}   RŽ   R˜   Rž   RU   R¨   R°   RY   R¸   (    (    (    s,   lib/python2.7/site-packages/conda/history.pyRA   N   s(   							.	=				0	
u   __main__(   t   pprint(L   t
   __future__R    R   R   R   t   astR   R´   R[   R   R   R   t   loggingt   operatorR   RO   t   os.pathR	   R
   R   R`   R(   t   textwrapR   R&   RV   t    R   R*   t   _vendor.auxlib.ishR   t   _vendor.toolzR   R   t   base.constantsR   t   base.contextR   t   common.compatR   R   R   R   t   common.pathR   t   core.prefix_dataR   t
   exceptionsR   R   t   gateways.disk.updateR   t   models.distR   t   models.versionR   R   t   models.match_specR   t	   getLoggerR!   t   logt   WarningR    R-   R1   R>   R@   t   objectRA   R»   RB   t   hRŽ   R¥   R˜   (    (    (    s,   lib/python2.7/site-packages/conda/history.pyt   <module>   sL   ""				ÿ H