Rekd5@sdZddlZddlZddlZddlmZddlZyddlmZWn"e k r~ddl mZYnXddl Z ddl m Z yddlZdZWne k rdZYnXydd lmZWne k rdZYnXydd lmZWne k r)dZYnXd d d ddddddddddddddddddgZGd ddeZGd!ddeZGd"ddeZGd#d$d$eZGd%d&d&eZyeWnek rdZYnXdfd)d Zd*d+Zd,d Z d-d Z!d.dZ"d/dZ#d0dZ$d1dZ%dde$dd2dZ&ddd3dZ'd4d5Z(d6dZ)d7d8Z*d9d:Z+d;d<Z,d=dddddd>d?Z-ddd@dAZ.ddddBdCZ/dDe-dggdFfdGe-dhgdIfdJe-digdKfdLe/gdMfiZ0erue-djgdIfe0dGdS)kzUtility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. N)abspath)Callable)tarfileTF)getpwnam)getgrnam copyfileobjcopyfilecopymodecopystatcopycopy2copytreemovermtreeErrorSpecialFileError ExecError make_archiveget_archive_formatsregister_archive_formatunregister_archive_formatget_unpack_formatsregister_unpack_formatunregister_unpack_formatunpack_archiveignore_patternsc@seZdZdS)rN)__name__ __module__ __qualname__r r /builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/distlib/_backport/shutil.pyr/s c@seZdZdZdS)rz|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)N)rrr__doc__r r r r!r2s c@seZdZdZdS)rz+Raised when a command could not be executedN)rrrr"r r r r!r6s c@seZdZdZdS) ReadErrorz%Raised when an archive cannot be readN)rrrr"r r r r!r#9s r#c@seZdZdZdS) RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsN)rrrr"r r r r!r$<s r$icCs.x'|j|}|sP|j|qWdS)z=copy data from file-like object fsrc to file-like object fdstN)readwrite)fsrcfdstlengthbufr r r!rFs c Cs|ttjdrBytjj||SWntk rAdSYnXtjjtjj|tjjtjj|kS)NsamefileF)hasattrospathr,OSErrornormcaser)srcdstr r r! _samefileNs  r4cCst||r%td||fx^||gD]P}ytj|}Wntk r_Yq2Xtj|jr2td|q2Wt|d-}t|d}t ||WdQRXWdQRXdS)zCopy data from src to dstz`%s` and `%s` are the same filez`%s` is a named piperbwbN) r4rr.statr0S_ISFIFOst_moderopenr)r2r3fnstr(r)r r r!r Zs cCsDttdr@tj|}tj|j}tj||dS)zCopy mode bits from src to dstchmodN)r-r.r7S_IMODEr9r=)r2r3r<moder r r!r nscCstj|}tj|j}ttdrLtj||j|jfttdrktj||ttdrt|drytj ||j WnJt k r}z*tt d s|j t j krWYdd}~XnXdS)zCCopy all stat info (mode bits, atime, mtime, flags) from src to dstutimer=chflagsst_flags EOPNOTSUPPN)r.r7r>r9r-r@st_atimest_mtimer=rArBr0errnorC)r2r3r<r?whyr r r!r uscCsQtjj|r3tjj|tjj|}t||t||dS)zVCopy data and mode bits ("cp src dst"). The destination may be a directory. N)r.r/isdirjoinbasenamer r )r2r3r r r!r s! cCsQtjj|r3tjj|tjj|}t||t||dS)z]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N)r.r/rHrIrJr r )r2r3r r r!r s! csfdd}|S)zFunction 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)extendfnmatchfilterset)r/names ignored_namespattern)patternsr r!_ignore_patternss z)ignore_patterns.._ignore_patternsr )rRrSr )rRr!rscCs:tj|}|dk r-|||}n t}tj|g}xe|D]]} | |kreqPtjj|| } tjj|| } ytjj| rtj| } |rtj| | q0tjj |  r|rwP|| | n8tjj | r#t | | |||n || | WqPt k rl} z|j | jdWYdd} ~ XqPtk r}z!|j| | t|fWYdd}~XqPXqPWyt||Wn_tk r#}z?tdk rt|trn|j ||t|fWYdd}~XnX|r6t |dS)aRecursively 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. Nr)r.listdirrNmakedirsr/rIislinkreadlinksymlinkexistsrHrrrKargsEnvironmentErrorappendstrr r0 WindowsError isinstance)r2r3symlinksignore copy_functionignore_dangling_symlinksrOrPerrorsnamesrcnamedstnamelinktoerrrGr r r!rsD$     &3/c$Cs|rdd}n|dkr-dd}y"tjj|rNtdWn2tk r|tjj|tjdSYnXg}ytj|}Wn.tjk r|tj|tjYnXx|D]}tjj||}ytj |j }Wntjk r#d}YnXt j |rFt |||qytj|Wqtjk r|tj|tjYqXqWytj|Wn.tjk r|tj|tjYnXdS)aRecursively 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)Nr )rZr r r!onerrorszrmtree..onerrorNcWsdS)Nr )rZr r r!rjsz%Cannot call rmtree on a symbolic linkr)r.r/rVr0sysexc_inforTerrorrIlstatr9r7S_ISDIRrremovermdir)r/ ignore_errorsrjrOrefullnamer?r r r!rs>       "cCstjj|jtjjS)N)r.r/rJrstripsep)r/r r r! _basename*srvc Cs|}tjj|rxt||r;tj||dStjj|t|}tjj|rxtd|ytj||Wnt k rtjj|rt ||rtd||ft ||ddt |nt ||tj|YnXdS)aRecursively 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. Nz$Destination path '%s' already existsz.Cannot move a directory '%s' into itself '%s'.r`T)r.r/rHr4renamerIrvrYrr0 _destinsrcrrr unlink)r2r3real_dstr r r!r/s$   cCsot|}t|}|jtjjs=|tjj7}|jtjjsb|tjj7}|j|S)N)rendswithr.r/ru startswith)r2r3r r r!rxWs  rxc Cs_tdks|dkrdSyt|}Wntk rFd}YnX|dk r[|dSdS)z"Returns a gid, given a group name.N)rKeyError)reresultr r r!_get_gid`s   rc Cs_tdks|dkrdSyt|}Wntk rFd}YnX|dk r[|dSdS)z"Returns an uid, given a user name.Nr})rr~)rerr r r!_get_uidls   rgzipc sgddddi}ddi} tr8d|d._set_uid_gidzw|%srM)_BZ2_SUPPORTED ValueErrorformatgetr.r/dirnamerYinforUrrrr:addclose) base_namebase_dircompressverbosedry_runrrloggertar_compression compress_ext archive_name archive_dirrtarr )rrrrr! _make_tarballxs4             rc Cs~|rd}nd}ddlm}ddlm}y |d|||gd|Wn"|k rytd|YnXdS) Nz-rz-rqr)DistutilsExecError)spawnziprzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)distutils.errorsrdistutils.spawnrr)r zip_filenamerr zipoptionsrrr r r!_call_external_zips    rcCs|d}tjj|}tjj|s]|dk rJ|jd||s]tj|yddl}Wntk rd}YnX|dkrt||||n|dk r|jd|||s|j |dd|j }xtj |D]\} } } xm| D]e} tjj tjj | | } tjj| r|j| | |dk r|jd| qWqW|j|S) amCreate 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. z.zipNz creating %srz#creating '%s' and adding '%s' to itw compressionz adding '%s')r.r/rrYrrUzipfile ImportErrorrZipFile ZIP_DEFLATEDwalknormpathrIisfiler'r)rrrrrrrrrdirpathdirnames filenamesrer/r r r! _make_zipfiles8           !  rgztarrzgzip'ed tar-filebztarrzbzip2'ed tar-filerzuncompressed tar filerzZIP filecCs'ddtjD}|j|S)zReturns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) cSs&g|]\}}||dfqS)r}r ).0reregistryr r r! s z'get_archive_formats..)_ARCHIVE_FORMATSitemssort)formatsr r r!rs  rcCs|dkrg}t|ts1td|t|ttfsRtdxB|D]:}t|ttf st|dkrYtdqYW|||ft|.)_UNPACK_FORMATSrr)rr r r!rZs  c Csi}x9tjD]+\}}x|dD]}||| s                     Q1  ( =0     6    %