3
ÀÞL]  ã               @   s|   d dl m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 ejeƒZG dd„ deƒZejeƒ dS )	é    )Úabsolute_importN)Úconfigparser)Údisplay_pathÚpath_to_url)ÚTempDirectory)ÚVersionControlÚvcsc               @   sx   e Zd ZdZdZdZdZedd	„ ƒZd
d„ Z	dd„ Z
dd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )Ú	MercurialÚhgz.hgÚcloneúhg+httpúhg+httpsúhg+sshúhg+static-httpc             C   s   | gS )N© )Úrevr   r   ú:/tmp/pip-build-69lrc5qx/pip/pip/_internal/vcs/mercurial.pyÚget_base_rev_args   s    zMercurial.get_base_rev_argsc             C   s@   t dd��,}| j|j|d� | 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)ÚurlÚarchiveF)Úshow_stdoutÚcwdN)r   ÚunpackÚpathÚrun_command)ÚselfÚlocationr   Ú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   )Z
to_displayÚloggerÚinfor   r   Úto_args)r   Údestr   Ú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   ÚRawConfigParserÚ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   )Úclsr   r   r   r   r   Úget_remote_urlC   s    
zMercurial.get_remote_urlc             C   s   | j ddgd|d�jƒ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}F)r   r   )r   r?   )rA   r   Úcurrent_revisionr   r   r   Úget_revisionL   s    zMercurial.get_revisionc             C   s   | j ddgd|d�jƒ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rC   z--template={node}F)r   r   )r   r?   )rA   r   Úcurrent_rev_hashr   r   r   Úget_requirement_revisionV   s    z"Mercurial.get_requirement_revisionc             C   s   dS )z&Always assume the versions don't matchFr   )rA   r$   Únamer   r   r   Úis_commit_id_equala   s    zMercurial.is_commit_id_equalN)r
   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__rH   r/   Ú	repo_nameÚschemesÚstaticmethodr   r   r(   r<   r    ÚclassmethodrB   rE   rG   rI   r   r   r   r   r	      s   		
r	   )Ú
__future__r   Úloggingr-   Zpip._vendor.six.movesr   Zpip._internal.utils.miscr   r   Zpip._internal.utils.temp_dirr   Z pip._internal.vcs.versioncontrolr   r   Ú	getLoggerrJ   r!   r	   Úregisterr   r   r   r   Ú<module>   s   
X