B
    UvgU                 @   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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)parse)path_to_url)display_pathmake_vcs_requirement_urlrmtree)TempDirectory)VersionControlvcsc                   s   e Zd ZdZdZdZdZd fdd	Zdd	 Zd
d Z	dd Z
dd Zdd Z fddZdd Zdd Zdd Zdd Z  ZS )Bazaarbzrz.bzrbranch)r   zbzr+httpz	bzr+httpszbzr+sshzbzr+sftpzbzr+ftpzbzr+lpNc                s6   t t| j|f|| ttdd r2tjdg d S )Nuses_fragmentlp)superr   __init__getattrurllib_parser   extend)selfurlargskwargs)	__class__ 9/tmp/pip-install-r_9ig3yj/pip/pip/_internal/vcs/bazaar.pyr      s    zBazaar.__init__c             C   s   d|gS )Nz-rr   )r   revr   r   r   get_base_rev_args"   s    zBazaar.get_base_rev_argsc          	   C   sP   t j|rt| tdd(}| |j | jd|g|jdd W dQ R X dS )zU
        Export the Bazaar repository at the url to the destination location
        export)kindF)cwdshow_stdoutN)ospathexistsr   r   unpackrun_command)r   locationtemp_dirr   r   r   r   %   s    zBazaar.exportc             C   sB   |  }td||t| ddg|  ||g }| | d S )NzChecking out %s%s to %sr   z-q)
to_displayloggerinfor   to_argsr&   )r   destr   rev_optionsrev_displaycmd_argsr   r   r   	fetch_new5   s    
zBazaar.fetch_newc             C   s   | j d|g|d d S )Nswitch)r    )r&   )r   r-   r   r.   r   r   r   r2   @   s    zBazaar.switchc             C   s"   ddg|   }| j||d d S )Npullz-q)r    )r,   r&   )r   r-   r   r.   r0   r   r   r   updateC   s    zBazaar.updatec                s2   t t| |\}}}|dr(d| }|||fS )Nzssh://zbzr+)r   r   get_url_rev_and_auth
startswith)r   r   r   	user_pass)r   r   r   r5   G   s    
zBazaar.get_url_rev_and_authc             C   sl   | j dgd|d}xT| D ]H}| }x:dD ]2}||r.||d }| |r\t|S |S q.W qW d S )Nr+   F)r!   r    )zcheckout of branch: zparent branch:    )r&   
splitlinesstripr6   split_is_local_repositoryr   )r   r'   urlslinexrepor   r   r   get_urlN   s    


zBazaar.get_urlc             C   s   | j dgd|d}| d S )NrevnoF)r!   r    )r&   r9   )r   r'   revisionr   r   r   get_revision[   s    zBazaar.get_revisionc             C   sR   |  |}|sd S | ds(d| }| |}| ddd }t|||S )Nzbzr:zbzr+-r8   r   )rA   lowerr6   rE   egg_namer;   r   )r   distr'   r@   current_revegg_project_namer   r   r   get_src_requirementa   s    

zBazaar.get_src_requirementc             C   s   dS )z&Always assume the versions don't matchFr   )r   r-   namer   r   r   is_commit_id_equalk   s    zBazaar.is_commit_id_equal)N)__name__
__module____qualname__rM   dirname	repo_nameschemesr   r   r   r1   r2   r4   r5   rA   rE   rL   rN   __classcell__r   r   )r   r   r      s   
r   )
__future__r   loggingr"   Zpip._vendor.six.moves.urllibr   r   pip._internal.downloadr   pip._internal.utils.miscr   r   r   pip._internal.utils.temp_dirr   pip._internal.vcsr	   r
   	getLoggerrO   r*   r   registerr   r   r   r   <module>   s   
^