
§|j�  ã               @   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 Gd d „  d e
 ƒ Z e	 j e ƒ d S)	é    )Úabsolute_importN)Údisplay_pathÚrmtree)ÚvcsÚVersionControl)Úpath_to_url)Úconfigparserc               @   s”   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   sT   t  j d d ƒ } |  j | ƒ z# |  j d | g d d d | ƒWd t | ƒ Xd S)z?Export the Hg repository at the url to the destination locationz-exportzpip-ÚarchiveÚshow_stdoutFÚcwdN)ÚtempfileÚmkdtempÚunpackÚrun_commandr   )ÚselfÚlocationÚtemp_dir© r   ú0/tmp/pip-build-5c7ija6t/pip/pip/vcs/mercurial.pyÚexport   s    zMercurial.exportc             C   sÖ   t  j j | |  j d ƒ } t j ƒ  } yJ | j | ƒ | j d d | ƒ t | d ƒ � } | j	 | ƒ Wd  QRXWnA t
 t j f k
 r´ } z t j d | | ƒ WYd  d  } ~ Xn X|  j d d g | d | ƒd  S)	NÚhgrcÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sÚupdatez-qr   )Ú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-qr   r!   )r   )r   r/   r1   r   r   r   r!   /   s    zMercurial.updatec             C   s«   |  j  ƒ  \ } } | r. | g } d | } n g  } d } |  j | | | | ƒ r§ t 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   sL   |  j  d d g d d d | ƒj ƒ  } |  j | ƒ rB t | ƒ } | j ƒ  S)NÚ
showconfigzpaths.defaultr   Fr   )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 d | ƒj ƒ  } | S)NÚparentsz--template={rev}r   Fr   )r   r@   )r   r   Úcurrent_revisionr   r   r   Úget_revisionM   s    zMercurial.get_revisionc             C   s+   |  j  d d g d d d | ƒj ƒ  } | S)NrC   z--template={node}r   Fr   )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 } | sT 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