ó
'šMc           @   sÃ   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 d  d l m Z d e f d	 „  ƒ  YZ e j e ƒ d S(
   iÿÿÿÿN(   t   call_subprocess(   t   display_patht   rmtree(   t   logger(   t   vcst   VersionControl(   t   path_to_url2(   t   ConfigParsert	   Mercurialc           B   s   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 d „  Z d „  Z d „  Z RS(   t   hgs   .hgt   clones   hg+https   hg+httpss   hg+sshs   hg+static-https   hg-clone.txtsg   # This was a Mercurial repo; to make it a repo again run:
hg init
hg pull %(url)s
hg update -r %(rev)s
c         C   sÃ   d  } } x² | j ƒ  D]¤ } | j ƒ  s | j ƒ  j d ƒ rE q n  t j d | ƒ } | ru | j d ƒ j ƒ  } n  t j d | ƒ } | r¥ | j d ƒ j ƒ  } n  | r | r | | f Sq Wd S(   Nt   #s   hg\s*pull\s*(.*)\s*i   s   ^hg\s*update\s*-r\s*(.*)\s*(   NN(   t   Nonet
   splitlinest   stript
   startswitht   ret   searcht   group(   t   selft   contentt   urlt   revt   linet	   url_matcht	   rev_match(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   parse_vcs_bundle_file   s    
"c         C   s`   t  j d d ƒ } |  j | ƒ z/ t |  j d | g d |  j d t d | ƒWd t | ƒ Xd S(   s?   Export the Hg repository at the url to the destination locations   -exports   pip-t   archivet   filter_stdoutt   show_stdoutt   cwdN(   t   tempfilet   mkdtempt   unpackR    t   cmdt   _filtert   FalseR   (   R   t   locationt   temp_dir(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   export%   s    c         C   sÙ   t  j j | |  j d ƒ } t j ƒ  } yJ | j | ƒ | j d d | ƒ t | d ƒ } | j	 | ƒ | j
 ƒ  WnA t t j f k
 r´ t j ƒ  d } t j d | | f ƒ n! Xt |  j d d g | d	 | ƒd  S(
   Nt   hgrct   pathst   defaultt   wi   s/   Could not switch Mercurial repository to %s: %st   updates   -qR   (   t   ost   patht   joint   dirnameR   t   SafeConfigParsert   readt   sett   opent   writet   closet   OSErrort   NoSectionErrort   syst   exc_infoR   t   warnR    R"   (   R   t   destR   t   rev_optionst   repo_configt   configt   config_filet   e(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   switch0   s    c         C   s@   t  |  j d d g d | ƒt  |  j d d g | d | ƒd  S(   Nt   pulls   -qR   R,   (   R    R"   (   R   R<   R=   (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyR,   A   s    c         C   s¸   |  j  ƒ  \ } } | r. | g } d | } n g  } d } |  j | | | | ƒ r´ t j d | | t | ƒ f ƒ t |  j d d d | | g ƒ t |  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   notifyR   R    R"   (   R   R<   R   R   R=   t   rev_display(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   obtainF   s    		c         C   sR   t  |  j d d g d t d | ƒj ƒ  } |  j | ƒ rH t | ƒ } n  | j ƒ  S(   Nt
   showconfigs   paths.defaultR   R   (   R    R"   R$   R   t   _is_local_repositoryR   (   R   R%   R   (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_urlT   s    c         C   s¯   t  |  j d g d t d | ƒ} g  } x{ | j ƒ  D]m } t j d | ƒ } | r4 | j d ƒ } | j d ƒ } d | k r¡ | j | j ƒ  | j ƒ  f ƒ q¡ q4 q4 Wt	 | ƒ S(   Nt   tagsR   R   s   ([\w\d\.-]+)\s*([\d]+):.*$i   i   t   tip(
   R    R"   R$   R   R   R   R   t   appendR   t   dict(   R   R%   RM   t   tag_revsR   t
   tags_matcht   tagR   (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_tag_revs\   s    )c         C   s¯   t  |  j d g d t d | ƒ} g  } x{ | j ƒ  D]m } t j d | ƒ } | r4 | j d ƒ } | j d ƒ } d | k r¡ | j | j ƒ  | j ƒ  f ƒ q¡ q4 q4 Wt	 | ƒ S(   Nt   branchesR   R   s   ([\w\d\.-]+)\s*([\d]+):.*$i   i   R*   (
   R    R"   R$   R   R   R   R   RO   R   RP   (   R   R%   RU   t   branch_revsR   t   branches_matcht   branchR   (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_branch_revsi   s    )c         C   s.   t  |  j d d g d t d | ƒj ƒ  } | S(   Nt   parentss   --template={rev}R   R   (   R    R"   R$   R   (   R   R%   t   current_revision(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_revisionv   s    c         C   s.   t  |  j d d g d t d | ƒj ƒ  } | S(   NRZ   s   --template={node}R   R   (   R    R"   R$   R   (   R   R%   t   current_rev_hash(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_revision_hash|   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(
   RL   t   lowerR   t   egg_namet   splitR   R\   R^   RT   RY   (   R   t   distR%   t	   find_tagst   repot   egg_project_namet   current_revR]   RQ   RV   t   full_egg_name(    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   get_src_requirement‚   s     
(   R	   s   hg+https   hg+httpss   hg+sshs   hg+static-http(   t   __name__t
   __module__t   nameR0   t	   repo_namet   schemest   bundle_filet   guideR   R'   RB   R,   RI   RL   RT   RY   R\   R^   Ri   (    (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyR      s"   										(   R-   R   R   R9   t   pipR    t   pip.utilR   R   t   pip.logR   t   pip.vcsR   R   t   pip.downloadR   t   pip.backwardcompatR   R   t   register(    (    (    s5   /usr/lib/python2.7/dist-packages/pip/vcs/mercurial.pyt   <module>   s   Š