
    d'                         d Z ddlZddlZddlmZ ddlmZ g dZi ZdZ	g dZ
d Zdd
Zd Zd Z G d d          ZddZeefdZd Zd Zedk    r e             dS dS )zUtilities for comparing files and directories.

Classes:
    dircmp

Functions:
    cmp(f1, f2, shallow=True) -> int
    cmpfiles(a, b, common) -> ([], [], [])
    clear_cache()

    N)filterfalse)GenericAlias)clear_cachecmpdircmpcmpfilesDEFAULT_IGNORESi    )RCSCVStagsz.gitz.hgz.bzr_darcs__pycache__c                  8    t                                            dS )zClear the filecmp cache.N)_cacheclear       /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/filecmp.pyr   r      s    
LLNNNNNr   Tc                    t          t          j        |                     }t          t          j        |                    }|d         t          j        k    s|d         t          j        k    rdS |r||k    rdS |d         |d         k    rdS t                              | |||f          }|Dt          | |          }t          t                    dk    rt                       |t          | |||f<   |S )aM  Compare two files.

    Arguments:

    f1 -- First file name

    f2 -- Second file name

    shallow -- treat files as identical if their stat signatures (type, size,
               mtime) are identical. Otherwise, files are considered different
               if their sizes or contents differ.  [default: True]

    Return value:

    True if the files are the same, False otherwise.

    This function uses a cache for past comparisons and the results,
    with cache entries invalidated if their stat information
    changes.  The cache may be cleared by calling clear_cache().

    r   FT   Nd   )	_sigosstatS_IFREGr   get_do_cmplenr   )f1f2shallows1s2outcomes         r   r   r      s    . 
bgbkk		B	bgbkk		B	!u1 5 5u 288t	!u1~~ujj"b"b)**G"b//v;;MMM!(r2r2~Nr   c                 N    t          j        | j                  | j        | j        fS N)r   S_IFMTst_modest_sizest_mtime)sts    r   r   r   F   s%    K
##JK r   c                 j   t           }t          | d          5 }t          |d          5 }	 |                    |          }|                    |          }||k    r	 d d d            d d d            dS |s	 d d d            d d d            dS e# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrbTF)BUFSIZEopenread)r   r    bufsizefp1fp2b1b2s          r   r   r   K   s   G	b$ 3R #	'""B'""BRxx                            	                         sF   B(3BB(4B7B(BB	B(B	B((B,/B,c                       e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Z ee	eeeeeeeeeee          Zd Z ee          ZdS )r   a  A class that manages the comparison of 2 directories.

    dircmp(a, b, ignore=None, hide=None)
      A and B are directories.
      IGNORE is a list of names to ignore,
        defaults to DEFAULT_IGNORES.
      HIDE is a list of names to hide,
        defaults to [os.curdir, os.pardir].

    High level usage:
      x = dircmp(dir1, dir2)
      x.report() -> prints a report on the differences between dir1 and dir2
       or
      x.report_partial_closure() -> prints report on differences between dir1
            and dir2, and reports on common immediate subdirectories.
      x.report_full_closure() -> like report_partial_closure,
            but fully recursive.

    Attributes:
     left_list, right_list: The files in dir1 and dir2,
        filtered by hide and ignore.
     common: a list of names in both dir1 and dir2.
     left_only, right_only: names only in dir1, dir2.
     common_dirs: subdirectories in both dir1 and dir2.
     common_files: files in both dir1 and dir2.
     common_funny: names in both dir1 and dir2 where the type differs between
        dir1 and dir2, or the name is not stat-able.
     same_files: list of identical files.
     diff_files: list of filenames which differ.
     funny_files: list of files which could not be compared.
     subdirs: a dictionary of dircmp instances (or MyDirCmp instances if this
       object is of type MyDirCmp, a subclass of dircmp), keyed by names
       in common_dirs.
     Nc                     || _         || _        |t          j        t          j        g| _        n|| _        |t          | _        d S || _        d S r&   )leftrightr   curdirpardirhider	   ignore)selfabr=   r<   s        r   __init__zdircmp.__init__|   sI    	
<BI.DIIDI>)DKKK DKKKr   c                 N   t          t          j        | j                  | j        | j        z             | _        t          t          j        | j                  | j        | j        z             | _        | j        	                                 | j        	                                 d S r&   )
_filterr   listdirr8   r<   r=   	left_listr9   
right_listsortr>   s    r   phase0zdircmp.phase0   s     DI!6!6!%4;!68 8!"*TZ"8"8"&)DK"79 9r   c           	      r   t          t          t          t          j        j        | j                  | j                            }t          t          t          t          j        j        | j                  | j                            }t          t          |j	        t          |j        |                              | _        t          t          |j	        t          |j        |                              | _        t          t          |j	        t          |j        |                              | _        d S r&   )dictzipmapr   pathnormcaserE   rF   list__getitem__filter__contains__commonr   	left_only
right_only)r>   r?   r@   s      r   phase1zdircmp.phase1   s    S)4>::DNKKLLS)4?;;T_MMNN3q}fQ^Q.G.GHHIIc!-Q^Q1O1OPPQQs1=+ana2P2PQQRRr   c                 V   g | _         g | _        g | _        | j        D ]}t          j                            | j        |          }t          j                            | j        |          }d}	 t	          j	        |          }n# t          $ r d}Y nw xY w	 t	          j	        |          }n# t          $ r d}Y nw xY w|rt          j        |j                  }t          j        |j                  }||k    r| j                            |           t          j        |          r| j                             |           $t          j        |          r| j                            |           T| j                            |           p| j                            |           d S )Nr   r   )common_dirscommon_filescommon_funnyrT   r   rN   joinr8   r9   r   OSErrorr'   r(   appendS_ISDIRS_ISREG)	r>   xa_pathb_pathoka_statb_stata_typeb_types	            r   phase2zdircmp.phase2   s    	, 	,AW\\$)Q//FW\\$*a00FB        ,V^44V^44V##%,,Q////\&)) 0$++A....\&)) 0%,,Q////%,,Q////!((++++9	, 	,s$   -BBBB**B98B9c                 p    t          | j        | j        | j                  }|\  | _        | _        | _        d S r&   )r   r8   r9   rZ   
same_files
diff_filesfunny_files)r>   xxs     r   phase3zdircmp.phase3   s3    diT->??=?:$*:*:*:r   c                    i | _         | j        D ]v}t          j                            | j        |          }t          j                            | j        |          }|                     ||| j        | j	                  | j         |<   wd S r&   )
subdirsrY   r   rN   r\   r8   r9   	__class__r=   r<   )r>   ra   a_xb_xs       r   phase4zdircmp.phase4   s|    
 ! 	P 	PA',,ty!,,C',,tz1--C#~~c3TYOODLOO	P 	Pr   c                     |                                   | j                                        D ]}|                                 d S r&   )ru   rq   valuesphase4_closurer>   sds     r   rx   zdircmp.phase4_closure   sK    ,%%'' 	  	 B	  	 r   c                 B   t          d| j        | j                   | j        r5| j                                         t          d| j        d| j                   | j        r5| j                                         t          d| j        d| j                   | j        r.| j                                         t          d| j                   | j        r.| j                                         t          d| j                   | j        r.| j                                         t          d| j                   | j	        r.| j	                                         t          d| j	                   | j
        r0| j
                                         t          d| j
                   d S d S )	NdiffzOnly in:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :)printr8   r9   rU   rG   rV   rk   rl   rm   rY   r[   rH   s    r   reportzdircmp.report   s   fdi,,,> 	=N!!!)TYT^<<<? 	?O  """)TZdo>>>? 	8O  """%t777? 	8O  """%t777 	C!!###/1ABBB 	?!!###+T-=>>> 	=""$$$($*;<<<<<	= 	=r   c                     |                                   | j                                        D ]$}t                       |                                  %d S r&   )r   rq   rw   r~   ry   s     r   report_partial_closurezdircmp.report_partial_closure   sN    ,%%'' 	 	BGGGIIKKKK	 	r   c                     |                                   | j                                        D ]$}t                       |                                 %d S r&   )r   rq   rw   r~   report_full_closurery   s     r   r   zdircmp.report_full_closure   sT    ,%%'' 	% 	%BGGG""$$$$	% 	%r   )rq   rk   rl   rm   rY   rZ   r[   rT   rU   rV   rE   rF   c                 ~    || j         vrt          |           | j         |         |            t          | |          S r&   )	methodmapAttributeErrorgetattr)r>   attrs     r   __getattr__zdircmp.__getattr__   sD    t~%% &&&tT"""tT"""r   )NN)__name__
__module____qualname____doc__rA   rI   rW   ri   ro   ru   rx   r   r   r   rK   r   r   classmethodr   __class_getitem__r   r   r   r   r   X   s       !	 !	F
! 
! 
! 
!  S S S!, !, !,F@ @ @	P 	P 	P     
= = =2  % % % V &6v#)V"f%&	: : :I# # # $L11r   r   c                     g g g f}|D ]l}t           j                            | |          }t           j                            ||          }|t          |||                                       |           m|S )a]  Compare common files in two directories.

    a, b -- directory names
    common -- list of file names found in both directories
    shallow -- if true, do comparison based solely on stat() information

    Returns a tuple of three lists:
      files that compare equal
      files that are different
      filenames that aren't regular files.

    )r   rN   r\   _cmpr^   )r?   r@   rT   r!   resra   axbxs           r   r   r     su     r2,C - -W\\!QW\\!QDR!!"))!,,,,Jr   c                 T    	  | || ||                     S # t           $ r Y dS w xY w)N   )r]   )r?   r@   shabsr   s        r   r   r     sH    3ss1a}}%%%%   qqs    
''c                 F    t          t          |j        |                     S r&   )rP   r   rS   )flistskips     r   rC   rC   &  s    D-u55666r   c                  H   dd l } dd l}|                    | j        dd          d          \  }}t          |          dk    r|                    dd           t          |d         |d                   }d|v r|                                 d S |                                 d S )Nr   r   rr   zneed exactly two args)z-r )sysgetoptargvr   GetoptErrorr   r   r   )r   r   optionsargsdds        r   demor   ,  s    JJJMMMMM#(122,44MGT
4yyA~~  !8$???	Qa	!	!BW
     
		r   __main__)T)r   r   r   	itertoolsr   typesr   __all__r   r.   r	   r   r   r   r   r   r   r   r   rC   r   r   r   r   r   <module>r      sT  
 
 
			  ! ! ! ! ! !      
I
I
I	
J J J  & & & &P  
	 	 	g2 g2 g2 g2 g2 g2 g2 g2T   6     7 7 7
 
 
 zDFFFFF r   