
    a{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y)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y)&SvnCommandPathzZ path implementation that offers access to (possibly remote) subversion
    repositories.    )
maxentriesi  g      N@)r   
maxsecondsNc                    t         j                  |       }t        ||       r$|j                  }|j                  }|j
                  }t        j                  |        |j                  d      }||_        ||_        ||_        |S )N/)	object__new__
isinstancerevauthstrpath	svncommoncheckbadcharsrstrip)clsr   r   r   selfs        1/usr/lib/python3/dist-packages/py/_path/svnurl.pyr   zSvnCommandPath.__new__   sm    ~~c"dC ((C99D<<D%t{{3	    c                 x    | 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__$   s6    88r>$,,..  (,||TXX>>r   c                     | j                    | j                  |g| S d| j                   gt        |      z   } | j                  |g| S )z9 execute an svn command, append our own url and revision -r)r   	_svnwritelist)r   cmdargss      r   _svnwithrevzSvnCommandPath._svnwithrev*   sO    88!4>>#---$((#d4j0D!4>>#---r   c                 0   d|z  g}|D cg c]  }d| j                  |      z   }}|j                  |       |j                  d| j                         z         dj	                  |      }t
        rt        d|z         | j                  |      }|S c c}w )z, execute an svn command, append our own url zsvn %sz"%s" z
execing %s)_escapeextendappend_encodedurljoinDEBUGprint_svncmdexecauth)r   r&   r'   litemstringouts          r   r$   zSvnCommandPath._svnwrite2   s    ^8<=d++==		$**,,-!,'(""6*
 >s   Bc                     t        j                         |z   }| j                   |d| j                  j                         z   z  }| j	                  |      S )z  execute an svn command 'as is' r*   )r   	fixlocaler   makecmdoptions_cmdexecr   r&   s     r   r2   zSvnCommandPath._svncmdexecauth?   sJ    !!#c)99 311333C}}S!!r   c                 n   	 t        j                  |      }|S # t        j                   j                  j                  $ rt t	        j
                         d   }|j                  j                  d      dk7  s|j                  j                  d      dk7  rt        j                  j                  |        w xY w)N   zFile Existsr   zFile already exists)
r   cmdexecpyErrorsysexc_infoerrfinderrorEEXIST)r   r&   r6   es       r   r:   zSvnCommandPath._cmdexecF   s    	//#&C 
 zz!!'' 	q!A

=)R/EEJJ'<=Chhood++	s
    BB4c                     t        j                         |z   }| j                   |d| j                  j                         z   z  }| j	                  |      S )z9 execute an svn command, return a pipe for reading stdin r*   )r   r8   r   r9   _popenr;   s     r   _svnpopenauthzSvnCommandPath._svnpopenauthQ   sJ    !!#c)99 311333C{{3r   c                 ,    t        j                  |      S N)ospopenr;   s     r   rI   zSvnCommandPath._popenX   s    xx}r   c                 8    | j                  | j                        S rL   )r+   r   r    s    r   r.   zSvnCommandPath._encodedurl[   s    ||DLL))r   c                     | j                   xr | j                   j                         xs d }| j                  j                  t	        |      |f       y rL   )r   r9   _lsnorevcachedelentrystr)r   r   r   s      r   _norev_delentryzSvnCommandPath._norev_delentry^   s?    yy7TYY557?4##SY$56r   c                 :   |dvrt        d|d      | j                  d      sJ | j                  .| j                  d| j	                  | j
                        d      S | j                  d| j                  d	| j	                  | j
                        d      S )
z, return an opened file with the given mode. )rrUzmode z not supportedr=   )filez	svn cat ""zsvn cat -r  ")
ValueErrorcheckr   rJ   r+   r   )r   modes     r   openzSvnCommandPath.openb   s    |#>??zzqz!!!88%%&*ll4<<&@'D E E %%&*hhT\\0J'L M Mr   c                 ,   | j                   j                  | j                        }t        |      dk  r t        j
                  j                  | d      t        |      dk(  r | j                  |i |S  | j                  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lenr?   rE   EINVALr/   new)r   r'   kwargsr3   s       r   dirpathzSvnCommandPath.dirpathn   s     LLtxx(q6A:((//$(;<<Vq[499d-f---488R8(--t>v>>r   c                     |j                  dd      } | j                  | }|j                  dd|       | j                  |j	                                |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$   rT   ri   )r   r'   rh   
commit_msg
createpaths        r   rl   zSvnCommandPath.mkdir{   sT     ZZ'CD
TYY%
WdJ7Z//12r   c           
         t        |dd       t        j                  j                  |d      | j	                  d|d| j                  |       d| j                  |      d       | j                  |j                                y)z. copy path to target with checkin message msg.r   Nrevisions are immutablezsvn copy -m "" "rY   getattrr?   rE   rf   r2   r+   rT   ri   r   targetrk   s      r   copyzSvnCommandPath.copy   sj    65$'3((//&*CDDC!\\$/f1EG 	HV^^-.r   c           
      0   t        | dd       t        j                  j                  | d      | j	                  d|d| j                  |       d| j                  |      d       | j                  | j                                | j                  |        y)z6 rename this path to target with checkin message msg. r   Nrq   zsvn move -m "z" --force "rr   rY   rs   ru   s      r   renamezSvnCommandPath.rename   sw    4%1((//$(ABB $,,t"4dll66JL 	MT\\^,T"r   c                     | j                    t        j                  j                  | d      | j	                  d|d| j                  |       d       | j                  | j                                y)zT remove a file or directory (or a directory tree if rec=1) with
checkin message msg.Nrq   zsvn rm -m "rr   rY   )r   r?   rE   rf   r2   r+   rT   ri   )r   recrk   s      r   removezSvnCommandPath.remove   sT     88((//$(ABBS$,,t:LMNT\\^,r   c                 *   t         j                  j                  |      }d| j                  |       dd| j                  |      dg}| j                  dt        | j                        g|z   }| j                  ddj                  |             |S )z export to a local path

            topath should not exist prior to calling this, returns a
            py.path.local instance
        rY   r#   zsvn export r*   )r?   r   localr+   r   rS   r2   r/   )r   topathr'   s      r   exportzSvnCommandPath.export   sz     v&,,t,.,,v.0288#dhh-(4/D@Ar   c                    t        | dd       t        j                  j                  | d       | j                  | }|j                  dd      }|j                  d      D ]  }|j                         s n! t        j                  j                  |d      ||k(  rX|j                  |	      sD|xr t        j                  j                  |      xs t        j                  j                  |      |S |j                  |      }|j                  | j                  d
      d   }t        j                  j                  j!                         }	 |j#                  ||	       dd| j%                  |      z  d| j%                  |j	                  |            d|j	                  |      j'                         d}	| j)                  |	       | j+                  |       |j-                          |S # |j-                          w xY w)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   Nrq   dirr   T)reversezhas not any valid base!)r   r=   zsvn import -m "z	ensure %srr   rY   )rt   r?   rE   rf   r/   rm   partsr\   ENOENTENOTDIREISDIRreltorc   rd   r   r~   mkdtempensurer+   r.   r2   rT   r|   )
r   r'   rh   rv   r   xtocreaterb   tempdirr&   s
             r   r   zSvnCommandPath.ensure   s   
 4%1((//$(ABBD!jj"d+ 	EAwwy	E ((//&*CDD;77s7#1bhh..q1GRXX__Q5GGH<<?>>$((A.q1''--'')		NN8N-$,,x"88LLh!78FF8$0024C   %  #NN NNs   BG. .H c                 0    | j                  d|      }|d d S )Npropgetr   )r(   )r   nameress      r   _propgetzSvnCommandPath._propget   s    y$/3Bxr   c                     | j                  d      }|j                  d      }|dd  D cg c]  }|j                          }}t        j                  | |      S c c}w )Nproplist
r=   )r(   rc   stripr   PropListDict)r   r   linesr   s       r   	_proplistzSvnCommandPath._proplist   sV    z*		$$)!"I.q..%%dE22 /s   Ac                     | j                         }|j                         }| j                  }|D ]  \  }}||k(  s|c S  t        j                  j                  |       )z9 return an Info structure with svn-provided information. )ri   _listdir_nameinforb   r?   rE   r   )r   parentnameinfo_seqbnr   infos         r   r   zSvnCommandPath.info   sX    //1]]& 	JD$rz	 hhood##r   c                 4     fd} j                   xr  j                   j                         xs d} j                  3 j                  j	                   j
                   j                  |f|      S  j                  j	                   j
                  |f|      S )z8 return sequence of name-info directory entries of self c                  8   	 j                  dd      } | j                  d      }g }|D ]=  }|st        |      }|j                  dk7  s!|j!                  |j                  |f       ? |j#                          |S # t        j                  j                  $ r t	        j
                         d   }|j                  j                  d      dk7  r*t        j                  j                  |j                        |j                  j                  d      dk7  r*t        j                  j                  |j                        |j                  j                  d      dk7  r*t        j                  j                  |j                        |j                  j                  d      dk7  r*t        j                  j                  |j                        |j                  j                  d	      dk7  r*t        j                  j                  |j                        |j                  j                         j                  d
      dk7  r*t        j                  j                  |j                        t        j                  j                  |j                        w xY w)Nls-vr=   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   r>   r@   rA   rB   rC   rD   r?   rE   r   lowerEACCESrc   InfoSvnCommand_namer-   sort)r   rG   r   r   lsliner   r   s         r   builderz1SvnCommandPath._listdir_nameinfo.<locals>.builder   s   ,&&tT2  IIdOEL @)&1DzzS($++TZZ,>?	@
 / ??(( ,LLN1%55::=>"D((//$66UUZZ
+r1((//$66UUZZ 01R7((//$66UUZZ :;R?((//$66UUZZ 0125((//$66UU[[]''(<=rA((//$66hhnnQUU++,s   A< <HJN)r   r9   r   _lsrevcache
getorbuildr   rQ   )r   r   r   s   `  r   r   z SvnCommandPath._listdir_nameinfo   s    	 6 yy7TYY557?488##..dhh/M/68 8 %%00$,,1E18: :r   c                    t        |t              rt        j                  |      }| j	                         }t        |      dk(  rE|d   \  }}|| j                  k(  r.|j                  dk(  rt        j                  j                  |       |D cg c]  \  }}| j                  |       }}}|r|D cg c]  } ||      s| }}| j                  ||       |S c c}}w c c}w )zi list directory contents, possibly filter by the given fil func
            and possibly sorted.
        r=   r   rX   )r   rS   r   	FNMatcherr   re   rb   kindr?   rE   r   r/   	_sortlist)r   filr   r   r   r   pathsr   s           r   listdirzSvnCommandPath.listdir  s     c3""3'C--/|!%aJD$t}}$f)<hh&&t,,5AB\dD4BB %01QQ0E0ud#	 C0s   C2C  C c           	         | j                         sJ |du xr dxs |}|du xr dxs |}|dk(  r|dk(  rd}nd|d|}|xr dxs d}| j                  d|d	|d
| j                  d      }ddlm} |j                  |      }g }	t        d|j                  j                        D ]@  }
|
j                  |
j                  k(  s|	j                  t        j                  |
             B |	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HEADr=   ra   z-r :r   zsvn log --xml r*   rZ   rY   r   )minidom)r\   rJ   r   xml.domr   parsefilter
firstChild
childNodesnodeTypeELEMENT_NODEr-   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<G$-w7G&$,"%%'.T\\'K L#}}W%tT__%?%?@ 	<H  H$9$99i00:;	< r   )NN)rV   )zcopied by py lib invocation)zrenamed by py lib invocation)r=   zremoved by py lib invocation)Nr=   F) __name__
__module____qualname____doc__r   r   r   rQ   r   r!   r(   r$   r2   r:   rJ   rI   r.   rT   r^   ri   rl   rw   ry   r|   r   r   r   r   r   r   r   r    r   r   r
   r
      s     '#6K$4@M?."	 *7
M
?/#-D3$#:J&r   r
   c                   <    e Zd Z ej                  d      Zd Zd Zy)r   zc^ *(?P<rev>\d+) +(?P<author>.+?) +(0? *(?P<size>\d+))? *(?P<date>\w+ +\d{2} +[\d:]+) +(?P<file>.*)$c                    | j                   j                  |      }|j                         }|d   | _        | j                  d   dk(  r| j                  d d | _        d| _        nd| _        t        |d         | _        |d   | _        |d   xr t        |d         xs d| _        t        |d	         | _
        | j                  d
z  | _        y )NrX   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 CRDJDIDItE{+>L6Sf%6;!	1$v,?
JJ(	r   c                 4    | j                   |j                   k(  S rL   )__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  s#     

	<=I)$/r   r   c           
      .   ddl }t        j                         }| j                         }t        j                  |j                  d      d      d   }t        j                  |j                  d      d      d   }|j                  d      }	 d|v r
t               t        j                  |d      d   }dx}}	|||||	ddddf	}
|j                  |
      S # t        $ r9 t        j                  |d	      d
d \  }}	|d   }|||||	ddddf	}
|
|kD  r|dz  }Y ]w xY w)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%br=   z%d   r   z%Yz%H:%M      )calendarr   gmtimerc   strptimepopr[   timegm)timestrr   t_nowtpartsmonthdaylastyearhourminutet_results              r   r   r   Y  s   
 KKME]]_FMM&**Q-.q1E
--

1t
,Q
/C::a=D$;,}}T4(+v eS$!Aa8H??8$$  }}T73Aa8fQx%dFAa!<eAIDs   +C ?DDc                       e Zd Zd Zy)	PathEntryc                 d   |j                   j                  j                  d      | _        |j	                  d      j                  d      | _        | j
                  dk(  rR|j	                  d      j                  d      | _        | j                  r t        |j	                  d            | _        y y y )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188A((299'B;;#!&!3!3O!D!K!KG!TD!!$'(:(:>(J$K! " r   N)r   r   r   r   r   r   r   r   r   t  s    Lr   r   )r   rM   rA   r   r   r?   r   r   py._pathr   r   r   py._path.cacheutilr   r   r0   SvnPathBaser
   r   r   r   r   r   r   <module>r     sW      	   ' ?bY** bR	/ /@%6L Lr   