ó
Đ9Vc           @@  sÂ   d  d l  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 d  d l	 m
 Z
 m Z d  d l m Z d  d l m Z e j e  Z d e f d     YZ e
 j e  d S(	   i    (   t   absolute_importN(   t   display_patht   rmtree(   t   vcst   VersionControl(   t   path_to_url(   t   configparsert	   Mercurialc           B@  sz   e  Z d  Z d Z d Z d Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z RS(   t   hgs   .hgt   clones   hg+https   hg+httpss   hg+sshs   hg+static-httpc         C@  sT   t  j d d  } |  j |  z# |  j d | g d t d | Wd t |  Xd S(   s?   Export the Hg repository at the url to the destination locations   -exports   pip-t   archivet   show_stdoutt   cwdN(   t   tempfilet   mkdtempt   unpackt   run_commandt   FalseR   (   t   selft   locationt   temp_dir(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   export   s    c         C@  sÃ   t  j j | |  j d  } t j   } yI | j |  | j d d |  t | d   } | j	 |  Wd  QXWn/ t
 t j f k
 rĄ } t j d | |  n X|  j d d g | d | d  S(	   Nt   hgrct   pathst   defaultt   ws/   Could not switch Mercurial repository to %s: %st   updates   -qR   (   t   ost   patht   joint   dirnameR   t   SafeConfigParsert   readt   sett   opent   writet   OSErrort   NoSectionErrort   loggert   warningR   (   R   t   destt   urlt   rev_optionst   repo_configt   configt   config_filet   exc(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   switch!   s    c         C@  s:   |  j  d d g d | |  j  d d g | d | d  S(   Nt   pulls   -qR   R   (   R   (   R   R(   R*   (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyR   0   s    c         C@  sŪ   |  j    \ } } | r. | g } d | } n g  } d } |  j | | | |  rŠ t j d | | t |   |  j d d d | | g  |  j d d g | d | n  d  S(	   Ns    (to revision %s)t    s   Cloning hg %s%s to %sR	   s
   --noupdates   -qR   R   (   t   get_url_revt   check_destinationR&   t   infoR   R   (   R   R(   R)   t   revR*   t   rev_display(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   obtain4   s    	c         C@  sO   |  j  d d g d t d | j   } |  j |  rE t |  } n  | j   S(   Nt
   showconfigs   paths.defaultR   R   (   R   R   t   stript   _is_local_repositoryR   (   R   R   R)   (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_urlF   s    c         C@  sŽ   |  j  d g d t d | } g  } x{ | j   D]m } t j d |  } | r1 | j d  } | j d  } d | k r | j | j   | j   f  q q1 q1 Wt |  S(   Nt   tagsR   R   s   ([\w\d\.-]+)\s*([\d]+):.*$i   i   t   tip(	   R   R   t
   splitlinest   ret   searcht   groupt   appendR9   t   dict(   R   R   R<   t   tag_revst   linet
   tags_matcht   tagR5   (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_tag_revsN   s    )c         C@  sŽ   |  j  d g d t d | } g  } x{ | j   D]m } t j d |  } | r1 | j d  } | j d  } d | k r | j | j   | j   f  q q1 q1 Wt |  S(   Nt   branchesR   R   s   ([\w\d\.-]+)\s*([\d]+):.*$i   i   R   (	   R   R   R>   R?   R@   RA   RB   R9   RC   (   R   R   RI   t   branch_revsRE   t   branches_matcht   branchR5   (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_branch_revsZ   s    )c         C@  s+   |  j  d d g d t d | j   } | S(   Nt   parentss   --template={rev}R   R   (   R   R   R9   (   R   R   t   current_revision(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_revisiong   s    c         C@  s+   |  j  d d g d t d | j   } | S(   NRN   s   --template={node}R   R   (   R   R   R9   (   R   R   t   current_rev_hash(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_revision_hashm   s    c         C@  sô   |  j  |  } | j   j d  s1 d | } n  | j   j d d  d } | sW d  S|  j |  } |  j |  } |  j |  } |  j	 |  }	 | | k rķ d | | | f }
 n- | |	 k rŲ d | |	 | f }
 n
 d | }
 d | | |
 f S(	   Ns   hg:s   hg+t   -i   i    s   %s-%ss   %s-devs   %s@%s#egg=%s(
   R;   t   lowert
   startswitht   egg_namet   splitt   NoneRP   RR   RH   RM   (   R   t   distR   t	   find_tagst   repot   egg_project_namet   current_revRQ   RD   RJ   t   full_egg_name(    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   get_src_requirements   s$    
(   s   hgs   hg+https   hg+httpss   hg+sshs   hg+static-http(   t   __name__t
   __module__t   nameR   t	   repo_namet   schemesR   R/   R   R7   R;   RH   RM   RP   RR   R_   (    (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyR      s   	
								(   t
   __future__R    t   loggingR   R   R?   t	   pip.utilsR   R   t   pip.vcsR   R   t   pip.downloadR   t   pip._vendor.six.movesR   t	   getLoggerR`   R&   R   t   register(    (    (    s.   /tmp/pip-build-5Z5nTX/pip/pip/vcs/mercurial.pyt   <module>   s   z