Ñò ndJc@s,dZddkZddkZddkZddklZddkZdddddd d d d d g Zd efd„ƒYZ ye Wne j o dZ nXdd„Z d„Zd„Zd„Zd„Zd„Zd„Zd„Zedd„Zedd„Zd„Zd„Zd„ZdS(s‰Utility functions for copying files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. iÿÿÿÿN(tabspatht copyfileobjtcopyfiletcopymodetcopystattcopytcopy2tcopytreetmovetrmtreetErrorcBseZRS((t__name__t __module__(((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR siicCs2x+|i|ƒ}|pPn|i|ƒqdS(s=copy data from file-like object fsrc to file-like object fdstN(treadtwrite(tfsrctfdsttlengthtbuf((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyRs cCsttidƒo2ytii||ƒSWqEtj otSXntiitii|ƒƒtiitii|ƒƒjS(Ntsamefile(thasattrtostpathRtOSErrortFalsetnormcaseR(tsrctdst((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyt _samefile s cCs”t||ƒotd||f‚nd}d}z/t|dƒ}t|dƒ}t||ƒWd|o|iƒn|o|iƒnXdS(sCopy data from src to dsts`%s` and `%s` are the same filetrbtwbN(RR tNonetopenRtclose(RRRR((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR,scCsIttdƒo5ti|ƒ}ti|iƒ}ti||ƒndS(sCopy mode bits from src to dsttchmodN(RRtstattS_IMODEtst_modeR"(RRtsttmode((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR=scCs°ti|ƒ}ti|iƒ}ttdƒo ti||i|ifƒnttdƒoti||ƒnttdƒo't|dƒoti ||i ƒndS(sCCopy all stat info (mode bits, atime, mtime, flags) from src to dsttutimeR"tchflagstst_flagsN( RR#R$R%RR(tst_atimetst_mtimeR"R)R*(RRR&R'((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyRDs  cCsVtii|ƒo%tii|tii|ƒƒ}nt||ƒt||ƒdS(sVCopy data and mode bits ("cp src dst"). The destination may be a directory. N(RRtisdirtjointbasenameRR(RR((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyRPs% cCsVtii|ƒo%tii|tii|ƒƒ}nt||ƒt||ƒdS(s]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N(RRR-R.R/RR(RR((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR[s% cs‡fd†}|S(sFunction that can be used as copytree() ignore parameter. Patterns is a sequence of glob-style patterns that are used to exclude filescs:g}x'ˆD]}|iti||ƒƒq Wt|ƒS(N(textendtfnmatchtfiltertset(Rtnamest ignored_namestpattern(tpatterns(s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyt_ignore_patternsks ((R7R8((R7s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pytignore_patternsfsc Csõti|ƒ}|dj o|||ƒ}n tƒ}ti|ƒg}x)|D]!}||joqRntii||ƒ}tii||ƒ} yx|o6tii|ƒo#ti|ƒ} ti | | ƒn8tii |ƒot || ||ƒnt || ƒWqRt tifj o%} |i|| t| ƒfƒqRtj o} |i| idƒqRXqRWyt||ƒWnRtj oF} tdj ot| tƒoqÝ|i||t| ƒfƒnX|o t|‚ndS(sÇRecursively copy a directory tree using copy2(). The destination directory must not already exist. If exception(s) occur, an Error is raised with a list of reasons. If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied. The optional ignore argument is a callable. If given, it is called with the `src` parameter, which is the directory being visited by copytree(), and `names` which is the list of `src` contents, as returned by os.listdir(): callable(src, names) -> ignored_names Since copytree() is called recursively, the callable will be called once for each directory that is copied. It returns a list of names relative to the `src` directory that should not be copied. XXX Consider this example code rather than the ultimate tool. iN(RtlistdirRR3tmakedirsRR.tislinktreadlinktsymlinkR-RRtIOErrorterrortappendtstrR R0targsRRt WindowsErrort isinstance( RRtsymlinkstignoreR4R5terrorstnametsrcnametdstnametlinktotwhyterr((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyRrs>     !cCsà|o d„}n|djo d„}ny'tii|ƒotdƒ‚nWn0tj o$|tii|tiƒƒdSXg}yti|ƒ}Wn1tij o"}|ti|tiƒƒnXxÁ|D]¹}tii ||ƒ}yti |ƒi }Wntij o d}nXt i |ƒot|||ƒqÜyti|ƒWqÜtij o"}|ti|tiƒƒqÜXqÜWyti|ƒWn/tij o |ti|tiƒƒnXdS(sÁRecursively delete a directory tree. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error with arguments (func, path, exc_info) where func is os.listdir, os.remove, or os.rmdir; path is the argument to that function that caused it to fail; and exc_info is a tuple returned by sys.exc_info(). If ignore_errors is false and onerror is None, an exception is raised. cWsdS(N((RC((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pytonerror¿scWs‚dS(N((RC((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyROÂss%Cannot call rmtree on a symbolic linkNi(RRRR<Rtsystexc_infoR:R@R.tlstatR%R#tS_ISDIRR tremovetrmdir(Rt ignore_errorsROR4RNRItfullnameR'((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR ³s@     "cCstii|itiiƒƒS(N(RRR/trstriptsep(R((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyt _basenameäscCsÿ|}tii|ƒoCtii|t|ƒƒ}tii|ƒotd|‚q\nyti||ƒWnˆtj o|tii|ƒoHt ||ƒotd||f‚nt ||dt ƒt |ƒqût ||ƒti|ƒnXdS(s“Recursively move a file or directory to another location. This is similar to the Unix "mv" command. If the destination is a directory or a symlink to a directory, the source is moved inside the directory. The destination path must not already exist. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics. If the destination is on our current filesystem, then rename() is used. Otherwise, src is copied to the destination and then removed. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. s$Destination path '%s' already existss.Cannot move a directory '%s' into itself '%s'.RFN(RRR-R.RZtexistsR trenameRt destinsrcRtTrueR Rtunlink(RRtreal_dst((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyRés cCst|ƒit|ƒƒS(N(Rt startswith(RR((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyR] si@(t__doc__RRPR#tos.pathRR1t__all__tEnvironmentErrorR RDt NameErrorRRRRRRRRR9RRR RZRR](((s2/usr/lib/python2.6/site-packages/cas/cas_shutil.pyts2         A1  "