ó
qw4Zc           @` s›  d  d l  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	 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 m Z d d l m Z m Z d d l m Z d d l m Z m Z d d	 l m Z e j e ƒ Z d
 e  f d „  ƒ  YZ! d „  Z" d „  Z# d „  Z$ d „  Z% d e& f d „  ƒ  YZ' e d k r—d  d l( m( Z( e' e j) ƒ Z* e( e* j+ ƒ  ƒ n  d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   isdirt   isfilet   joini   (   t   DEFAULTS_CHANNEL_NAME(   t   ensure_text_typet   open(   t   linked(   t   CondaFileIOErrort   CondaHistoryError(   t   Distt   CondaHistoryWarningc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   lib/python2.7/site-packages/conda/history.pyR      s   c         C` sE   |  j  d t j d ƒ ƒ |  j  d d j 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    (   t   writet   timet   strftimeR   t   syst   argv(   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` s\  i  } i  } xš |  D]’ } | d } t  | ƒ } | j \ } } } }	 |	 t k ra | d |	 7} n  | j d ƒ rƒ | | | 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q;Wd  S(   Ni   u    (%s)u   -u   +u    %s  {%s -> %s}u   -%s-%su   +%s-%s(   R   t   quadR   R   t   lowert   sett   sorted(   t   difft   addedt   removedR   t   fnt   distt   namet   versiont   _t   channelt   changed(    (    s,   lib/python2.7/site-packages/conda/history.pyt   pretty_diff#   s&    
c         C` s*   t  |  ƒ r t |  ƒ St t |  ƒ ƒ Sd  S(   N(   R   R,   t   iterR!   (   R   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   pretty_content9   s    
t   Historyc           B` s   e  Z d  „  Z d „  Z d „  Z e d „ Z d „  Z d d „ Z d „  Z	 d „  Z
 d	 „  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C` s4   | |  _  t | d ƒ |  _ t |  j d ƒ |  _ d  S(   Nu
   conda-metau   history(   t   prefixR   t   meta_dirt   path(   t   selfR0   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   __init__B   s    	c         C` s   |  j  d ƒ |  S(   Nu   enter(   t   update(   R3   (    (    s,   lib/python2.7/site-packages/conda/history.pyt	   __enter__G   s    c         C` s   |  j  d ƒ d  S(   Nu   exit(   R5   (   R3   t   exc_typet	   exc_valuet	   traceback(    (    s,   lib/python2.7/site-packages/conda/history.pyt   __exit__K   s    c         C` s4   | r t  |  j ƒ r d  S|  j t |  j ƒ ƒ d  S(   N(   R   R2   t   write_distsR
   R0   (   R3   t   force(    (    s,   lib/python2.7/site-packages/conda/history.pyt   init_log_fileN   s    c         C` s   t  j |  j ƒ j d k S(   Ni    (   t   ost   statR2   t   st_size(   R3   (    (    s,   lib/python2.7/site-packages/conda/history.pyt   file_is_emptyS   s    u    c         C` s(  yÖ |  j  ƒ  y t |  j ƒ  ƒ } Wn1 t k
 rV } t j d |  j | f t ƒ d SXt t t	 t
 |  j ƒ ƒ ƒ } | | k rÅ | d k rÁ |  j ƒ  rÁ t |  j d ƒ  } t | ƒ Wd QXn  d S|  j | | ƒ WnK t k
 r#} | j t j k r
t j d ƒ q$t |  j d | ƒ ‚ n Xd S(   uK   
        update the history file (creating a new one if necessary)
        u   Error in %s: %sNu   exitu   au   Can't write the history fileu   Can't write the history file %s(   R=   R    t	   get_stateR   t   warningst   warnR2   R   t   mapt   strR
   R0   RA   R	   R   t   write_changest   IOErrort   errnot   EACCESt   logt   debugR   (   R3   t   enter_or_exitt   lastt   et   currR   (    (    s,   lib/python2.7/site-packages/conda/history.pyR5   V   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 | d d j | ƒ 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   (   R   R2   t   ret   compileR	   t   readt
   splitlinest   stript   matcht   appendt   groupR    R   t   add(   R3   t   rest   sep_patt   ft   linest   linet   m(    (    s,   lib/python2.7/site-packages/conda/history.pyt   parsep   s"    %c         C` s,  g  } t  j d ƒ } t  j d ƒ } x|  j ƒ  D]ó \ } } } i | d 6} x¸ | D]° } | j | ƒ }	 |	 r± |	 j d ƒ j ƒ  }
 |
 d j d ƒ r¤ d |
 d <n  |
 | d <n  | j | ƒ }	 |	 rT |	 j ƒ  \ } } | | d <t j	 | j
 d	 d
 ƒ ƒ | d <qT qT Wd | k r1 | j | ƒ q1 q1 W| 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   #\s*cmd:\s*(.+)u   #\s*(\w+)\s*specs:\s*(.+)u   datei   i    u   condau   cmdu   actionu   'u   "u   specs(   RQ   RR   R`   RV   RX   t   splitt   endswitht   groupst   jsont   loadst   replaceRW   (   R3   RZ   t   com_patt   spec_patt   dtt   unused_contt   commentst   itemR^   R_   R   t   actiont   specs(    (    s,   lib/python2.7/site-packages/conda/history.pyt   get_user_requestsˆ   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(	   R    R`   R   R   t   discardRY   R   RW   t   copy(   R3   RZ   t   curRi   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)
        (   Ru   R    t   zip(   R3   t   revt   statest   timest   pkgs(    (    s,   lib/python2.7/site-packages/conda/history.pyRB   º   s
    
c         C` sp   xi t  |  j ƒ  ƒ D]U \ } \ } } } t d | | f ƒ x" t | ƒ D] } t d | ƒ qI Wt ƒ  q Wd  S(   Nu   %s  (rev %d)u       %s(   t	   enumerateR`   t   printR.   (   R3   t   it   dateR   Rt   R^   (    (    s,   lib/python2.7/site-packages/conda/history.pyt	   print_logÆ   s
    (c         C` sn  g  } xat  |  j ƒ  ƒ D]M\ } \ } } } i | d 6| d 6g  d 6g  d 6g  d 6g  d 6} i  } i  } t | ƒ r1xƒ | D]{ }	 t |	 d ƒ j \ }
 } } } |	 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{   R`   R   R   R   R   R   R    R!   R   RW   (   R3   t   resultR}   R~   R   Rt   t   eventR#   R$   t   pkgR'   R(   t   buildR*   R+   t   oldt   newt   details(    (    s,   lib/python2.7/site-packages/conda/history.pyt
   object_logÍ   sH    (
 

),c         C` s|   t  |  j ƒ s" t j |  j ƒ n  t |  j d ƒ B } | rr t | ƒ x( t | ƒ D] } | j d | ƒ qT Wn  Wd  QXd  S(   Nu   wu   %s
(	   R   R1   R>   t   makedirsR	   R2   R   R!   R   (   R3   t   distsR   R&   (    (    s,   lib/python2.7/site-packages/conda/history.pyR;   ý   s    
c         C` s   t  |  j d ƒ i } t | ƒ x) t | | ƒ D] } | j d | ƒ q0 Wx) t | | ƒ D] } | j d | ƒ q\ WWd  QXd  S(   Nu   au   -%s
u   +%s
(   R	   R2   R   R!   R   (   R3   t
   last_statet   current_stateR   R%   (    (    s,   lib/python2.7/site-packages/conda/history.pyRG     s    
(   R   R   R4   R6   R:   t   FalseR=   RA   R5   R`   Ro   Ru   RB   R   R‡   R;   RG   (    (    (    s,   lib/python2.7/site-packages/conda/history.pyR/   @   s   									0		u   __main__(   t   pprint(,   t
   __future__R    R   R   R   RI   Rd   t   loggingR>   t   os.pathR   R   R   RQ   R   R   RC   t   base.constantsR   t   common.compatR   R	   t   core.linked_dataR
   t
   exceptionsR   R   t   models.distR   t	   getLoggerR   RK   t   WarningR   R   R   R,   R.   t   objectR/   R   R0   t   hRo   (    (    (    s,   lib/python2.7/site-packages/conda/history.pyt   <module>   s2   "				Ï