� |��Wc@sDdZddlZddlmZddlmZyddlmZWn!ek riddlmZnXddlZddl Z dddd d d gZ de fd ��YZ defd ��YZ de fd��YZd efd��YZdded�Zed�Zddd�Zddd�Zd�Zd�ZdS(s Module to find differences over time in a filesystem Basically this takes a snapshot of a directory, then sees what changes were made. The contents of the files are not checked, so you can detect that the content was changed, but not what the old version of the file was. i����N(tfnmatch(tdatetime(tIterableUserDicttDifftSnapshottFiletDirtreport_expected_diffst show_diffcBs8eZdZd�Zd�Zd�Zeed�ZRS(s9 Represents the difference between two snapshots cCs ||_||_|j�dS(N(tbeforetaftert _calculate(tselfR R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt__init__s  cCs�|jj}|jj}i|_i|_|j�|_xm|j�D]_\}}||krq||j|<qFn|j|=|j||jkrF|||j|<qFqFWdS(N( R tdataR tdeletedtupdatedtcopytcreatedtitemstmtime(R R R tpathtf((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR $s       cCs |j�S(N(treport(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt__str__2sc Cs�g}|r;|jd|jj|jj|jjf�nxsd|jtfd|jtfd|jtfgD]>\}}}|ro|jd|�|j �}|j �d}x�|D]�\}} dt ||dd d t �} |}|r| j d kr| d | j 7} n|r�g} |jj|�rJ| j|j|j�n|jj|�rv| j|j|j�n| d djtt| ��7} n|j| �q�WqoqoWt|�dkr�|jd�ndj|�S(NsDifference in %s from %s to %s:RRRs-- %s: -------------------ts %stindentit include_sepsN/As (%s bytes)s (mtime: %s)s->is (no changes)s (tappendR t base_patht calculatedR RtTrueRRRtsortt _space_prefixtFalsetsizetgetRtjointmaptreprtlen( R theadertdateststnametfilest show_sizetlastRRtttparts((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR5s@   "   #( t__name__t __module__t__doc__R R RRR"R(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRs    cBszeZdZd d d ed�Zd�Zd�Zd�Zd�Zd�Z e j d d e d�Z d�Zd �ZRS( sx Represents a snapshot of a set of files. Has a dictionary-like interface, keyed relative to ``base_path`` cCsY||_||_||_||_d|_|p6i|_|dkrU|j�ndS(N(Rtignore_wildcardst ignore_hiddent ignore_pathstNoneRRt find_files(R RR-R5R7R6((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR ^s      cCs&|jd|j�tj�|_dS(s_ Find all the files under the base path, and put them in ``self.data`` RN(t_find_traverseRRtnowR(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR9mscCsf||jkrtS|jr;tjj|�jd�r;tSx$|jD]}t||�rEtSqEWt S(Nt.( R7RR6tosRtbasenamet startswithR5RR"(R tfntpat((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt _ignore_fileus$cCs?||jkrtS|jr;tjj|�jd�r;tStS(NR<(R7RR6R=RR>R?R"(R R@((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRBs $cCs�tjj|j|�}tjj|�r�|rIt|j|�||<nxjtj|�D]@}tjj||�}|j|�r�qYn|j||�qYWnt |j|�||<dS(N( R=RR%RtisdirRtlistdirRBR:R(R RtresulttfullR@((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR:�scCs#d|jj|j|jpdfS(Ns<%s in %r from %r>s(no calculation done)(t __class__R2RR(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt__repr__�sc CsAi}x4|D],}|}|jd�}||jkrb|rL||�} nd} | ||<q n||} |j|} | j} || | �s&|r�|| | �} npt| �t| �kr�dt| �t| �} n;t| �t| �krdt| �t| �} nd} | ||<q |r d||<q q W|S(s� Compares a dictionary of ``path: content`` to the found files. Comparison is done by equality, or the ``comparison(actual_content, expected_content)`` function given. Returns dictionary of differences, keyed by path. Each difference is either noted, or the output of ``differ(actual_content, expected_content)`` is given. If a file does not exist and ``not_found`` is given, then ``not_found(path)`` is put in. t/s not foundsdiffer (%i bytes smaller)sdiffer (%i bytes larger)sdiff (same size)ssame!(tstripRtbytesR(( R texpectedt comparisontdiffert not_foundtinclude_successRERt orig_pathtmsgtexpected_contenttfiletactual_content((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pytcompare_expected�s6      cCst||j��S(N(Rtclone(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt diff_to_now�sc Cs.|jd|jd|jd|jd|j�S(NRR5R7R6(RGRR5R7R6(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRW�s  N(((R2R3R4R8RR R9RBR:RHtoperatorteqR"RVRXRW(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRWs     , cBsSeZdZeZeZd�Zd�Ze e�Z d�Z d�Z d�Z RS(s Represents a single file found as the result of a command. Has attributes: ``path``: The path of the file, relative to the ``base_path`` ``full``: The full path ``stat``: The results of ``os.stat``. Also ``mtime`` and ``size`` contain the ``.st_mtime`` and ``st_size`` of the stat. ``bytes``: The contents of the file. You may use the ``in`` operator with these objects (tested against the contents of the file), and the ``.mustcontain()`` method. cCsj||_||_tjj||�|_tj|j�|_|jj|_|jj|_ d|_ dS(N( RRR=R%RFtstattst_mtimeRtst_sizeR#R8t_bytes(R RR((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR �s  cCsD|jdkr=t|jd�}|j�|_|j�n|jS(Ntrb(R^R8topenRFtreadtclose(R R((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt bytes__get�s  cCs ||jkS(N(RK(R R+((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt __contains__�scCsBt}|j}||kr>d|GH|GH||ks>t�ndS(NsCould not find %r in:(RRKtAssertionError(R R+t__tracebackhide__RK((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt mustcontain�s    cCsd|jj|j|jfS(Ns <%s %s:%s>(RGR2RR(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRHs (R2R3R4RRTR"tdirR RctpropertyRKRdRgRH(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR�s    cBsAeZdZeZeZd�Zd�Zd�Z e e �Z RS(s6 Represents a directory created by a command. cCs@||_||_tjj||�|_d|_d|_dS(NsN/A(RRR=R%RFR#R(R RR((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR s    cCsd|jj|j|jfS(Ns <%s %s:%s>(RGR2RR(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRHs cCstd|��dS(Ns!Directory %r doesn't have content(tNotImplementedError(R ((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRc!s( R2R3R4R"RTRRhR RHRcRiRK(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR s   cCs|dkrtjj}n|j|�}|j|�}g}x�|r�|r�|d|dkr�|dkr�|jdt|d�t|��n|jd|�|jd�|jd�qBW|r |r�dj|�||j|�Sdj|�|j|�Sn |j|�SdS(s� Anything shared by pref and full will be replaced with spaces in full, and full returned. Example:: >>> _space_prefix('/foo/bar', '/foo') ' /bar' it RN( R8R=RtseptsplitRR(tpopR%(tprefRFRlRRtpadding((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR!(s # ( c Cs�|s dS|j�}|j�g}d}xZ|D]R\}}t||dddt�}|rrt|d�}n|}t|j��dkrjttjd|�j d ��}t |d |�}|rY|d 7}x�|j�D]q}|j �j d �rt|d �}n6|j �j d�r5t|d�}nt|d�}||d 7}q�Wqx|d |7}n|d|7}|j |�q3W|j dt|��d j|�S(sh Takes the output of compare_expected, and returns a string description of the differences. sNo differencesRRiRi is^[ ]*iis t+i t-i iRksFiles with differences: %s(RR R!R"t color_lineR(t splitlinestretsearchtgroupRRJR?RR%( tdiffstcolorizeR+R/RtdescR0t cur_indenttline((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRFs8  ! cCs�|d kr|d krdSg}|d kr>|jd�nF|dkro|jd�|jdd|�n|jdd|�|d kr�|jd�n|jdd |�d d j|�S( s� 0 black 1 red 2 green 3 yellow 4 blue 5 magenta (purple) 6 cyan 7 white (gray) Add 8 to get high-intensity ss[39mis[1ms[%imiis[49mi(sN(R8RR%(t foregroundt backgroundtcodes((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt color_codeks     cCsAtjd|�}|jd�t||�||j�t�S(Ns^(\s*)i(RuRvRwR�tend(R|R}R~tmatch((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyRs�scCs.djg|j�D]}d||^q�S(Ns Rk(R%Rt(Rttexttl((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR�scCs�g|j�D]}|j�r |j�^q }g|j�D]}|j�r>|j�^q>}t|�t|�ko�dknr�d|d|dfS|s�d|Sddl}dj|j||��S(Nis %r not %risEmpty; should have: i����s (RtRJR(tdifflibR%tndiff(RURSR�t actual_linestexpected_linesR�((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyR�s( (R4R=RRtUserDictRt ImportErrortpaste.util.UserDict24RYRut__all__tobjectRRRRR8RR!R"RR�RsRR(((sC/opt/alt/python27/lib/python2.7/site-packages/paste/debug/fsdiff.pyt<module> s*     >y< %