B äxácf&ã@s´dZddlZddlZddlmZdddddgZiZd Zd d d d ddddgZdd„Z d"dd„Z dd„Z dd„Z Gdd„dƒZ d#dd„Zee fdd„Zdd„Zdd „Zed!kr°eƒdS)$z³Utilities for comparing files and directories. Classes: dircmp Functions: cmp(f1, f2, shallow=True) -> int cmpfiles(a, b, common) -> ([], [], []) clear_cache() éN)Ú filterfalseÚ 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/python37/lib64/python3.7/filecmp.pyrsTcCsªtt |¡ƒ}tt |¡ƒ}|dtjks8|dtjkrdS|sdSqWWdQRXWdQRXdS)NÚrbFT)ÚBUFSIZEÚopenÚread)rrÚbufsizeÚfp1Úfp2Zb1Zb2r r r rIs  rc@sŠeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z ee eeeeeeeeeeed Zdd„ZdS)raMA 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 objects, keyed by names in common_dirs. NcCsD||_||_|dkr$tjtjg|_n||_|dkr:t|_n||_dS)N)ÚleftÚrightrÚcurdirÚpardirÚhiderÚignore)ÚselfÚaÚbr,r+r r r Ú__init__xszdircmp.__init__cCsPtt |j¡|j|jƒ|_tt |j¡|j|jƒ|_|j  ¡|j  ¡dS)N) Ú_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 |ƒƒƒ|_dS)N)ÚdictÚzipÚmaprÚpathÚnormcaser3r4ÚlistÚ __getitem__ÚfilterÚ __contains__ÚcommonrÚ left_onlyÚ right_only)r-r.r/r r r Úphase1Œs z dircmp.phase1c Cs:g|_g|_g|_x |jD]}tj |j|¡}tj |j|¡}d}yt  |¡}Wn&t k rz}zd}Wdd}~XYnXyt  |¡}Wn&t k r°}zd}Wdd}~XYnX|r&t   |j ¡}t   |j ¡} || kræ|j  |¡n>t  |¡rþ|j  |¡n&t  |¡r|j  |¡n |j  |¡q|j  |¡qWdS)Nr r)Ú common_dirsÚ common_filesÚ common_funnyr@rr:Újoinr'r(rÚOSErrorrrÚappendÚS_ISDIRÚS_ISREG) r-ÚxZa_pathZb_pathÚokZa_statZwhyZb_statZa_typeZb_typer r r Úphase2“s4    z dircmp.phase2cCs&t|j|j|jƒ}|\|_|_|_dS)N)rr'r(rEÚ same_filesÚ diff_filesÚ funny_files)r-Zxxr r r Úphase3¶sz dircmp.phase3cCsRi|_xF|jD]<}tj |j|¡}tj |j|¡}t|||j|j ƒ|j|<qWdS)N) ÚsubdirsrDrr:rGr'r(rr,r+)r-rLZa_xZb_xr r r Úphase4ºs  z dircmp.phase4cCs(| ¡x|j ¡D] }| ¡qWdS)N)rTrSÚvaluesÚphase4_closure)r-Úsdr r r rVÄszdircmp.phase4_closurecCsätd|j|jƒ|jr2|j ¡td|jd|jƒ|jrT|j ¡td|jd|jƒ|jrp|j ¡td|jƒ|jrŒ|j ¡td|jƒ|jr¨|j ¡td|jƒ|j rÄ|j  ¡td|j ƒ|j rà|j  ¡td|j ƒdS) NZdiffzOnly inú:zIdentical files :zDiffering files :zTrouble with common files :zCommon subdirectories :zCommon funny cases :) Úprintr'r(rAr5rBrOrPrQrDrF)r-r r r ÚreportÉs,           z dircmp.reportcCs.| ¡x |j ¡D]}tƒ| ¡qWdS)N)rZrSrUrY)r-rWr r r Úreport_partial_closureâszdircmp.report_partial_closurecCs.| ¡x |j ¡D]}tƒ| ¡qWdS)N)rZrSrUrYÚreport_full_closure)r-rWr r r r\èszdircmp.report_full_closure) rSrOrPrQrDrErFr@rArBr3r4cCs*||jkrt|ƒ‚|j||ƒt||ƒS)N)Ú methodmapÚAttributeErrorÚgetattr)r-Úattrr r r Ú __getattr__ôs zdircmp.__getattr__)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r0r6rCrNrRrTrVrZr[r\r7r]rar r r r rVs"  #  cCsNgggf}x>|D]6}tj ||¡}tj ||¡}|t|||ƒ |¡qW|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:rGÚ_cmprI)r.r/r@rZresrLZaxZbxr r r rús  cCs,y|||||ƒƒ Stk r&dSXdS)Né)rH)r.r/ZshÚabsrr r r rfsrfcCstt|j|ƒƒS)N)r<rr?)ZflistÚskipr r r r1sr1cCsrddl}ddl}| |jdd…d¡\}}t|ƒdkrB| dd¡‚t|d|dƒ}d|krf| ¡n| ¡dS)Nrr Úrrgzneed exactly two args)z-rÚ)ÚsysÚgetoptÚargvrZ GetoptErrorrr\rZ)rlrmZoptionsÚargsZddr r r Údemo$s   rpÚ__main__)T)T)rerrÚ itertoolsrÚ__all__r r!rrrrrrrrhrfr1rprbr r r r Ú s&  ' %