3
[                 @   s   d dl mZ d dlZd dlZd dlm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 ejeZG dd	 d	eZeje dS )
    )absolute_importN)configparser)path_to_url)display_pathmake_vcs_requirement_url)TempDirectory)VersionControlvcsc               @   sl   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d ZdS )	Mercurialhgz.hgclonehg+httphg+httpshg+sshhg+static-httpc             C   s   |gS )N )selfrevr   r   </tmp/pip-install-65viz3iy/pip/pip/_internal/vcs/mercurial.pyget_base_rev_args   s    zMercurial.get_base_rev_argsc             C   s<   t dd(}| j|j | jd|gd|jd W dQ R X dS )z?Export the Hg repository at the url to the destination locationexport)kindarchiveF)show_stdoutcwdN)r   unpackpathrun_command)r   locationtemp_dirr   r   r   r      s    zMercurial.exportc             C   sR   |j  }tjd||t| | jddd||g ddg|j  }| j||d d S )NzCloning hg %s%s to %sr   z
--noupdatez-qupdate)r   )
to_displayloggerinfor   r   to_args)r   desturlrev_optionsrev_displaycmd_argsr   r   r   	fetch_new"   s    
zMercurial.fetch_newc       	      C   s   t jj|| jd}tj }y<|j| |jdd| t|d}|j	| W d Q R X W n6 t
tjfk
r } ztjd|| W Y d d }~X n X ddg|j  }| j||d d S )	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr    z-q)r   )osr   joindirnamer   SafeConfigParserreadsetopenwriteOSErrorNoSectionErrorr"   warningr$   r   )	r   r%   r&   r'   repo_configconfigconfig_fileexcr)   r   r   r   switch.   s    
zMercurial.switchc             C   s4   | j ddg|d ddg|j  }| j ||d d S )Npullz-q)r   r    )r   r$   )r   r%   r&   r'   r)   r   r   r   r    >   s    zMercurial.updatec             C   s2   | j ddgd|dj }| j|r*t|}|j S )N
showconfigzpaths.defaultF)r   r   )r   strip_is_local_repositoryr   )r   r   r&   r   r   r   get_urlC   s    
zMercurial.get_urlc             C   s   | j ddgd|dj }|S )Nparentsz--template={rev}F)r   r   )r   rA   )r   r   current_revisionr   r   r   get_revisionK   s    zMercurial.get_revisionc             C   s   | j ddgd|dj }|S )NrD   z--template={node}F)r   r   )r   rA   )r   r   current_rev_hashr   r   r   get_revision_hashQ   s    zMercurial.get_revision_hashc             C   sJ   | j |}|j jds d| }| j|}|j jddd }t|||S )Nzhg:zhg+-   r   )rC   lower
startswithrH   egg_namesplitr   )r   distr   reporG   egg_project_namer   r   r   get_src_requirementW   s    

zMercurial.get_src_requirementc             C   s   dS )z&Always assume the versions don't matchFr   )r   r%   namer   r   r   is_commit_id_equal`   s    zMercurial.is_commit_id_equalN)r   r   r   r   r   )__name__
__module____qualname__rS   r1   	repo_nameschemesr   r   r*   r>   r    rC   rF   rH   rR   rT   r   r   r   r   r
      s   		r
   )
__future__r   loggingr/   pip._vendor.six.movesr   pip._internal.downloadr   pip._internal.utils.miscr   r   pip._internal.utils.temp_dirr   pip._internal.vcsr   r	   	getLoggerrU   r"   r
   registerr   r   r   r   <module>   s   
U