3
zYði�  ã               @   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-ue6tjl93/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