B
    =)H[|  ã               @   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	 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)Ú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   ú\C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\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   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: %sÚupdatez-q)r   )Úosr   ÚjoinÚdirnamer   ÚSafeConfigParserÚreadÚsetÚopenÚwriteÚOSErrorÚNoSectionErrorÚloggerÚwarningÚto_argsr   )	r   ÚdestÚurlÚrev_optionsÚrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   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/   r4   r   r   r   r   2   s    zMercurial.updatec             C   sv   |   ¡ \}}|  |¡}|  |||¡rr| ¡ }t d||t|ƒ¡ |  ddd||g¡ ddg| ¡  }| j||d� d S )NzCloning hg %s%s to %sr   z
--noupdatez-qr   )r   )	Úget_url_revÚmake_rev_optionsÚcheck_destinationÚ
to_displayr*   Úinfor   r   r,   )r   r-   r.   r   r/   Úrev_displayr4   r   r   r   Úobtain7   s    

zMercurial.obtainc             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_urlF   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_revisionN   s    zMercurial.get_revisionc             C   s   | j ddgd|d� ¡ }|S )NrB   z--template={node}F)r   r   )r   r?   )r   r   Úcurrent_rev_hashr   r   r   Úget_revision_hashT   s    zMercurial.get_revision_hashc             C   sT   |   |¡}| ¡  d¡s d| }| ¡  dd¡d }|s<d S |  |¡}d|||f S )Nzhg:zhg+ú-é   r   z%s@%s#egg=%s)rA   ÚlowerÚ
startswithÚegg_nameÚsplitrF   )r   Údistr   ÚrepoÚegg_project_namerE   r   r   r   Úget_src_requirementZ   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_equald   s    zMercurial.is_commit_id_equalN)Ú__name__Ú
__module__Ú__qualname__rQ   r"   Ú	repo_nameÚschemesr   r   r5   r   r=   rA   rD   rF   rP   rR   r   r   r   r   r	      s   	
r	   )Ú
__future__r   Úloggingr    Úpip._vendor.six.movesr   Úpip._internal.downloadr   Úpip._internal.utils.miscr   Úpip._internal.utils.temp_dirr   Úpip._internal.vcsr   r   Ú	getLoggerrS   r*   r	   Úregisterr   r   r   r   Ú<module>   s   
Y