ó
heý[c           @   s_  d  d l  m Z m Z m Z m Z m Z d  d l 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 Z y d  d l m Z m Z Wn› e k
 rAy d  d l m Z m Z WqBe k
 r=y d  d l m Z m Z Wq>e k
 r9y d  d l m Z m Z Wq:e k
 r5q:Xq>XqBXn Xd e e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   NoRepot	   checktoolt   commandlinet   committ   converter_source(   t   _(   t   utilt   errorN(   t   ElementTreet	   XMLParsert   darcs_sourcec           B   sƒ   e  Z d d  „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         C   s  t  j |  | | d | ƒt j |  | d ƒ t j j t j j | d ƒ ƒ sf t t d ƒ | ƒ ‚ n  t	 d d d ƒ|  j
 d ƒ j ƒ  d j ƒ  } | d k  r½ t j t d	 ƒ | ƒ ‚ n  d
 t ƒ  k rò t j t d ƒ t d ƒ d ƒ ‚ n  t j j | ƒ |  _ d  |  _ i  |  _ i  |  _ i  |  _ |  j ƒ  } | re| d k r{t t d ƒ | ƒ ‚ q{n |  j j t d ƒ ƒ d  S(   Nt   revst   darcst   _darcss(   %s does not look like a darcs repositoryt   debnames	   --versioni    s   2.1s,   darcs version 2.1 or newer needed (found %r)R   s*   Python ElementTree module is not availables     (try installing the %s package)s   python-celementtrees	   darcs-1.0t   hasheds3   %s repository format is unsupported, please upgrades#   failed to detect repository format!(   s	   darcs-1.0R   (   R   t   __init__R   t   ost   patht   existst   joinR    R   R   t   run0t
   splitlinest   stripR   t   Abortt   globalst   realpatht   Nonet   lastrevt   changest   parentst   tagst   formatt   uit   warn(   t   selfR!   R   R   t   versionR    (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyR      s.    !				c   	      C   s:  t  j d d t j j |  j ƒ d ƒ |  _ |  j d d |  j ƒ\ } } |  j | ƒ |  j d d t	 d t	 d |  j ƒ} d  } d  } xŸ | j d	 ƒ D]Ž } | j d
 ƒ } | j d d ƒ } | j d ƒ rà | d j ƒ  } n" | d  k	 r| |  j | <d  } n  | |  j | <| g |  j | <| } q— Wg  |  j | <d  S(   Nt   prefixs   convert-t   -t   initt   repodirR   t
   xml_outputt   summaryt   patcht   hasht   namet    s   TAG i   (   t   tempfilet   mkdtempR   R   t   basenamet   tmppatht   runt	   checkexitt   xmlt   TrueR   t   findallt   gett   findtextt
   startswithR   R   R   R   (	   R#   t   outputt   statust   treet   tagnamet   childt   eltt   nodeR-   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   beforeA   s(    	#	
c         C   s1   |  j  j d |  j ƒ t j |  j d t ƒd  S(   Ns   cleaning up %s
t   ignore_errors(   R!   t   debugR2   t   shutilt   rmtreeR6   (   R#   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   afterX   s    c         C   s:   t  | t ƒ r! | j d ƒ } n  t t |  ƒ j | | ƒ S(   Ns   latin-1(   t
   isinstancet   unicodet   encodet   superR
   t   recode(   R#   t   st   encoding(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyRL   \   s    c         K   sd   t  ƒ  } t d d ƒ } |  j | |  } | j | j d | ƒ| j ƒ  |  j | j ƒ | j ƒ  S(   NRN   s   latin-1t   parser(	   R   R	   t   _runt   parset   stdoutt   waitR4   t
   returncodet   getroot(   R#   t   cmdt   kwargst   etreeRO   t   p(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyR5   d   s    	
c         C   s…   |  j  d d d t d |  j ƒ\ } } |  j | ƒ t j d | t j ƒ } | sV d  Sd j t	 d „  | j
 d ƒ j d ƒ Dƒ ƒ ƒ S(	   Nt   showt   repot   no_filesR(   s   ^\s*Format:\s*(.*)$t   ,c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   R   (   t   .0t   f(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pys	   <genexpr>y   s    i   (   R3   R6   R   R4   t   ret   searcht	   MULTILINER   R   t   sortedt   groupt   split(   R#   R;   R<   t   m(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyR    r   s    c         C   sx   g  } |  j  d d d t d |  j ƒ\ } } |  j | ƒ x7 | j d ƒ D]& } | d } | rJ | j | ƒ qJ qJ W| S(   NRZ   t   filest   no_directoriesR(   s   
i   (   R3   R6   R2   R4   Re   t   append(   R#   t   manR;   R<   t   lineR   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   manifest{   s    
c         C   s   |  j  d  S(   N(   R   R   (   R#   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   getheads†   s    c      
   C   sž   |  j  | } t j | j d ƒ d ƒ } | j d ƒ d | j d d ƒ } t d |  j | j d ƒ ƒ d t j | d	 ƒ d
 |  j | ƒ j ƒ  d |  j	 | ƒ S(   Nt
   local_dates   %a %b %d %H:%M:%S %Z %YR-   s   
t   commentR.   t   authort   dates   %Y-%m-%d %H:%M:%S %1%2t   descR   (
   R   R   t   strdateR8   R9   R   RL   t   datestrR   R   (   R#   t   revR@   Rq   Rr   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt	   getcommit‰   s    #c         C   s¯   |  j  d |  j d t d d | d t d t d d d	 |  j ƒ\ } } | r« | j d
 ƒ d k rt |  j | | ƒ n  |  j  d d t d	 |  j ƒ\ } } |  j | | ƒ n  d  S(   Nt   pullt   allt   matchs   hash %st   no_testt   no_posthookt   external_merges
   /bin/falseR(   s   We have conflicts iniÿÿÿÿt   revert(   R3   R   R6   R2   t   findR4   (   R#   Ru   R;   R<   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyRw   ”   s    
$c         C   s·  | r t  j t d ƒ ƒ ‚ n  i  } g  } d  } xX|  j | j d ƒ j ƒ  D]:} | j d	 k rh qM n  | j d k rk| d  k r’ |  j ƒ  } n  | j	 d ƒ | j	 d ƒ } } | | k rð | j
 | | f ƒ | j
 | | f ƒ | | | <q‡| d } xŠ | D]c }	 |	 j | ƒ sqn  | d |	 t | ƒ }
 | j
 |	 | f ƒ | j
 |
 | f ƒ |	 | |
 <qWqM | j
 | j j ƒ  | f ƒ qM W|  j | ƒ | |  _ t | ƒ | t ƒ  f S(
   Ns*   convert from darcs does not support --fullR*   t   add_directoryt   remove_directoryt   movet   fromt   tot   /(   R   R€   (   R   R   R   R   R   R~   t   getchildrent   tagRl   R8   Ri   R:   t   lent   textR   Rw   R   Rc   t   set(   R#   Ru   t   fullt   copiesR   Rj   R@   t   sourcet   destR_   t   fdest(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt
   getchanges    s8    #
 	c         C   s³   | |  j  k r' t j t d ƒ ƒ ‚ n  t j j |  j | ƒ } y% t j	 | ƒ } t j
 | ƒ j } Wn, t k
 r’ } | j t j k rŒ d S‚  n X| d @r£ d p¦ d } | | f S(   Ns   internal calling inconsistencyiI   t   xR.   (   NN(   R   R   R   R   R   R   R   R2   R   t   readfilet   lstatt   st_modet   IOErrort   errnot   ENOENTR   (   R#   R-   Ru   R   t   datat   modet   inst(    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   getfileÂ   s    c         C   s   |  j  S(   N(   R   (   R#   (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   gettagsÐ   s    N(   t   __name__t
   __module__R   R   RB   RG   RL   R5   R    Rl   Rm   Rv   Rw   R   Rš   R›   (    (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyR
      s   #										"	(   t   commonR    R   R   R   R   t   mercurial.i18nR   t	   mercurialR   R   R   RE   R/   R`   R•   t   xml.etree.cElementTreeR   R	   t   ImportErrort   xml.etree.ElementTreet   elementtree.cElementTreet   elementtree.ElementTreeR
   (    (    (    s7   /usr/lib/python2.7/dist-packages/hgext/convert/darcs.pyt   <module>   s"   (<