Vc'csdZddlZddlZddlmZddlmZgdZiZdZ gdZ dZ dd Z d Z d ZGd dZddZee fdZdZdZedkr edSdS)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_cachecmpdircmpcmpfilesDEFAULT_IGNORESi )ZRCSZCVSZtagsz.gitz.hgz.bzrZ_darcsZ __pycache__cs8tdS)zClear the filecmp cache.N)_cacheZclear /usr/lib64/python3.11/filecmp.pyrrs LLNNNNNr Tcsttj|}ttj|}|dtjks|dtjkrdS|r||krdS|d|dkrdSt||||f}|Dt ||}ttdkrt|t||||f<|S)aMCompare 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(). rFTNid) _sigosstatZS_IFREGrZget_do_cmplenr)f1f2shallowZs1Zs2Zoutcomes r rrs. bgbkk  B bgbkk  B !u 1 5u28t !u1~ujj"b"b)**G)"b// v;;   MMM!(r2r2~ Nr csNtj|j|j|jfSN)rS_IFMTst_modeZst_sizeZst_mtime)Zst r r r Fs% K # # J K r csjt}t|d5}t|d5} ||}||}||kr dddddddS|s dddddddSe#1swxYwYddddS#1swxYwYdS)NZrbTF)BUFSIZEZopenZread)rrZbufsizeZfp1Zfp2Zb1Zb2s r rrKsG b$3R# '""B'""BRx     sFB(3B B(4B7 B(BB B(B B((B,/B,cseZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z ee eeeeeeeeeee ZdZeeZdS)raA 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. Ncs||_||_|tjtjg|_n||_|t |_dS||_dSr)leftrightrZcurdirZpardirhiderignore)selfabrr r __init__zdircmp.__init__|sO   BI.DIIDI  !)DKKK DKKKr csNttj|j|j|jz|_ttj|j|j|jz|_|j |j dSr) _filterrZlistdirrrr left_listr right_listsortrrr phase0z dircmp.phase0s DI!6!6!%4;!688!"*TZ"8"8"&)DK"799  r c srttttjj|j|j}ttttjj|j|j}tt|j t|j ||_ tt|j t|j ||_tt|j t|j ||_dSr)dictZzipZmaprpathZnormcaser$r%listZ __getitem__Zfilter __contains__commonr left_only right_only)rrr s r phase1z dircmp.phase1s S)4>::DNKK L L S)4?;;T_MM N N3q}fQ^Q.G.GHHII c!-Q^Q1O1OPPQQs1=+ana2P2PQQRRr csVg|_g|_g|_|jD]}tj|j|}tj|j|}d} t j |}n#t$rd}YnwxYw t j |}n#t$rd}YnwxYw|rtj |j }tj |j }||kr|j |tj|r|j |$tj|r|j |T|j |p|j |dS)Nr r) common_dirs common_files common_funnyr-rr*joinrrrOSErrorrrappendZS_ISDIRZS_ISREG) rxZa_pathZb_pathZokZa_statZb_statZa_typeZb_types r phase2z dircmp.phase2s , ,AW\\$)Q//FW\\$*a00FB           ,V^44V^44V#0%,,Q////\&))0$++A....\&))0%,,Q////%,,Q////!((++++9 , ,s$-B BBB** B98B9cspt|j|j|j}|\|_|_|_dSr)rrrr2 same_files diff_files funny_files)rZxx r phase3z dircmp.phase3s3 diT-> ? ?=?:$*:*:*:r csi|_|jD]v}tj|j|}tj|j|}||||j|j |j|<wdSr) subdirsr1rr*r4rrZ __class__rr)rr7Za_xZb_xs r phase4z dircmp.phase4s|  ! P PA',,ty!,,C',,tz1--C#~~c3 TYOODLOO P Pr cs||jD]}|dSr)r?r>valuesphase4_closurerZsdr<r rAzdircmp.phase4_closuresK ,%%''  B         r csBtd|j|j|jr5|jtd|jd|j|jr5|jtd|jd|j|jr.|jtd|j|jr.|jtd|j|jr.|jtd|j|j r.|j td|j |j r0|j td|j dSdS) NZdiffzOnly inz:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :) printrrr.r&r/r9r:r;r1r3r'rr reportz dircmp.reports fdi,,, > = N   ! ! ! )TYT^ < < < ? ? O " " " )TZdo > > > ? 8 O " " " %t 7 7 7 ? 8 O " " " %t 7 7 7   C   ! ! # # # /1A B B B   ?   ! ! # # # +T-= > > >   =   " " $ $ $ ($*; < < < < < = =r cs||jD]$}t|%dSr)rDr>r@rCrBr<r report_partial_closurezdircmp.report_partial_closuresN ,%%''  B GGG IIKKKK  r cs||jD]$}t|%dSr)rDr>r@rCreport_full_closurerBr<r rFzdircmp.report_full_closuresT ,%%'' % %B GGG  " " $ $ $ $ % %r ) r>r9r:r;r1r2r3r-r.r/r$r%cs~||jvrt||j||t||Sr) methodmapZAttributeErrorZgetattr)rZattrr<r __getattr__zdircmp.__getattr__sF t~ % ' && &tT"""tT"""r )NN)__name__Z __module__Z __qualname____doc__r"r(r0r8r=r?rArDrErFr)rGrHZ classmethodrZ__class_getitem__r r r rrXs! ! F ! ! ! !SSS!,!,!,F@@@ P P P   ===2 %%% V &6v#)V"f%& :::I ### $ L11r rcsgggf}|D]l}tj||}tj||}|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. )rr*r4_cmpr6)rr r-rZresr7ZaxZbxs r rrsu r2,C -- W\\!Q   W\\!Q   DR ! !"))!,,,, Jr csT ||||| S#t$rYdSwxYw)N)r5)rr Zshabsrr!r rKrKsH3ss1a}}%%%% qqs  ''csFtt|j|Sr)r+rr,)ZflistZskipr<r r#r#&s  D-u55 6 66r csHddl}ddl}||jddd\}}t|dkr|ddt |d|d}d|vr|dS|dS)Nrr ZrrLzneed exactly two args)z-rZ)sysgetoptZargvrZ GetoptErrorrrFrD)rNrOZoptionsZargsZddr!r demorP,sJJJMMMMM#(122,44MGT 4yyA~@  !8$??? Qa ! !BW       r Z__main__)T)rJrrZ itertoolsrZtypesrZ__all__rrrrrr rrrrMrKr#rPrIr r r rQsX   !!!!!! I I I  JJJ&&&&P   g2g2g2g2g2g2g2g2T6777    z DFFFFF  r