o bc'@sdZddlZddlZddlmZddlmZgdZiZdZ gdZ dd Z dd d Z d dZ ddZGdddZdddZee fddZddZddZedkrWedSdS)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_darcs __pycache__cCs tdS)zClear the filecmp cache.N)_cacheclearr r h/home/lily/lilypond-2.24.1/release/binaries/dependencies/install/Python-3.10.8/lib/python3.10/filecmp.pyrs rTcCstt|}tt|}|dtjks|dtjkrdS|r&||kr&dS|d|dkr0dSt||||f}|durSt||}ttdkrKt|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_IFREGr get_do_cmplenr)f1f2shallows1s2Zoutcomer r r rs   rcCst|j|j|jfSN)rS_IFMTst_modest_sizest_mtime)str r r rFs rc Cst}t|dG}t|d1} ||}||}||kr, WdWddS|s= WdWddSq1sAwYWddS1sQwYdS)NrbTF)BUFSIZEopenread)rrbufsizefp1fp2Zb1Zb2r r r rKs  4rc@seZdZdZdddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ee eeeeeeeeeeed ZddZeeZdS)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. NcCsF||_||_|durtjtjg|_n||_|durt|_dS||_dSr)leftrightrcurdirpardirhiderignore)selfabr.r-r r r __init__|s  zdircmp.__init__cCsPtt|j|j|j|_tt|j|j|j|_|j |j dSr) _filterrlistdirr)r-r. left_listr* right_listsortr/r r r phase0s     z dircmp.phase0cCsttttjj|j|j}ttttjj|j|j}tt|j t |j ||_ tt|j t |j ||_tt|j t |j ||_dSr)dictzipmaprpathnormcaser5r6list __getitem__filter __contains__commonr left_only right_only)r/r0r1r r r phase1s 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*rOSErrorrrappendS_ISDIRS_ISREG) r/xZa_pathZb_pathokZa_statZb_statZa_typeZb_typer r r phase2s:       z dircmp.phase2cCs&t|j|j|j}|\|_|_|_dSr)rr)r*rH same_files diff_files funny_files)r/Zxxr r r phase3sz dircmp.phase3cCsPi|_|jD]}tj|j|}tj|j|}||||j|j |j|<qdSr) subdirsrGrr=rJr)r* __class__r.r-)r/rOZa_xZb_xr r r phase4s  z dircmp.phase4cCs$||jD]}|q dSr)rXrVvaluesphase4_closurer/Zsdr r r rZs zdircmp.phase4_closurecCstd|j|j|jr|jtd|jd|j|jr*|jtd|jd|j|jr8|jtd|j|jrF|jtd|j|jrT|jtd|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 reports.           z dircmp.reportcCs*||jD] }t|q dSr)r^rVrYr]r[r r r report_partial_closure  zdircmp.report_partial_closurecCs*||jD] }t|q dSr)r^rVrYr]report_full_closurer[r r r rar`zdircmp.report_full_closure) rVrRrSrTrGrHrIrCrDrEr5r6cCs*||jvr t||j||t||Sr) methodmapAttributeErrorgetattr)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)r0r1rCrresrOZaxZbxr r r rs rcCs*z ||||| WStyYdSw)N)rK)r0r1Zshabsrr r r rms  rmcCstt|j|Sr)r?rrB)flistskipr r r r3&sr3cCstddl}ddl}||jddd\}}t|dkr!|ddt|d|d}d|vr4|dS|dS)Nrrrrozneed exactly two args)z-r)sysgetoptargvrZ GetoptErrorrrar^)rurvZoptionsargsZddr r r demo,s    ry__main__)T)rjrr itertoolsrtypesr__all__r r#rrrrrrrrprmr3ryrgr r r r s,    (  +