a
    /§»a{9  ã                   @   s¢   d Z ddlZddl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	 ddlm
Z ddlmZmZ dZG dd	„ d	ejƒZG d
d„ dƒZdd„ ZG dd„ dƒZdS )zµ
module defining a subversion path object based on the external
command 'svn'. This modules aims to work with svn 1.3 and higher
but might also interact well with earlier versions.
é    N)ÚpathÚprocess)Úcommon)Úsvnwc)ÚBuildcostAccessCacheÚ
AgingCacheFc                   @   sô   e Zd ZdZedd�Zeddd�Zd>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d„Zdd „ Zd!d"„ Zd@d$d%„ZdAd'd(„ZdBd+d,„Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ ZdCd9d:„ZdDd<d=„ZdS )EÚSvnCommandPathzZ path implementation that offers access to (possibly remote) subversion
    repositories. é€   )Ú
maxentriesiè  g      N@)r
   Z
maxsecondsNc                 C   sP   t  | ¡}t|| ƒr&|j}|j}|j}t |¡ | d¡}||_||_||_|S )Nú/)	ÚobjectÚ__new__Ú
isinstanceÚrevÚauthÚstrpathÚ	svncommonZcheckbadcharsÚrstrip)Úclsr   r   r   Úself© r   úI/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/py/_path/svnurl.pyr      s    



zSvnCommandPath.__new__c                 C   s(   | j dkrd| j S d| j| j f S d S )Néÿÿÿÿz
svnurl(%r)zsvnurl(%r, %r))r   r   ©r   r   r   r   Ú__repr__$   s    

zSvnCommandPath.__repr__c                 G   sD   | j du r| j|g|¢R Ž S d| j gt|ƒ }| j|g|¢R Ž S dS )z9 execute an svn command, append our own url and revision Nú-r)r   Ú	_svnwriteÚlist)r   ÚcmdÚargsr   r   r   Ú_svnwithrev*   s    
zSvnCommandPath._svnwithrevc                    s`   d| g}‡ fdd„|D ƒ}|  |¡ | dˆ  ¡  ¡ d |¡}trRtd| ƒ ˆ  |¡}|S )z, execute an svn command, append our own url zsvn %sc                    s   g | ]}d ˆ   |¡ ‘qS )ú"%s")Ú_escape)Ú.0Úitemr   r   r   Ú
<listcomp>5   ó    z,SvnCommandPath._svnwrite.<locals>.<listcomp>r!   ú z
execing %s)ÚextendÚappendÚ_encodedurlÚjoinÚDEBUGÚprintÚ_svncmdexecauth)r   r   r   ÚlÚstringÚoutr   r   r   r   2   s    



zSvnCommandPath._svnwritec                 C   s2   t  ¡ | }| jdur(|d| j ¡  7 }|  |¡S )z  execute an svn command 'as is' Nr'   )r   Ú	fixlocaler   ÚmakecmdoptionsÚ_cmdexec©r   r   r   r   r   r.   ?   s    
zSvnCommandPath._svncmdexecauthc                 C   sf   zt  |¡}W nR tj jjy`   t ¡ d }|j d¡dksN|j d¡dkrZtj 	| ¡‚‚ Y n0 |S )Né   zFile Existsr   zFile already exists)
r   ÚcmdexecÚpyÚErrorÚsysÚexc_infoÚerrÚfindÚerrorÚEEXIST)r   r   r1   Úer   r   r   r4   F   s    ÿzSvnCommandPath._cmdexecc                 C   s2   t  ¡ | }| jdur(|d| j ¡  7 }|  |¡S )z9 execute an svn command, return a pipe for reading stdin Nr'   )r   r2   r   r3   Ú_popenr5   r   r   r   Ú_svnpopenauthQ   s    
zSvnCommandPath._svnpopenauthc                 C   s
   t  |¡S ©N)ÚosÚpopenr5   r   r   r   rA   X   s    zSvnCommandPath._popenc                 C   s   |   | j¡S rC   )r"   r   r   r   r   r   r*   [   s    zSvnCommandPath._encodedurlc                 C   s,   | j r| j  ¡ pd }| j t|ƒ|f¡ d S rC   )r   r3   Ú_lsnorevcacheZdelentryÚstr)r   r   r   r   r   r   Ú_norev_delentry^   s    zSvnCommandPath._norev_delentryÚrc                 C   sh   |dvrt d|f ƒ‚| jdd�s&J ‚| jdu rH|  d|  | j¡f ¡S |  d| j|  | j¡f ¡S dS )z, return an opened file with the given mode. )rI   ZrUzmode %r not supportedr6   )ÚfileNzsvn cat "%s"zsvn cat -r %s "%s")Ú
ValueErrorÚcheckr   rB   r"   r   )r   Úmoder   r   r   Úopenb   s    

ÿÿzSvnCommandPath.openc                 O   sb   | j  | j¡}t|ƒdk r*tj | d¡‚n4t|ƒdkrF| j|i |¤ŽS | jdd�j|i |¤ŽS dS )zi return the directory path of the current path joined
            with any given path arguments.
        é   zbase is not validÚ )ÚbasenameN)	r   ÚsplitÚsepÚlenr8   r>   ÚEINVALr+   Únew)r   r   Úkwargsr/   r   r   r   Údirpathn   s    zSvnCommandPath.dirpathc                 O   s6   |  dd¡}| j|Ž }| dd|¡ |  | ¡ ¡ |S )zz create & return the directory joined with args.
        pass a 'msg' keyword argument to set the commit message.
        Úmsgzmkdir by py lib invocationÚmkdirz-m)Úgetr+   r   rH   rX   )r   r   rW   Z
commit_msgZ
createpathr   r   r   rZ   {   s
    
zSvnCommandPath.mkdirúcopied by py lib invocationc                 C   sP   t |ddƒdurtj |d¡‚|  d||  | ¡|  |¡f ¡ |  | ¡ ¡ dS )z. copy path to target with checkin message msg.r   Núrevisions are immutablezsvn copy -m "%s" "%s" "%s"©Úgetattrr8   r>   rU   r.   r"   rH   rX   ©r   ÚtargetrY   r   r   r   Úcopy…   s    ÿzSvnCommandPath.copyúrenamed by py lib invocationc                 C   sZ   t | ddƒdurtj | d¡‚|  d||  | ¡|  |¡f ¡ |  |  ¡ ¡ |  | ¡ dS )z6 rename this path to target with checkin message msg. r   Nr]   z"svn move -m "%s" --force "%s" "%s"r^   r`   r   r   r   Úrename�   s    ÿzSvnCommandPath.renamer6   úremoved by py lib invocationc                 C   sB   | j durtj | d¡‚|  d||  | ¡f ¡ |  |  ¡ ¡ dS )zT remove a file or directory (or a directory tree if rec=1) with
checkin message msg.Nr]   zsvn rm -m "%s" "%s")r   r8   r>   rU   r.   r"   rH   rX   )r   ZrecrY   r   r   r   Úremove–   s    
zSvnCommandPath.removec                 C   sb   t j |¡}d|  | ¡f d|  |¡f g}| jdurHdt| jƒg| }|  dd |¡f ¡ |S )z‰ export to a local path

            topath should not exist prior to calling this, returns a
            py.path.local instance
        r!   Nr   zsvn export %sr'   )r8   r   Úlocalr"   r   rG   r.   r+   )r   Ztopathr   r   r   r   Úexportž   s    ÿ
zSvnCommandPath.exportc           
      O   s(  t | ddƒdurtj | d¡‚| j|Ž }| dd¡}|jdd�D ]}| ¡ r@ q`q@tj |d¡‚||kr”|j|d	�s�|r„tj 	|¡pŽtj 
|¡‚|S | |¡}| | jd
¡d }tjj ¡ }z\|j||d	� dd|  |¡ |  | |¡¡| |¡ ¡ f }	|  |	¡ |  |¡ W | ¡  n
| ¡  0 |S )z½ ensure that an args-joined path exists (by default as
            a file). If you specify a keyword argument 'dir=True'
            then the path is forced to be a directory path.
        r   Nr]   Údirr   T)Úreversezhas not any valid base!)ri   r6   zsvn import -m "%s" "%s" "%s"z	ensure %s)r_   r8   r>   rU   r+   r[   ÚpartsrL   ÚENOENTÚENOTDIRZEISDIRZreltorR   rS   r   rg   ÚmkdtempÚensurer"   r*   r.   rH   rf   )
r   r   rW   ra   ri   ÚxZtocreaterQ   Útempdirr   r   r   r   ro   ¬   s4    

ý
zSvnCommandPath.ensurec                 C   s   |   d|¡}|d d… S )NZpropgetr   )r    )r   ÚnameÚresr   r   r   Ú_propgetÎ   s    zSvnCommandPath._propgetc                 C   s6   |   d¡}| d¡}dd„ |dd … D ƒ}t | |¡S )NZproplistÚ
c                 S   s   g | ]}|  ¡ ‘qS r   )Ústrip©r#   rp   r   r   r   r%   Õ   r&   z,SvnCommandPath._proplist.<locals>.<listcomp>r6   )r    rR   r   ZPropListDict)r   rs   Úlinesr   r   r   Ú	_proplistÒ   s    

zSvnCommandPath._proplistc                 C   sD   |   ¡ }| ¡ }| j}|D ]\}}||kr|  S qtj | ¡‚dS )z9 return an Info structure with svn-provided information. N)rX   Ú_listdir_nameinforQ   r8   r>   rl   )r   ÚparentÚnameinfo_seqZbnrr   Úinfor   r   r   r}   Ø   s    
zSvnCommandPath.infoc                    sZ   ‡ fdd„}ˆ j rˆ j  ¡ pd}ˆ jdurBˆ j ˆ jˆ j|f|¡S ˆ j ˆ j|f|¡S dS )z8 return sequence of name-info directory entries of self c                     sf  zˆ   dd¡} W �n tjj�y   t ¡ d }|j d¡dkrTtj	 
ˆ |j¡‚n®|j d¡dkrvtj	 
ˆ |j¡‚nŒ|j d¡dkr˜tj	 
ˆ |j¡‚nj|j d¡dkrºtj	 
ˆ |j¡‚nH|j d	¡dkrÜtj	 
ˆ |j¡‚n&|j ¡  d
¡dk�rtj	 ˆ |j¡‚tj	 |j¡‚Y n0 |  d¡}g }|D ]0}|�r(t|ƒ}|jdk�r(| |j|f¡ �q(| ¡  |S )NZlsú-vr6   znon-existent in that revisionr   zE200009:zFile not foundznot part of a repositoryzUnable to openzmethod not allowedru   Ú.)r    r   r7   r9   r:   r;   r<   r=   r8   r>   rl   ÚlowerÚEACCESrR   ÚInfoSvnCommandÚ_namer)   Úsort)rs   r@   rx   r|   Zlsliner}   r   r   r   Úbuilderå   s4    
z1SvnCommandPath._listdir_nameinfo.<locals>.builderN)r   r3   r   Ú_lsrevcacheZ
getorbuildr   rF   )r   r…   r   r   r   r   rz   ã   s    
ÿÿz SvnCommandPath._listdir_nameinfoc                    sŒ   t ˆ tƒrt ˆ ¡‰ ˆ ¡ }t|ƒdkrT|d \}}|ˆjkrT|jdkrTtj	 
ˆ¡‚‡fdd„|D ƒ}ˆ r|‡ fdd„|D ƒ}ˆ ||¡ |S )zi list directory contents, possibly filter by the given fil func
            and possibly sorted.
        r6   r   rJ   c                    s   g | ]\}}ˆ   |¡‘qS r   )r+   )r#   rr   r}   r   r   r   r%     r&   z*SvnCommandPath.listdir.<locals>.<listcomp>c                    s   g | ]}ˆ |ƒr|‘qS r   r   rw   )Úfilr   r   r%     r&   )r   rG   r   Z	FNMatcherrz   rT   rQ   Úkindr8   r>   rm   Z	_sortlist)r   r‡   r„   r|   rr   r}   Úpathsr   )r‡   r   r   Úlistdir  s    

zSvnCommandPath.listdirFc                 C   s¾   |   ¡ sJ ‚|du rdp|}|du r(dp*|}|dkrB|dkrBd}nd||f }|rVdpXd}|  d||| jf ¡}dd	lm} | |¡}g }	td|jjƒD ] }
|
j	|
j
kr˜|	 t |
¡¡ q˜|	S )
zø return a list of LogEntry instances for this path.
rev_start is the starting revision (defaulting to the first one).
rev_end is the last revision (defaulting to HEAD).
if verbose is True, then the LogEntry instances also know which files changed.
NÚHEADr6   rP   z-r %s:%sr~   zsvn log --xml %s %s "%s"r   )Úminidom)rL   rB   r   Úxml.domrŒ   ÚparseÚfilterÚ
firstChildÚ
childNodesZnodeTypeZELEMENT_NODEr)   r   ZLogEntry)r   Z	rev_startZrev_endÚverboseZrev_optZverbose_optZxmlpiperŒ   ÚtreeÚresultZlogentryr   r   r   Úlog  s"    
ÿ
zSvnCommandPath.log)NN)rI   )r\   )rc   )r6   re   )NN)Nr6   F) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r†   r   rF   r   r   r    r   r.   r4   rB   rA   r*   rH   rN   rX   rZ   rb   rd   rf   rh   ro   rt   ry   r}   rz   rŠ   r•   r   r   r   r   r      s6   





	
"%
r   c                   @   s&   e Zd Ze d¡Zdd„ Zdd„ ZdS )r‚   zc^ *(?P<rev>\d+) +(?P<author>.+?) +(0? *(?P<size>\d+))? *(?P<date>\w+ +\d{2} +[\d:]+) +(?P<file>.*)$c                 C   sš   | j  |¡}| ¡ }|d | _| jd dkrD| jd d… | _d| _nd| _t|d ƒ| _|d | _|d rvt|d ƒpxd| _t	|d	 ƒ| _
| j
d
 | _d S )NrJ   r   r   ri   r   ÚauthorÚsizer   Údatei@B )Ú	lspatternÚmatchÚ	groupdictrƒ   rˆ   ÚintZcreated_revZlast_authorr›   Úparse_time_with_missing_yearÚmtimeÚtime)r   Úlinerž   Údatar   r   r   Ú__init__?  s    

zInfoSvnCommand.__init__c                 C   s   | j |j kS rC   )Ú__dict__)r   Úotherr   r   r   Ú__eq__Q  s    zInfoSvnCommand.__eq__N)r–   r—   r˜   ÚreÚcompiler�   r¦   r©   r   r   r   r   r‚   9  s
   ÿr‚   c                 C   sò   ddl }t ¡ }|  ¡ }t | d¡d¡d }t | d¡d¡d }| d¡}z*d|v r^tƒ ‚t |d¡d }d }}	W nX tyÐ   t |d	¡d
d… \}}	|d }|||||	ddddf	}
|
|krÌ|d8 }Y n0 |||||	ddddf	}
| |
¡S )zˆ analyze the time part from a single line of "svn ls -v"
    the svn output doesn't show the year makes the 'timestr'
    ambigous.
    r   Nz%br6   z%dé   ú:z%Yz%H:%Mé   é   )Úcalendarr£   ÚgmtimerR   ÚstrptimeÚpoprK   Útimegm)Ztimestrr°   Zt_nowZtpartsÚmonthÚdayÚlastÚyearÚhourÚminuteZt_resultr   r   r   r¡   Y  s&    
r¡   c                   @   s   e Zd Zdd„ ZdS )Ú	PathEntryc                 C   sX   |j j d¡| _| d¡ d¡| _| jdkrT| d¡ d¡| _| jrTt| d¡ƒ| _d S )NzUTF-8ÚactionÚAzcopyfrom-pathzcopyfrom-rev)	r�   Z	nodeValueÚencoder   ÚgetAttributer¼   Zcopyfrom_pathr    Zcopyfrom_rev)r   Zppartr   r   r   r¦   u  s    
zPathEntry.__init__N)r–   r—   r˜   r¦   r   r   r   r   r»   t  s   r»   )r™   rD   r:   r£   rª   r8   r   r   Zpy._pathr   r   r   Zpy._path.cacheutilr   r   r,   ZSvnPathBaser   r‚   r¡   r»   r   r   r   r   Ú<module>   s      + 