ó zfc@s3dZddlZddlZddlZddlmZddlZddlZddlZyddl Z [ e Z Wne k re Z nXyddlZ[e ZWne k rĆe ZnXyddlmZWne k rńdZnXyddlmZWne k rdZnXdddd d d d d dddddddddgZdefd„ƒYZdefd„ƒYZdefd„ƒYZyeWnek r¼dZnXd?d„Zd„Zd„Zd„Zd „Z d!„Z!d"„Z"d#„Z#e dd$„Z$e dd%„Z%d&„Z&d'„Z'd(„Z(d)„Z)d*„Z*d+d,d,dddd-„Z+d.„Z,d,d,dd/„Z-ie+d@gd1fd26e-gd3fd46Z.e rŃe+dAgd5fe.d6„Z2dS(Cs—Utility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. i’’’’N(tabspath(tgetpwnam(tgetgrnamt copyfileobjtcopyfiletcopymodetcopystattcopytcopy2tcopytreetmovetrmtreetErrortSpecialFileErrort ExecErrort make_archivetget_archive_formatstregister_archive_formattunregister_archive_formattignore_patternscBseZRS((t__name__t __module__(((s/usr/lib64/python2.7/shutil.pyR -scBseZdZRS(s|Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)(RRt__doc__(((s/usr/lib64/python2.7/shutil.pyR 0scBseZdZRS(s+Raised when a command could not be executed(RRR(((s/usr/lib64/python2.7/shutil.pyR4siicCs1x*|j|ƒ}|sPn|j|ƒqWdS(s=copy data from file-like object fsrc to file-like object fdstN(treadtwrite(tfsrctfdsttlengthtbuf((s/usr/lib64/python2.7/shutil.pyR<s cCs{ttjdƒrAytjj||ƒSWqAtk r=tSXntjjtjj|ƒƒtjjtjj|ƒƒkS(Ntsamefile(thasattrtostpathRtOSErrortFalsetnormcaseR(tsrctdst((s/usr/lib64/python2.7/shutil.pyt _samefileDs c CsĢt||ƒr(td||fƒ‚nx`||gD]R}ytj|ƒ}Wntk raq5Xtj|jƒr5td|ƒ‚q5q5Wt|dƒ,}t|dƒ}t ||ƒWdQXWdQXdS(sCopy data from src to dsts`%s` and `%s` are the same files`%s` is a named pipetrbtwbN( R&R RtstatR!tS_ISFIFOtst_modeR topenR(R$R%tfntstRR((s/usr/lib64/python2.7/shutil.pyRPs cCsGttdƒrCtj|ƒ}tj|jƒ}tj||ƒndS(sCopy mode bits from src to dsttchmodN(RRR)tS_IMODER+R/(R$R%R.tmode((s/usr/lib64/python2.7/shutil.pyRdscCstj|ƒ}tj|jƒ}ttdƒrOtj||j|jfƒnttdƒrqtj||ƒnttdƒržt|dƒržytj ||j ƒWqžt k rś}x@dD]1}tt |ƒræ|j t t |ƒkræPqæqæW‚qžXndS( s;Copy file metadata Copy the permission bits, last access time, last modification time, and flags from `src` to `dst`. On Linux, copystat() also copies the "extended attributes" where possible. The file contents, owner, and group are unaffected. `src` and `dst` are path names given as strings. tutimeR/tchflagstst_flagst EOPNOTSUPPtENOTSUPN(R5R6(RR)R0R+RR2tst_atimetst_mtimeR/R3R4R!terrnotgetattr(R$R%R.R1twhyterr((s/usr/lib64/python2.7/shutil.pyRks 'cCsTtjj|ƒr6tjj|tjj|ƒƒ}nt||ƒt||ƒdS(sVCopy data and mode bits ("cp src dst"). The destination may be a directory. N(RR tisdirtjointbasenameRR(R$R%((s/usr/lib64/python2.7/shutil.pyRƒs$ cCsTtjj|ƒr6tjj|tjj|ƒƒ}nt||ƒt||ƒdS(sÉCopy data and metadata. Return the file's destination. Metadata is copied with copystat(). Please see the copystat function for more information. The destination may be a directory. N(RR R=R>R?RR(R$R%((s/usr/lib64/python2.7/shutil.pyRŽs $ cs‡fd†}|S(sFunction 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]}|jtj||ƒƒq Wt|ƒS(N(textendtfnmatchtfiltertset(R tnamest ignored_namestpattern(tpatterns(s/usr/lib64/python2.7/shutil.pyt_ignore_patterns”s ((RGRH((RGs/usr/lib64/python2.7/shutil.pyRœsc CsŲtj|ƒ}|dk r-|||ƒ}n tƒ}tj|ƒg}x|D] }||krhqPntjj||ƒ}tjj||ƒ} ys|rĻtjj|ƒrĻtj|ƒ} tj | | ƒn5tjj |ƒr÷t || ||ƒn t || ƒWqPt k r.} |j| jdƒqPtk r\} |j|| t| ƒfƒqPXqPWyt||ƒWnMtk rĮ} tdk r¢t| tƒr¢qĀ|j||t| ƒfƒnX|rŌ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(RtlistdirtNoneRCtmakedirsR R>tislinktreadlinktsymlinkR=R RR R@targstEnvironmentErrortappendtstrRR!t WindowsErrort isinstance( R$R%tsymlinkstignoreRDREterrorstnametsrcnametdstnametlinktoR<R;((s/usr/lib64/python2.7/shutil.pyR Øs<     $ cCsĪ|rd„}n|dkr*d„}ny%tjj|ƒrNtdƒ‚nWn.tk r|tjj|tjƒƒdSXg}ytj|ƒ}Wn/tjk rŹ}|tj|tjƒƒnXx»|D]³}tjj ||ƒ}ytj |ƒj }Wntjk rd}nXt j |ƒrBt|||ƒqŅytj|ƒWqŅtjk r„}|tj|tjƒƒqŅXqŅWytj|ƒWn-tjk rÉ|tj|tjƒƒ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((RO((s/usr/lib64/python2.7/shutil.pytonerrorõscWs‚dS(N((RO((s/usr/lib64/python2.7/shutil.pyR\ųss%Cannot call rmtree on a symbolic linkNi(RJRR RLR!tsystexc_infoRIterrorR>tlstatR+R)tS_ISDIRR tremovetrmdir(R t ignore_errorsR\RDR<RXtfullnameR1((s/usr/lib64/python2.7/shutil.pyR és>       !cCs5tjjtjjpd}tjj|j|ƒƒS(Nt(RR tseptaltsepR?trstrip(R Rg((s/usr/lib64/python2.7/shutil.pyt _basenamescCs|}tjj|ƒr{t||ƒr;tj||ƒdStjj|t|ƒƒ}tjj|ƒr{td|‚q{nytj||ƒWn‚t k rtjj|ƒröt ||ƒrÖtd||f‚nt ||dt ƒt |ƒqt||ƒtj|ƒ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. Ns$Destination path '%s' already existss.Cannot move a directory '%s' into itself '%s'.RU(RR R=R&trenameR>RjtexistsR R!t _destinsrcR tTrueR Rtunlink(R$R%treal_dst((s/usr/lib64/python2.7/shutil.pyR s$   cCsut|ƒ}t|ƒ}|jtjjƒs@|tjj7}n|jtjjƒsh|tjj7}n|j|ƒS(N(RtendswithRR Rgt startswith(R$R%((s/usr/lib64/python2.7/shutil.pyRmHs  cCs^tdks|dkrdSyt|ƒ}Wntk rEd}nX|dk rZ|dSdS(s"Returns a gid, given a group name.iN(RRJtKeyError(RXtresult((s/usr/lib64/python2.7/shutil.pyt_get_gidQs   cCs^tdks|dkrdSyt|ƒ}Wntk rEd}nX|dk rZ|dSdS(s"Returns an uid, given a user name.iN(RRJRs(RXRt((s/usr/lib64/python2.7/shutil.pyt_get_uid]s   tgzipics‡|d krd}nKtr0|dkr0d}n0trK|dkrKd}ntdj|ƒƒ‚|rpd|nd} |d| } tjj| ƒ} | rētjj| ƒ rē|d k rĪ|j d | ƒn|sētj | ƒqēnd d l } |d k r|j d ƒnt ˆƒ‰t ˆƒ‰‡‡‡‡fd †} |sƒ| j| d|ƒ}z|j|d| ƒWd |jƒXn| S(sķCreate a (possibly compressed) tar file from all the files under 'base_dir'. 'compress' must be "gzip" (the default), "bzip2", or None. 'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owner and group will be used. The output tar file will be named 'base_name' + ".tar", possibly plus the appropriate compression extension (".gz", or ".bz2"). Returns the output filename. RfRwtgztbzip2tbz2sCbad value for 'compress', or compression format not supported : {0}t.s.tars creating %si’’’’NsCreating tar archivecsFˆdk r!ˆ|_ˆ|_nˆdk rBˆ|_ˆ|_n|S(N(RJtgidtgnametuidtuname(ttarinfo(R|tgrouptownerR~(s/usr/lib64/python2.7/shutil.pyt _set_uid_gid—s      sw|%sRB(RJt_ZLIB_SUPPORTEDt_BZ2_SUPPORTEDt ValueErrortformatRR tdirnameRltinfoRKttarfileRvRuR,taddtclose(t base_nametbase_dirtcompresstverbosetdry_runR‚Rtloggerttar_compressiont compress_extt archive_namet archive_dirRŠRƒttar((R|RR‚R~s/usr/lib64/python2.7/shutil.pyt _make_tarballis8            cCs›|rd}nd}d|||g}|dk rL|jdj|ƒƒn|rVdSddl}y|j|ƒWn!|jk r–td|‚nXdS(Ns-rs-rqtzipt i’’’’skunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility(RJR‰R>t subprocesst check_calltCalledProcessErrorR(RŽt zip_filenameRR‘R’t zipoptionstcmdR›((s/usr/lib64/python2.7/shutil.pyt_call_external_zip©s   c Csn|d}tjj|ƒ}|rmtjj|ƒ rm|dk rT|jd|ƒn|smtj|ƒqmnyddl}ddl}Wnt k r¢d}nX|dkrČt |||||ƒn¢|dk rź|jd||ƒn|sj|j |dd|j ƒZ} tjj |ƒ} | tjkra| j| | ƒ|dk ra|jd| ƒqanxżtj|ƒD]ģ\} } } xdt| ƒD]V}tjj tjj| |ƒƒ} | j| | ƒ|dk r|jd| ƒqqWxs| D]k}tjj tjj| |ƒƒ} tjj| ƒrī| j| | ƒ|dk rY|jd| ƒqYqīqīWqqWWdQXn|S( smCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises ExecError. Returns the name of the output zip file. s.zips creating %si’’’’Ns#creating '%s' and adding '%s' to ittwt compressions adding '%s'(RR RˆRlRJR‰RKtzlibtzipfilet ImportErrorR”tZipFilet ZIP_DEFLATEDtnormpathtcurdirRtwalktsortedR>tisfile(RRŽRR‘R’RžR–R¤R„tzfR tdirpathtdirnamest filenamesRX((s/usr/lib64/python2.7/shutil.pyt _make_zipfileæsL          !  ! 'Rsuncompressed tar fileR—sZIP fileR™sgzip'ed tar-filetgztarRysbzip2'ed tar-filetbztarcCs=gtjƒD]\}}||df^q }|jƒ|S(s‘Returns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) i(t_ARCHIVE_FORMATStitemstsort(RXtregistrytformats((s/usr/lib64/python2.7/shutil.pyRs, RfcCs½|dkrg}nt|tjƒs:td|ƒ‚nt|ttfƒs^tdƒ‚nxE|D]=}t|ttfƒ s“t|ƒdkretdƒ‚qeqeW|||ft|s                            A1  ( ? 8