grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jÂ'ã@s²dZddlZddlZddlmZddlmZgd¢ZiZdZ gd¢Z dd „Z dd d „Z d d„Z dd„ZGdd„dƒZddd„Zee fdd„Zdd„Zdd„ZedkrWeƒdSdS)z³Utilities 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 )ZRCSZCVSZtagsz.gitz.hgz.bzrZ_darcsÚ __pycache__cCs t ¡dS)zClear the filecmp cache.N)Ú_cacheÚclear©r r ú./opt/alt/python310/lib64/python3.10/filecmp.pyrs rTcCsªtt |¡ƒ}tt |¡ƒ}|dtjks|dtjkrdS|r&||kr&dS|d|dkr0dSt ||||f¡}|durSt||ƒ}ttƒdkrKtƒ|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(). rFTéNéd) Ú_sigÚosÚstatÚS_IFREGr ÚgetÚ_do_cmpÚlenr)Úf1Úf2ÚshallowÚs1Ús2Zoutcomer r r rs   rcCst |j¡|j|jfS©N)rÚS_IFMTÚst_modeÚst_sizeÚst_mtime)Ústr r r rFs þrc Cs°t}t|dƒ�G}t|dƒ�1} | |¡}| |¡}||kr, WdƒWdƒdS|s= WdƒWdƒdSq1sAwYWdƒdS1sQwYdS)NÚrbTF)ÚBUFSIZEÚopenÚread)rrÚbufsizeÚfp1Úfp2Zb1Zb2r r r rKs  ûù4ÿrc@s’eZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z ee eeeeeeeeeeed� Zdd„ZeeƒZdS)ra®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. NcCsF||_||_|durtjtjg|_n||_|durt|_dS||_dSr)ÚleftÚrightrÚcurdirÚpardirÚhiderÚignore)ÚselfÚaÚbr.r-r r r Ú__init__|s  zdircmp.__init__cCsPtt |j¡|j|jƒ|_tt |j¡|j|jƒ|_|j  ¡|j  ¡dSr) Ú_filterrÚlistdirr)r-r.Ú left_listr*Ú right_listÚsort©r/r r r Úphase0ˆs  ÿ  ÿ z dircmp.phase0cCsŠttttjj|jƒ|jƒƒ}ttttjj|jƒ|jƒƒ}tt|j t |j |ƒƒƒ|_ tt|j t |j |ƒƒƒ|_tt|j t |j |ƒƒƒ|_dSr)ÚdictÚzipÚmaprÚpathÚnormcaser5r6ÚlistÚ __getitem__ÚfilterÚ __contains__ÚcommonrÚ left_onlyÚ right_only)r/r0r1r r r Úphase1�s z dircmp.phase1c Csg|_g|_g|_|jD]x}tj |j|¡}tj |j|¡}d}zt  |¡}Wn t y2d}Ynwzt  |¡}Wn t yEd}Ynw|r~t   |j ¡}t   |j ¡}||kr_|j  |¡q t  |¡rk|j  |¡q t  |¡rw|j  |¡q |j  |¡q |j  |¡q dS)Nrr)Ú common_dirsÚ common_filesÚ common_funnyrCrr=Újoinr)r*rÚOSErrorrrÚappendÚS_ISDIRÚS_ISREG) r/ÚxZa_pathZb_pathÚokZa_statZb_statZa_typeZb_typer r r Úphase2—s:  þ þ    äz dircmp.phase2cCs&t|j|j|jƒ}|\|_|_|_dSr)rr)r*rHÚ same_filesÚ diff_filesÚ funny_files)r/Zxxr r r Úphase3ºsz dircmp.phase3cCsPi|_|jD]}tj |j|¡}tj |j|¡}| |||j|j ¡|j|<qdSr) ÚsubdirsrGrr=rJr)r*Ú __class__r.r-)r/rOZa_xZb_xr r r Úphase4¾s  ýz dircmp.phase4cCs$| ¡|j ¡D]}| ¡q dSr)rXrVÚvaluesÚphase4_closure©r/Zsdr r r rZÉs ÿzdircmp.phase4_closurecCsètd|j|jƒ|jr|j ¡td|jd|jƒ|jr*|j ¡td|jd|jƒ|jr8|j ¡td|jƒ|jrF|j ¡td|jƒ|jrT|j ¡td|jƒ|j rb|j  ¡td|j ƒ|j rr|j  ¡td|j ƒdSdS) NZdiffzOnly inú:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :) Úprintr)r*rDr7rErRrSrTrGrIr8r r r ÚreportÎs.           þz dircmp.reportcCs*| ¡|j ¡D] }tƒ| ¡q dSr)r^rVrYr]r[r r r Úreport_partial_closureçó  þzdircmp.report_partial_closurecCs*| ¡|j ¡D] }tƒ| ¡q dSr)r^rVrYr]Úreport_full_closurer[r r r raír`zdircmp.report_full_closure) rVrRrSrTrGrHrIrCrDrEr5r6cCs*||jvr t|ƒ‚|j||ƒt||ƒSr)Ú methodmapÚAttributeErrorÚgetattr)r/Úattrr r r Ú __getattr__ùs  zdircmp.__getattr__)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r2r9rFrQrUrXrZr^r_rar:rbrfÚ classmethodrÚ__class_getitem__r r r r rXs( # # ü rcCsJgggf}|D]}tj ||¡}tj ||¡}|t|||ƒ |¡q|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=rJÚ_cmprL)r0r1rCrÚresrOZaxZbxr r r rs rcCs*z |||||ƒƒ WStyYdSw)Né)rK)r0r1ZshÚabsrr r r rms  ÿrmcCstt|j|ƒƒSr)r?rrB)ZflistÚskipr r r r3&sr3cCstddl}ddl}| |jdd…d¡\}}t|ƒdkr!| dd¡‚t|d|dƒ}d|vr4| ¡dS| ¡dS)NrrÚrrozneed exactly two args)z-rÚ)ÚsysÚgetoptÚargvrZ GetoptErrorrrar^)rtruZoptionsÚargsZddr r r Údemo,s    rxÚ__main__)T)rjrrÚ itertoolsrÚtypesrÚ__all__r r#rrrrrrrrprmr3rxrgr r r r Ús,    (  +  ÿ