abc@s"dZddlZddlZddlZddlmZddlZddlZddlZddl m Z yddl Z e Z Wnek reZ nXyddlmZWnek rdZnXyddlmZWnek rdZnXdd d d d d dddddddddddddddgZdefdYZdefdYZdefdYZd efd!YZd"efd#YZyeWnek rdZnXdWd&Zd'Z d(Z!d)Z"d*Z#d+Z$d,Z%d-Z&ede%ed.Z'edd/Z(d0Z)d1Z*d2Z+d3Z,d4Z-d5d6d6dddd7Z.eed8Z/d6d6dd9Z0ie.dXgd;fd<6e.dYgd>fd?6e.dZgd@fdA6e0gdBfdC6Z1e re.d[gd>fe1d?fe=d?dddVZ?dS(\sUtility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. iN(tabspathi(ttarfile(tgetpwnam(tgetgrnamt copyfileobjtcopyfiletcopymodetcopystattcopytcopy2tcopytreetmovetrmtreetErrortSpecialFileErrort ExecErrort make_archivetget_archive_formatstregister_archive_formattunregister_archive_formattget_unpack_formatstregister_unpack_formattunregister_unpack_formattunpack_archivetignore_patternscBseZRS((t__name__t __module__(((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/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__(((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR/scBseZdZRS(s+Raised when a command could not be executed(RRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR3st ReadErrorcBseZdZRS(s%Raised when an archive cannot be read(RRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR6st RegistryErrorcBseZdZRS(sVRaised when a registry operation with the archiving and unpacking registries fails(RRR(((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR9siicCs1x*|j|}|sPn|j|qWdS(s=copy data from file-like object fsrc to file-like object fdstN(treadtwrite(tfsrctfdsttlengthtbuf((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRCs cCs{ttjdrAytjj||SWqAtk r=tSXntjjtjj|tjjtjj|kS(Ntsamefile(thasattrtostpathR$tOSErrortFalsetnormcaseR(tsrctdst((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyt _samefileKs c Cst||r(td||fnx`||gD]R}ytj|}Wntk raq5Xtj|jr5td|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 R&tstatR(tS_ISFIFOtst_modeRtopenR(R+R,tfntstR R!((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRWs cCsGttdrCtj|}tj|j}tj||ndS(sCopy mode bits from src to dsttchmodN(R%R&R0tS_IMODER2R6(R+R,R5tmode((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRkscCstj|}tj|j}ttdrOtj||j|jfnttdrqtj||nttdrt|drytj ||j Wqt k r}tt d s|j t j krqqXndS(sCCopy all stat info (mode bits, atime, mtime, flags) from src to dsttutimeR6tchflagstst_flagst EOPNOTSUPPN(R&R0R7R2R%R9tst_atimetst_mtimeR6R:R;R(terrnoR<(R+R,R5R8twhy((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRrscCsTtjj|r6tjj|tjj|}nt||t||dS(sVCopy data and mode bits ("cp src dst"). The destination may be a directory. N(R&R'tisdirtjointbasenameRR(R+R,((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRs$ cCsTtjj|r6tjj|tjj|}nt||t||dS(s]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N(R&R'RARBRCRR(R+R,((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR s$ csfd}|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]}|jtj||q Wt|S(N(textendtfnmatchtfiltertset(R'tnamest ignored_namestpattern(tpatterns(sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyt_ignore_patternss ((RKRL((RKsH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRscCs tj|}|dk r-|||}n t}tj|g}xG|D]?} | |krhqPntjj|| } tjj|| } ytjj| rtj| } |rtj | | q6tjj |  r|rwPn|| | n8tjj | r)t | | |||n || | WqPt k r`} |j| jdqPtk r}|j| | t|fqPXqPWyt||WnMtk r}tdk rt|trq|j||t|fnX|r t |ndS(sRecursively copy a directory tree. 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. If the file pointed by the symlink doesn't exist, an exception will be added in the list of errors raised in an Error exception at the end of the copy process. You can set the optional ignore_dangling_symlinks flag to true if you want to silence this exception. Notice that this has no effect on platforms that don't support os.symlink. 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. The optional copy_function argument is a callable that will be used to copy each file. It will be called with the source path and the destination path as arguments. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. iN(R&tlistdirtNoneRGtmakedirsR'RBtislinktreadlinktsymlinktexistsRAR R RDtargstEnvironmentErrortappendtstrRR(t WindowsErrort isinstance(R+R,tsymlinkstignoret copy_functiontignore_dangling_symlinksRHRIterrorstnametsrcnametdstnametlinktoterrR@((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR sD$     $ cCs|rd}n|dkr*d}ny%tjj|rNtdnWn.tk r|tjj|tjdSXg}ytj|}Wn-tjk r|tj|tjnXx|D]}tjj ||}ytj |j }Wntjk rd}nXt j |r@t|||qytj|Wqtjk r|tj|tjqXqWytj|Wn-tjk r|tj|tjnXdS(sRecursively 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((RT((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pytonerrorscWsdS(N((RT((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRdss%Cannot call rmtree on a symbolic linkNi(RNR&R'RPR(tsystexc_infoRMterrorRBtlstatR2R0tS_ISDIRR tremovetrmdir(R't ignore_errorsRdRHR_tfullnameR8((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR s>       !cCstjj|jtjjS(N(R&R'RCtrstriptsep(R'((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyt _basename'scCs|}tjj|r~t||r;tj||dStjj|t|}tjj|r~td|q~nytj||Wnt k rtjj|rt ||rtd||fnt ||dt t |qt||tj|nXdS(sRecursively 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'.RZ(R&R'RAR-trenameRBRpRSR R(t _destinsrcR tTrueR R tunlink(R+R,treal_dst((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyR ,s$   cCsut|}t|}|jtjjs@|tjj7}n|jtjjsh|tjj7}n|j|S(N(RtendswithR&R'Rot startswith(R+R,((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyRrTs  cCs^tdks|dkrdSyt|}Wntk rEd}nX|dk rZ|dSdS(s"Returns a gid, given a group name.iN(RRNtKeyError(R_tresult((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyt_get_gid]s   cCs^tdks|dkrdSyt|}Wntk rEd}nX|dk rZ|dSdS(s"Returns an uid, given a user name.iN(RRNRx(R_Ry((sH/usr/lib/python2.7/site-packages/pip/_vendor/distlib/_backport/shutil.pyt_get_uidis   tgzipics|idd6dd6}idd6} tr>d|d s                       Q1  ( =/    6     %