B
    ãUvg�  ã               @   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 e¡ZG dd	„ d	eƒZe 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)r   zhg+httpzhg+httpszhg+sshzhg+static-httpc             C   s   |gS )N© )ÚselfÚrevr   r   ú</tmp/pip-install-r_9ig3yj/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|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   |  ¡ }t d||t|ƒ¡ |  ddd||g¡ ddg| ¡  }| 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d¡}t ¡ }y<| |¡ | dd|¡ t|dƒ�}| 	|¡ W d Q R X W n6 t
tjfk
rŒ } zt d||¡ W d d }~X Y n X ddg| ¡  }| 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 ||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� ¡ }|  |¡r*t|ƒ}| ¡ 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� ¡ }|S )NÚparentsz--template={rev}F)r   r   )r   r=   )r   r   Úcurrent_revisionr   r   r   Úget_revisionK   s    zMercurial.get_revisionc             C   s   | j ddgd|d� ¡ }|S )Nr@   z--template={node}F)r   r   )r   r=   )r   r   Úcurrent_rev_hashr   r   r   Úget_revision_hashQ   s    zMercurial.get_revision_hashc             C   sJ   |   |¡}| ¡  d¡s d| }|  |¡}| ¡  dd¡d }t|||ƒS )Nzhg:zhg+ú-é   r   )r?   ÚlowerÚ
startswithrD   Úegg_nameÚsplitr   )r   Údistr   ÚreporC   Ú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)Ú__name__Ú
__module__Ú__qualname__rO   r-   Ú	repo_nameÚschemesr   r   r&   r:   r   r?   rB   rD   rN   rP   r   r   r   r   r
      s   		r
   )Ú
__future__r   Úloggingr+   Zpip._vendor.six.movesr   Úpip._internal.downloadr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.temp_dirr   Úpip._internal.vcsr   r	   Ú	getLoggerrQ   r   r
   Úregisterr   r   r   r   Ú<module>   s   
U