î
[Y¼  ã               @   sÃ   d  d l  Z  d  d l Z d  d l Z d  d l 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 d  d l m Z d  d l m Z Gd d	 „  d	 e ƒ Z e j e ƒ d S)
é    N)Úcall_subprocess)Údisplay_pathÚrmtree)Úlogger)ÚvcsÚVersionControl)Úpath_to_url)ÚConfigParserc               @   s¸   e  Z d  Z d 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 d „  Z d  S)"Ú	MercurialÚhgz.hgÚcloneúhg+httpúhg+httpsúhg+sshúhg+static-httpzhg-clone.txtzg# This was a Mercurial repo; to make it a repo again run:
hg init
hg pull %(url)s
hg update -r %(rev)s
c             C   sÃ   d  } } x² | j  ƒ  D]¤ } | j ƒ  s | j ƒ  j d ƒ rE q n  t j d | ƒ } | ru | j d ƒ j ƒ  } n  t j d | ƒ } | r¥ | j d ƒ j ƒ  } n  | r | r | | f Sq Wd S)Nú#zhg\s*pull\s*(.*)\s*é   z^hg\s*update\s*-r\s*(.*)\s*)NN)Ú
splitlinesÚstripÚ
startswithÚreÚsearchÚgroup)ÚselfÚcontentÚurlÚrevÚlineÚ	url_matchÚ	rev_match© r    ú=/home/kubikplay/www/django_dtb/build/pip/pip/vcs/mercurial.pyÚparse_vcs_bundle_file   s    
"zMercurial.parse_vcs_bundle_filec             C   s`   t  j d d ƒ } |  j | ƒ z/ t |  j d | g d |  j d d d | ƒWd t | ƒ Xd S)	z?Export the Hg repository at the url to the destination locationz-exportzpip-ÚarchiveÚfilter_stdoutÚshow_stdoutFÚcwdN)ÚtempfileÚmkdtempÚunpackr   ÚcmdÚ_filterr   )r   ÚlocationÚtemp_dirr    r    r!   Úexport%   s    zMercurial.exportc             C   sÚ   t  j j | |  j d ƒ } t j ƒ  } yJ | j | ƒ | j d d | ƒ t | d ƒ } | j	 | ƒ | j
 ƒ  WnB t t j f k
 rµ t j ƒ  d } t j d | | f ƒ Yn! Xt |  j d d g | d	 | ƒd  S)
NÚhgrcÚpathsÚdefaultÚwr   z/Could not switch Mercurial repository to %s: %sÚupdatez-qr&   )ÚosÚpathÚjoinÚdirnamer	   ÚSafeConfigParserÚreadÚsetÚopenÚwriteÚcloseÚOSErrorÚNoSectionErrorÚsysÚexc_infor   Úwarnr   r*   )r   Údestr   Úrev_optionsÚrepo_configÚconfigÚconfig_fileÚer    r    r!   Úswitch0   s    zMercurial.switchc             C   s@   t  |  j d d g d | ƒt  |  j d d g | d | ƒd  S)NÚpullz-qr&   r3   )r   r*   )r   rC   rD   r    r    r!   r3   A   s    zMercurial.updatec             C   s¸   |  j  ƒ  \ } } | r. | g } d | } n g  } d } |  j | | | | ƒ r´ t j d | | t | ƒ f ƒ t |  j d d d | | g ƒ t |  j d d g | d | ƒn  d  S)	Nz (to revision %s)Ú zCloning hg %s%s to %sr   z
--noupdatez-qr3   r&   )Úget_url_revÚcheck_destinationr   Únotifyr   r   r*   )r   rC   r   r   rD   Úrev_displayr    r    r!   ÚobtainF   s    		zMercurial.obtainc             C   sR   t  |  j d d g d d d | ƒj ƒ  } |  j | ƒ rH t | ƒ } n  | j ƒ  S)NÚ
showconfigzpaths.defaultr%   Fr&   )r   r*   r   Ú_is_local_repositoryr   )r   r,   r   r    r    r!   Úget_urlT   s    zMercurial.get_urlc             C   s¯   t  |  j d g d d d | ƒ} g  } x{ | j ƒ  D]m } t j d | ƒ } | r4 | j d ƒ } | j d ƒ } d | k r¡ | j | j ƒ  | j ƒ  f ƒ q¡ q4 q4 Wt | ƒ S)	NÚtagsr%   Fr&   z([\w\d\.-]+)\s*([\d]+):.*$r   é   Útip)	r   r*   r   r   r   r   Úappendr   Údict)r   r,   rT   Útag_revsr   Ú
tags_matchÚtagr   r    r    r!   Úget_tag_revs\   s    )zMercurial.get_tag_revsc             C   s¯   t  |  j d g d d d | ƒ} g  } x{ | j ƒ  D]m } t j d | ƒ } | r4 | j d ƒ } | j d ƒ } d | k r¡ | j | j ƒ  | j ƒ  f ƒ q¡ q4 q4 Wt | ƒ S)	NÚbranchesr%   Fr&   z([\w\d\.-]+)\s*([\d]+):.*$r   rU   r1   )	r   r*   r   r   r   r   rW   r   rX   )r   r,   r]   Úbranch_revsr   Úbranches_matchÚbranchr   r    r    r!   Úget_branch_revsi   s    )zMercurial.get_branch_revsc             C   s.   t  |  j d d g d d d | ƒj ƒ  } | S)NÚparentsz--template={rev}r%   Fr&   )r   r*   r   )r   r,   Úcurrent_revisionr    r    r!   Úget_revisionv   s    zMercurial.get_revisionc             C   s.   t  |  j d d g d d d | ƒj ƒ  } | S)Nrb   z--template={node}r%   Fr&   )r   r*   r   )r   r,   Úcurrent_rev_hashr    r    r!   Úget_revision_hash|   s    zMercurial.get_revision_hashc             C   sô   |  j  | ƒ } | j ƒ  j d ƒ s1 d | } n  | j ƒ  j d d ƒ d } | sW d  S|  j | ƒ } |  j | ƒ } |  j | ƒ } |  j | ƒ }	 | | k r¶ d | | | f }
 n- | |	 k rÙ d | |	 | f }
 n
 d | }
 d | | |
 f S)	Nzhg:zhg+ú-r   r   z%s-%sz%s-devz%s@%s#egg=%s)	rS   Úlowerr   Úegg_nameÚsplitrd   rf   r\   ra   )r   Údistr,   Ú	find_tagsÚrepoÚegg_project_nameÚcurrent_revre   rY   r^   Úfull_egg_namer    r    r!   Úget_src_requirement‚   s     
zMercurial.get_src_requirementN)zhgr   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Únamer7   Ú	repo_nameÚschemesÚbundle_fileÚguider"   r.   rI   r3   rP   rS   r\   ra   rd   rf   rq   r    r    r    r!   r
      s"   r
   )r4   r'   r   r@   Úpip.utilr   r   r   Úpip.logr   Úpip.vcsr   r   Úpip.downloadr   Zpip.backwardcompatr	   r
   Úregisterr    r    r    r!   Ú<module>   s   Š