U
    KQh                     @   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eZG dd de
Ze	e dS )	    )absolute_importN)display_pathrmtree)vcsVersionControl)path_to_url)configparserc                   @   sd   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)r
   zhg+httpzhg+httpszhg+sshzhg+static-httpc                 C   s>   t dd}| | z| jd|gd|d W 5 t| X dS )z?Export the Hg repository at the url to the destination locationz-exportzpip-archiveFshow_stdoutcwdN)tempfilemkdtempunpackr   run_command)selflocationtemp_dir r   0/tmp/pip-build-tlro1kwj/pip/pip/vcs/mercurial.pyexport   s    
  
zMercurial.exportc              
   C   s   t j|| jd}t }z<|| |dd| t|d}|	| W 5 Q R X W n6 t
tjfk
r } ztd|| W 5 d }~X Y nX | jddg| |d d S )	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %supdate-qr   )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pullr   r    r   )r   r   r.   r0   r   r   r   r   /   s    zMercurial.updatec                 C   sz   |   \}}|r |g}d| }ng }d}| ||||rvtd||t| | ddd||g | jddg| |d d S )	Nz (to revision %s) zCloning hg %s%s to %sr   z
--noupdater   r   r    )get_url_revcheck_destinationr,   infor   r   )r   r.   r/   revr0   rev_displayr   r   r   obtain3   s    
zMercurial.obtainc                 C   s2   | j ddgd|d }| |r*t|}| S )N
showconfigzpaths.defaultFr   )r   strip_is_local_repositoryr   )r   r   r/   r   r   r   get_urlE   s     

zMercurial.get_urlc                 C   s   | j ddgd|d }|S )Nparentsz--template={rev}Fr   r   r@   )r   r   current_revisionr   r   r   get_revisionM   s     
zMercurial.get_revisionc                 C   s   | j ddgd|d }|S )NrC   z--template={node}Fr   rD   )r   r   current_rev_hashr   r   r   get_revision_hashS   s     
zMercurial.get_revision_hashc                 C   sT   |  |}| ds d| }| ddd }|s<d S | |}d|||f S )Nzhg:zhg+-   r   z%s@%s#egg=%s)rB   lower
startswithegg_namesplitrH   )r   distr   repoegg_project_namerG   r   r   r   get_src_requirementY   s    

zMercurial.get_src_requirementc                 C   s   dS )z&Always assume the versions don't matchFr   r7   r   r   r   check_versionc   s    zMercurial.check_versionN)__name__
__module____qualname__namer$   	repo_nameschemesr   r5   r   r>   rB   rF   rH   rR   rS   r   r   r   r   r	      s   

r	   )
__future__r   loggingr!   r   	pip.utilsr   r   pip.vcsr   r   pip.downloadr   Zpip._vendor.six.movesr   	getLoggerrT   r,   r	   registerr   r   r   r   <module>   s   
W