
    Dg{9                         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	ej                  Z G d
 d          Zd Z G 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                       e Zd ZdZ ed          Z edd          Zd&dZd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd Zd'dZd Zd Zd(dZd)dZd*dZd Zd Zd Zd  Zd! Zd" Zd&d#Zd+d%ZdS ),SvnCommandPathzZ path implementation that offers access to (possibly remote) subversion
    repositories.    )
maxentriesi  g      N@)r   
maxsecondsNc                     t                               |           }t          ||           r|j        }|j        }|j        }t          j        |            |j        d          }||_        ||_        ||_        |S )N/)	object__new__
isinstancerevauthstrpath	svncommoncheckbadcharsrstrip)clsr   r   r   selfs        D/var/www/sysmax/venv/lib/python3.11/site-packages/py/_path/svnurl.pyr   zSvnCommandPath.__new__   sv    ~~c""dC   	 (C9D<D%%%t{3	    c                 R    | j         dk    r
d| j        z  S d| j        d| j         dS )Nz
svnurl(%r)zsvnurl(z, ))r   r   r   s    r   __repr__zSvnCommandPath.__repr__$   s8    8r>>$,..  (,|||TXXX>>r   c                 z    | j          | j        |g|R  S d| j         gt          |          z   } | j        |g|R  S )z9 execute an svn command, append our own url and revision N-r)r   	_svnwritelist)r   cmdargss      r   _svnwithrevzSvnCommandPath._svnwithrev*   sU    8!4>#-----$(#d4jj0D!4>#-----r   c                 4    d|z  g} fd|D             }|                     |           |                    d                                 z             d                    |          }t          rt          d|z                                  |          }|S )z, execute an svn command, append our own url zsvn %sc                 @    g | ]}d                      |          z  S )"%s")_escape).0itemr   s     r   
<listcomp>z,SvnCommandPath._svnwrite.<locals>.<listcomp>5   s*    ===d+++===r   r+    z
execing %s)extendappend_encodedurljoinDEBUGprint_svncmdexecauth)r   r&   r'   lstringouts   `     r   r$   zSvnCommandPath._svnwrite2   s    ^=======		$**,,,---! 	),'(((""6**
r   c                     t          j                    |z   }| j        |d| j                                        z   z  }|                     |          S )z  execute an svn command 'as is' Nr0   )r   	fixlocaler   makecmdoptions_cmdexecr   r&   s     r   r7   zSvnCommandPath._svncmdexecauth?   sL    !##c)9 3113333C}}S!!!r   c                 V   	 t          j        |          }n# t          j         j        j        $ rv t	          j                    d         }|j                            d          dk    s|j                            d          dk    rt          j        	                    |            w xY w|S )N   zFile Existsr   zFile already exists)
r   cmdexecpyErrorsysexc_infoerrfinderrorEEXIST)r   r&   r:   es       r   r>   zSvnCommandPath._cmdexecF   s    	/#&&CCz!' 	 	 	q!A

=))R//EJJ'<==CChood+++	 
s
    BB&c                     t          j                    |z   }| j        |d| j                                        z   z  }|                     |          S )z9 execute an svn command, return a pipe for reading stdin Nr0   )r   r<   r   r=   _popenr?   s     r   _svnpopenauthzSvnCommandPath._svnpopenauthQ   sL    !##c)9 3113333C{{3r   c                 *    t          j        |          S N)ospopenr?   s     r   rM   zSvnCommandPath._popenX   s    x}}r   c                 6    |                      | j                  S rP   )r,   r   r    s    r   r3   zSvnCommandPath._encodedurl[   s    ||DL)))r   c                     | j         r| j                                         pd }| j                            t	          |          |f           d S rP   )r   r=   _lsnorevcachedelentrystr)r   r   r   s      r   _norev_delentryzSvnCommandPath._norev_delentry^   sI    y7TY5577?4##SYY$566666r   rc                 B   |dvrt          d|d          |                     d          sJ | j        1|                     d|                     | j                  d          S |                     d	| j        d
|                     | j                  d          S )z, return an opened file with the given mode. )rY   rUzmode z not supportedrA   )fileNz	svn cat ""zsvn cat -r  ")
ValueErrorcheckr   rN   r,   r   )r   modes     r   openzSvnCommandPath.openb   s    |##*>???zzqz!!!!!8%%%&*ll4<&@&@&@&@'D E E E %%%&*hhhT\0J0J0J0J'L M M Mr   c                 (   | j                             | j                  }t          |          dk     r t          j                            | d          t          |          dk    r | j        |i |S  |                     d          j        |i |S )zi return the directory path of the current path joined
            with any given path arguments.
           zbase is not valid )basename)	r   splitseplenrC   rI   EINVALr4   new)r   r'   kwargsr8   s       r   dirpathzSvnCommandPath.dirpathn   s     Ltx((q66A::(//$(;<<<VVq[[49d-f----488R8((-t>v>>>r   c                     |                     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)getr4   r$   rX   rm   )r   r'   rl   
commit_msg
createpaths        r   rp   zSvnCommandPath.mkdir{   sd     ZZ'CDD
TY%
WdJ777Z//11222r   copied by py lib invocationc           
      @   t          |dd           t          j                            |d          |                     d|d|                     |           d|                     |          d           |                     |                                           dS )z. copy path to target with checkin message msg.r   Nrevisions are immutablezsvn copy -m "" "r]   getattrrC   rI   rj   r7   r,   rX   rm   r   targetro   s      r   copyzSvnCommandPath.copy   s    65$''3(//&*CDDDCCC!\\$////f1E1E1E1EG 	H 	H 	HV^^--.....r   renamed by py lib invocationc           
      j   t          | dd           t          j                            | d          |                     d|d|                     |           d|                     |          d           |                     |                                            |                     |            dS )z6 rename this path to target with checkin message msg. r   Nrv   zsvn move -m "z" --force "rw   r]   rx   rz   s      r   renamezSvnCommandPath.rename   s    4%%1(//$(ABBB SS$,,t"4"4"4"4dll66J6J6J6JL 	M 	M 	MT\\^^,,,T"""""r   rA   removed by py lib invocationc                     | j          t          j                            | d          |                     d|d|                     |           d           |                     |                                            dS )zT remove a file or directory (or a directory tree if rec=1) with
checkin message msg.Nrv   zsvn rm -m "rw   r]   )r   rC   rI   rj   r7   r,   rX   rm   )r   recro   s      r   removezSvnCommandPath.remove   sw     8(//$(ABBBSSS$,,t:L:L:L:LMNNNT\\^^,,,,,r   c                 >   t           j                            |          }d|                     |           dd|                     |          dg}| j        dt          | j                  g|z   }|                     dd                    |                     |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 r0   )rC   r   localr,   r   rW   r7   r4   )r   topathr'   s      r   exportzSvnCommandPath.export   s     v&&,,t,,,,..,,v....028#dh--(4/D@AAAr   c                 n   t          | dd           t          j                            | d           | j        | }|                    dd          }|                    d          D ]}|                                r n!t          j                            |d          ||k    rX|                    |	          s@|rt          j        	                    |          pt          j        
                    |          |S |                    |          }|                    | j        d
          d         }t          j        j                                        }	 |                    ||	           dd|                     |          z  d|                     |                    |                    d|                    |                                          d}	|                     |	           |                     |           |                                 n# |                                 w xY w|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   Nrv   dirr   T)reversezhas not any valid base!)r   rA   zsvn import -m "z	ensure %srw   r]   )ry   rC   rI   rj   r4   rq   partsr`   ENOENTENOTDIREISDIRreltorg   rh   r   r   mkdtempensurer,   r3   r7   rX   r   )
r   r'   rl   r{   r   xtocreaterf   tempdirr&   s
             r   r   zSvnCommandPath.ensure   s
   
 4%%1(//$(ABBBD!jj""d++ 	E 	EAwwyy  (//&*CDDD;;77s7## H1bh..q11GRX__Q5G5GGH<<??>>$(A..q1'-''))		NN8N----$,,x"8"8888LLh!7!78888FF8$$0022224C   %%%  ###NNGNNs   B.H H2c                 B    |                      d|          }|d d         S )Npropgetr   )r(   )r   nameress      r   _propgetzSvnCommandPath._propget   s$    y$//3B3xr   c                     |                      d          }|                    d          }d |dd          D             }t          j        | |          S )Nproplist
c                 6    g | ]}|                                 S  )strip)r-   r   s     r   r/   z,SvnCommandPath._proplist.<locals>.<listcomp>   s     ...q...r   rA   )r(   rg   r   PropListDict)r   r   liness      r   	_proplistzSvnCommandPath._proplist   sR    z**		$..E!""I...%dE222r   c                     |                                  }|                                }| j        }|D ]\  }}||k    r|c S t          j                            |           )z9 return an Info structure with svn-provided information. )rm   _listdir_nameinforf   rC   rI   r   )r   parentnameinfo_seqbnr   infos         r   r   zSvnCommandPath.info   se    //11]& 	 	JD$rzz hood###r   c                       fd} j         r j                                         pd} j        ( j                             j         j        |f|          S  j                             j        |f|          S )z8 return sequence of name-info directory entries of self c                     	                      dd          } n# t          j        j        $ r t	          j                    d         }|j                            d          dk    r%t          j	        
                    |j                  |j                            d          dk    r%t          j	        
                    |j                  |j                            d          dk    r%t          j	        
                    |j                  |j                            d          dk    r%t          j	        
                    |j                  |j                            d	          dk    r%t          j	        
                    |j                  |j                                                            d
          dk    r%t          j	                            |j                  t          j	                            |j                  w xY w|                     d          }g }|D ]:}|r6t          |          }|j        dk    r|                    |j        |f           ;|                                 |S )Nls-vrA   znon-existent in that revisionr   zE200009:zFile not foundznot part of a repositoryzUnable to openzmethod not allowedr   .)r(   r   rB   rD   rE   rF   rG   rH   rC   rI   r   lowerEACCESrg   InfoSvnCommand_namer2   sort)r   rK   r   r   lsliner   r   s         r   builderz1SvnCommandPath._listdir_nameinfo.<locals>.builder   s   ,&&tT22?( , , ,LNN1%5::=>>"DD(//$666UZZ
++r11(//$666UZZ 011R77(//$666UZZ :;;R??(//$666UZZ 011255(//$666U[[]]''(<==rAA(//$666hnnQU+++, IIdOOEL @ @ @)&11DzS(($++TZ,>???s
    G7HN)r   r=   r   _lsrevcache
getorbuildr   rU   )r   r   r   s   `  r   r   z SvnCommandPath._listdir_nameinfo   s    	  	  	  	  	 6 y7TY5577?48#..dh/M/68 8 8 %00$,1E18: : :r   c                     t          t                    rt          j                                                   }t          |          dk    r@|d         \  }}| j        k    r*|j        dk    rt          j	        
                                fd|D             }rfd|D             }                     ||           |S )zi list directory contents, possibly filter by the given fil func
            and possibly sorted.
        rA   r   r\   c                 @    g | ]\  }}                     |          S r   )r4   )r-   r   r   r   s      r   r/   z*SvnCommandPath.listdir.<locals>.<listcomp>  s'    BBB\dD4BBBr   c                 *    g | ]} |          |S r   r   )r-   r   fils     r   r/   z*SvnCommandPath.listdir.<locals>.<listcomp>  s&    0001Q0Q000r   )r   rW   r   	FNMatcherr   ri   rf   kindrC   rI   r   	_sortlist)r   r   r   r   r   r   pathss   ``     r   listdirzSvnCommandPath.listdir  s     c3 	("3''C--//|!!%aJD$t}$$f)<)<h&&t,,,BBBB\BBB 	10000000Eud###r   Fc           	         |                                  sJ |du rdp|}|du rdp|}|dk    r	|dk    rd}nd|d|}|rdpd}|                     d|d	|d
| j        d          }ddlm} |                    |          }g }	t          d|j        j                  D ]9}
|
j	        |
j
        k    r'|	                    t          j        |
                     :|	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HEADrA   re   z-r :r   zsvn log --xml r0   r^   r]   r   )minidom)r`   rN   r   xml.domr   parsefilter
firstChild
childNodesnodeTypeELEMENT_NODEr2   r   LogEntry)r   	rev_startrev_endverboserev_optverbose_optxmlpiper   treeresultlogentrys              r   logzSvnCommandPath.log  s(    zz||%0&=I	T/,f77a<<GG$-IIww7G&$,"%%%'.wwT\\\'K L L######}}W%%tT_%?@@ 	< 	<H H$999i0::;;;r   )NN)rY   )rt   )r}   )rA   r   )NrA   F) __name__
__module____qualname____doc__r   r   r   rU   r   r!   r(   r$   r7   r>   rN   rM   r3   rX   rb   rm   rp   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r
      s         '&#666KJ$4@@@M   ? ? ?. . .  " " "	 	 	       * * *7 7 7
M 
M 
M 
M
? 
? 
?  / / / /# # # #- - - -    D  3 3 3$ $ $#: #: #:J   &     r   r
   c                   :    e Zd Z ej        d          Zd Zd ZdS )r   zc^ *(?P<rev>\d+) +(?P<author>.+?) +(0? *(?P<size>\d+))? *(?P<date>\w+ +\d{2} +[\d:]+) +(?P<file>.*)$c                    | j                             |          }|                                }|d         | _        | j        d         dk    r| j        d d         | _        d| _        nd| _        t          |d                   | _        |d         | _        |d         rt          |d                   pd| _        t          |d	                   | _
        | j
        d
z  | _        d S )Nr\   r   r   r   r   authorsizer   datei@B )	lspatternmatch	groupdictr   r   intcreated_revlast_authorr   parse_time_with_missing_yearmtimetime)r   liner   datas       r   __init__zInfoSvnCommand.__init__?  s     $$T**  &\
:b>S  CRCDJDIIDItE{++>L6Sf%6%6;!	1$v,??
J(			r   c                 "    | j         |j         k    S rP   )__dict__)r   others     r   __eq__zInfoSvnCommand.__eq__Q  s    }..r   N)r   r   r   recompiler   r   r   r   r   r   r   r   9  sL         
	<= =I) ) )$/ / / / /r   r   c           
      |   ddl }t          j                    }|                                 }t          j        |                    d          d          d         }t          j        |                    d          d          d         }|                    d          }	 d|v rt                      t          j        |d          d         }dx}}	nN# t          $ rA t          j        |d	          d
d         \  }}	|d         }|||||	ddddf	}
|
|k    r|dz  }Y nw xY w|||||	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%brA   z%d   r   z%Yz%H:%M      )calendarr   gmtimerg   strptimepopr_   timegm)timestrr   t_nowtpartsmonthdaylastyearhourminutet_results              r   r   r   Y  sJ   
 OOOKMME]]__FM&**Q--..q1E
-

1t
,
,Q
/C::a==D$;;,,}T4((+vv   }T733AaC8fQx%dFAa!<eAID eS$!Aa8H??8$$$s   1C ADDc                       e Zd Zd ZdS )	PathEntryc                 |   |j         j                            d          | _        |                    d                              d          | _        | j        dk    r]|                    d                              d          | _        | j        r+t          |                    d                    | _        d S d S d S )NzUTF-8actionAzcopyfrom-pathzcopyfrom-rev)	r   	nodeValueencoder   getAttributer  copyfrom_pathr   copyfrom_rev)r   pparts     r   r   zPathEntry.__init__u  s    '188AA((2299'BB;#!&!3!3O!D!D!K!KG!T!TD! L$'(:(:>(J(J$K$K!!! L Lr   N)r   r   r   r   r   r   r   r  r  t  s(        L L L L Lr   r  )r   rQ   rE   r   r   rC   r   r   py._pathr   r   r   py._path.cacheutilr   r   r5   SvnPathBaser
   r   r   r  r   r   r   <module>r     sM                    				               ' ' ' ' ' ' ? ? ? ? ? ? ? ?b b b b bY* b b bR	/ / / / / / / /@% % %6L L L L L L L L L Lr   