
}_                 @   s   d  d l  m 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 Gd d   d e
  Z e	 j e  d S)	    )absolute_importN)display_pathrmtree)vcsVersionControl)path_to_url)configparserc               @   s   e  Z d  Z d Z d Z d Z d Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d S)	Mercurialhgz.hgclonehg+httphg+httpshg+sshhg+static-httpc             C   sT   t  j d d  } |  j |  z# |  j d | g d d d | Wd t |  Xd S)z?Export the Hg repository at the url to the destination locationz-exportzpip-archiveshow_stdoutFcwdN)tempfilemkdtempunpackrun_commandr   )selflocationtemp_dir r   0/tmp/pip-build-3_sjtvrs/pip/pip/vcs/mercurial.pyexport   s    zMercurial.exportc             C   s   t  j j | |  j d  } t j   } yJ | j |  | j d d |  t | d   } | j	 |  Wd  QRXWnA t
 t j f k
 r } z t j d | |  WYd  d  } ~ Xn X|  j d d g | d | d  S)	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %supdatez-qr   )ospathjoindirnamer   SafeConfigParserreadsetopenwriteOSErrorNoSectionErrorloggerwarningr   )r   desturlrev_optionsrepo_configconfigconfig_fileexcr   r   r   switch    s     zMercurial.switchc             C   s:   |  j  d d g d | |  j  d d g | d | d  S)Npullz-qr   r!   )r   )r   r/   r1   r   r   r   r!   /   s    zMercurial.updatec             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 | d  S)	Nz (to revision %s) zCloning hg %s%s to %sr   z
--noupdatez-qr!   r   )get_url_revcheck_destinationr-   infor   r   )r   r/   r0   revr1   rev_displayr   r   r   obtain3   s    	zMercurial.obtainc             C   sL   |  j  d d g d d d | j   } |  j |  rB t |  } | j   S)N
showconfigzpaths.defaultr   Fr   )r   strip_is_local_repositoryr   )r   r   r0   r   r   r   get_urlE   s    zMercurial.get_urlc             C   s+   |  j  d d g d d d | j   } | S)Nparentsz--template={rev}r   Fr   )r   r@   )r   r   current_revisionr   r   r   get_revisionM   s    zMercurial.get_revisionc             C   s+   |  j  d d g d d d | j   } | S)NrC   z--template={node}r   Fr   )r   r@   )r   r   current_rev_hashr   r   r   get_revision_hashS   s    zMercurial.get_revision_hashc             C   st   |  j  |  } | j   j d  s. d | } | j   j d d  d } | sT d  S|  j |  } d | | | f S)Nzhg:zhg+-   r   z%s@%s#egg=%s)rB   lower
startswithegg_namesplitrG   )r   distr   repoegg_project_namerF   r   r   r   get_src_requirementY   s    
zMercurial.get_src_requirementc             C   s   d S)z&Always assume the versions don't matchFr   )r   r/   r1   r   r   r   check_versionc   s    zMercurial.check_versionN)r
   r   r   r   r   )__name__
__module____qualname__namer%   	repo_nameschemesr   r6   r!   r>   rB   rE   rG   rQ   rR   r   r   r   r   r	      s   

r	   )
__future__r   loggingr"   r   	pip.utilsr   r   pip.vcsr   r   pip.downloadr   Zpip._vendor.six.movesr   	getLoggerrS   r-   r	   registerr   r   r   r   <module>   s   W