m๒ %UฒIc @s๋dZdkZdkZdkZdkZdklZddddddd d d d g Zd eifd „ƒYZ ddd„Z d„Z d„Z d„Z d„Zd„Zd„Zed„Zedd„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. N(sabspatht copyfileobjtcopyfiletcopymodetcopystattcopytcopy2tcopytreetmovetrmtreetErrorcBstZRS(N(t__name__t __module__(((t#/data/zmath/lib/python2.4/shutil.pyR siicCs4x-|i|ƒ}|pPn|i|ƒqWdS(s=copy data from file-like object fsrc to file-like object fdstiN(tfsrctreadtlengthtbuftfdsttwrite(R RRR((R RscCs‚ttidƒo5ytii||ƒSWqHtj o tSqHXntiitii |ƒƒtiitii |ƒƒjS(Ntsamefile( thasattrtostpathRtsrctdsttOSErrortFalsetnormcasetabspath(RR((R t _samefiles  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( RRRR tNoneR RtopenRtclose(RRRR ((R R'scCsIttdƒo5ti|ƒ}ti|iƒ}ti||ƒndS(sCopy mode bits from src to dsttchmodN( RRtstatRtsttS_IMODEtst_modetmodeR#R(RRR%R(((R R8s cCsyti|ƒ}ti|iƒ}ttdƒo ti||i |i fƒnttdƒoti ||ƒndS(s?Copy all stat info (mode bits, atime and mtime) from src to dsttutimeR#N( RR$RR%R&R'R(RR)Rtst_atimetst_mtimeR#(RRR%R(((R R?s cCsVtii|ƒo%tii|tii|ƒƒ}nt||ƒt||ƒdS(sVCopy data and mode bits ("cp src dst"). The destination may be a directory. N( RRtisdirRtjointbasenameRRR(RR((R RIs % 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,RR-R.RRR(RR((R RTs % c CsIti|ƒ} ti|ƒg}x | D]}tii ||ƒ}tii ||ƒ}yu|o6tii |ƒo#ti|ƒ} ti| |ƒn5tii|ƒot|||ƒnt||ƒWq)ttifj o}|i|||fƒq)tj o}|i|idƒq)Xq)W|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. XXX Consider this example code rather than the ultimate tool. iN(RtlistdirRtnamestmkdirRterrorstnameRR-tsrcnametdstnametsymlinkstislinktreadlinktlinktotsymlinkR,RRtIOErrorterrortwhytappendR terrtextendtargs( RRR6R2R3R?R5R=R4R0R9((R R`s*  cCs†|o d„}n|djo d„}ng}yti|ƒ}Wn1tij o"}|ti|t i ƒƒnXxม|D]น}tii ||ƒ}yti|ƒi}Wntij o d}nXti|ƒot|||ƒq‚yti|ƒWq‚tij o"}|ti|t i ƒƒq‚Xq‚Wyti|ƒWn/tij o |ti|t i ƒƒ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. cGsdS(N((RA((R tonerror’scGs‚dS(N((RA((R RB•siN(t ignore_errorsRBR R0RR/RR<R?tsystexc_infoR3R-tfullnametlstatR'R(R$tS_ISDIRRtremovetrmdir(RRCRBR3R?R0RFR(((R R†s6     "cCsฃyti||ƒWnˆtj o|tii|ƒoHt||ƒotd||f‚nt ||dt ƒt |ƒqŸt ||ƒti |ƒnXdS(s=Recursively move a file or directory to another location. If the destination is on our current filesystem, then simply use rename. Otherwise, copy src to the dst and then remove src. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. s.Cannot move a directory '%s' into itself '%s'.R6N(RtrenameRRRRR,t destinsrcR RtTrueRRtunlink(RR((R Rฎs cCst|ƒit|ƒƒS(N(RRt startswithR(RR((R RLฤs(t__doc__RRDR$t exceptionstos.pathRt__all__tEnvironmentErrorR RRRRRRRRRR RRRL(RRR$RRRSRRRRDRLRRR RQRRR((R t?s$     $   &(