3
e                 @   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G dd de
Ze	j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hg+httphg+httpshg+sshhg+static-httpc             C   s>   t jdd}| j| z| jd|gd|d W dt| X dS )z?Export the Hg repository at the url to the destination locationz-exportzpip-archiveF)show_stdoutcwdN)tempfilemkdtempunpackrun_commandr   )selflocationtemp_dir r   0/tmp/pip-build-argcdawy/pip/pip/vcs/mercurial.pyexport   s    
zMercurial.exportc             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 | jddg| |d d S )	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %supdatez-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pullz-q)r   r!   )r   )r   r/   r1   r   r   r   r!   /   s    zMercurial.updatec             C   sz   | j  \}}|r |g}d| }ng }d}| j||||rvt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   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   r0   r   r   r   get_urlE   s    
zMercurial.get_urlc             C   s   | j ddgd|dj }|S )Nparentsz--template={rev}F)r   r   )r   r@   )r   r   current_revisionr   r   r   get_revisionM   s    zMercurial.get_revisionc             C   s   | j ddgd|dj }|S )NrC   z--template={node}F)r   r   )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 }|s<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