Vc'dZddlZddlZddlmZddlmZgdZiZdZ 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 )RCSCVStagsz.gitz.hgz.bzr_darcs __pycache__c8tdS)zClear the filecmp cache.N)_cacheclear /usr/lib64/python3.11/filecmp.pyrrs LLNNNNNrTcttj|}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(). rFTNd) _sigosstatS_IFREGrget_do_cmplenr)f1f2shallows1s2outcomes rrrs. bgbkk  B bgbkk  B !u 1 5u28t !u1~ujj"b"b)**G)"b// v;;   MMM!(r2r2~ NrcNtj|j|j|jfSN)rS_IFMTst_modest_sizest_mtime)sts rrrFs% K # # J K rcjt}t|d5}t|d5} ||}||}||kr dddddddS|s dddddddSe#1swxYwYddddS#1swxYwYdS)NrbTF)BUFSIZEopenread)rr bufsizefp1fp2b1b2s rrrKsG b$3R# '""B'""BRx     sFB(3B B(4B7 B(BB B(B B((B,/B,ceZdZdZddZdZdZdZdZdZ 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. Nc||_||_|tjtjg|_n||_|t |_dS||_dSr&)leftrightrcurdirpardirhider ignore)selfabr=r<s r__init__zdircmp.__init__|sO   BI.DIIDI  !)DKKK DKKKrcNttj|j|j|jz|_ttj|j|j|jz|_|j |j dSr&) _filterrlistdirr8r<r= left_listr9 right_listsortr>s rphase0z dircmp.phase0s DI!6!6!%4;!688!"*TZ"8"8"&)DK"799  rc rttttjj|j|j}ttttjj|j|j}tt|j t|j ||_ tt|j t|j ||_tt|j t|j ||_dSr&)dictzipmaprpathnormcaserErFlist __getitem__filter __contains__commonr left_only right_only)r>r?r@s rphase1z dircmp.phase1s S)4>::DNKK L L S)4?;;T_MM N N3q}fQ^Q.G.GHHII c!-Q^Q1O1OPPQQs1=+ana2P2PQQRRrcVg|_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)Nrr) common_dirs common_files common_funnyrTrrNjoinr8r9rOSErrorr'r(appendS_ISDIRS_ISREG) r>xa_pathb_pathoka_statb_stata_typeb_types rphase2z dircmp.phase2s , ,AW\\$)Q//FW\\$*a00FB           ,V^44V^44V#0%,,Q////\&))0$++A....\&))0%,,Q////%,,Q////!((++++9 , ,s$-B BBB** B98B9cpt|j|j|j}|\|_|_|_dSr&)rr8r9rZ same_files diff_files funny_files)r>xxs rphase3z dircmp.phase3s3 diT-> ? ?=?:$*:*:*:rci|_|jD]v}tj|j|}tj|j|}||||j|j |j|<wdSr&) subdirsrYrrNr\r8r9 __class__r=r<)r>raa_xb_xs rphase4z dircmp.phase4s|  ! P PA',,ty!,,C',,tz1--C#~~c3 TYOODLOO P Prc||jD]}|dSr&)rurqvaluesphase4_closurer>sds rrxzdircmp.phase4_closuresK ,%%''  B         rcBtd|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) NdiffzOnly in:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :) printr8r9rUrGrVrkrlrmrYr[rHs rreportz 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-= > > >   =   " " $ $ $ ($*; < < < < < = =rc||jD]$}t|%dSr&)rrqrwr~rys rreport_partial_closurezdircmp.report_partial_closuresN ,%%''  B GGG IIKKKK  rc||jD]$}t|%dSr&)rrqrwr~report_full_closurerys rrzdircmp.report_full_closuresT ,%%'' % %B GGG  " " $ $ $ $ % %r) rqrkrlrmrYrZr[rTrUrVrErFc~||jvrt||j||t||Sr&) methodmapAttributeErrorgetattr)r>attrs r __getattr__zdircmp.__getattr__sF t~ % ' && &tT"""tT"""r)NN)__name__ __module__ __qualname____doc__rArIrWrirorurxrrrrKrr classmethodr__class_getitem__rrrrrXs! ! F ! ! ! !SSS!,!,!,F@@@ P P P   ===2 %%% V &6v#)V"f%& :::I ### $ L11rrcgggf}|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. )rrNr\_cmpr^)r?r@rTr!resraaxbxs rrrsu r2,C -- W\\!Q   W\\!Q   DR ! !"))!,,,, JrcT ||||| S#t$rYdSwxYw)N)r])r?r@shabsrs rrrsH3ss1a}}%%%% qqs  ''cFtt|j|Sr&)rPrrS)flistskips rrCrC&s  D-u55 6 66rcHddl}ddl}||jddd\}}t|dkr|ddt |d|d}d|vr|dS|dS)Nrrrrzneed exactly two args)z-r)sysgetoptargvr GetoptErrorrrr)rroptionsargsdds rdemor,sJJJMMMMM#(122,44MGT 4yyA~@  !8$??? Qa ! !BW       r__main__)T)rrr itertoolsrtypesr__all__rr.r rrrrrrrrrCrrrrrrsX   !!!!!! I I I  JJJ&&&&P   g2g2g2g2g2g2g2g2T6777    z DFFFFF  r