Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/distlib/_backport/__pycache__/shutil.cpython-36.pyc

3

aj/d-@s
dZddlZddlZddlZddlmZddlZddlZddlZddl	m
Z
yddlZdZWne
k
rtdZYnXyddlmZWne
k
rdZYnXydd	lmZWne
k
rdZYnXd
ddd
dddddddddddddddddgZGdddeZGd ddeZGd!ddeZGd"d#d#eZGd$d%d%eZyeWnek
rjdZYnXded(d
Zd)d*Zd+dZd,dZd-d
Z d.dZ!d/dZ"d0dZ#dde"dfd1dZ$dfd2dZ%d3d4Z&d5dZ'd6d7Z(d8d9Z)d:d;Z*dgd=d>Z+dhd?d@Z,didAdBZ-e+djgdDfe+dkgdFfe+dlgdGfe-gdHfdIZ.erRe+dmgdFfe.dJ<dKdZ/dndMdZ0dNdZ1dodOdZ2dPdZ3dQdRZ4dpdSdZ5dTdZ6dUdVZ7dWdXZ8dYdZZ9d[d\ge9gdDfd]ge9gdGfd^ge8gdHfd_Z:erd`ge9gdFfe:dJ<dadbZ;dqdcdZ<dS)rzUtility 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)tarfileTF)getpwnam)getgrnamcopyfileobjcopyfilecopymodecopystatcopycopy2copytreemovermtreeErrorSpecialFileError	ExecErrormake_archiveget_archive_formatsregister_archive_formatunregister_archive_formatget_unpack_formatsregister_unpack_formatunregister_unpack_formatunpack_archiveignore_patternsc@seZdZdS)rN)__name__
__module____qualname__rr/usr/lib/python3.6/shutil.pyr,sc@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__rrrr r/sc@seZdZdZdS)rz+Raised when a command could not be executedN)rrrr!rrrr r3sc@seZdZdZdS)	ReadErrorz%Raised when an archive cannot be readN)rrrr!rrrr r"6sr"c@seZdZdZdS)
RegistryErrorzVRaised when a registry operation with the archiving
    and unpacking registries failsN)rrrr!rrrr r#9sr#icCs$x|j|}|sP|j|qWdS)z=copy data from file-like object fsrc to file-like object fdstN)readwrite)fsrcfdstZlengthZbufrrr rCs

cCsXttjdr0ytjj||Stk
r.dSXtjjtjj|tjjtjj|kS)NsamefileF)hasattrospathr)OSErrornormcaser)srcdstrrr 	_samefileKsr1cCst||rtd||fxL||gD]@}ytj|}Wntk
rJYq$Xtj|jr$td|q$Wt|d&}t|d}t	||WdQRXWdQRXdS)zCopy data from src to dstz`%s` and `%s` are the same filez`%s` is a named piperbwbN)
r1rr+statr-S_ISFIFOst_moderopenr)r/r0fnstr'r(rrr rWs
cCs0ttdr,tj|}tj|j}tj||dS)zCopy mode bits from src to dstchmodN)r*r+r4S_IMODEr6r:)r/r0r9moderrr r	ks

cCstj|}tj|j}ttdr4tj||j|jfttdrJtj||ttdrt|drytj	||j
Wn<tk
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+r4r;r6r*r=st_atimest_mtimer:r>r?r-errnor@)r/r0r9r<whyrrr r
rs


cCs:tjj|r"tjj|tjj|}t||t||dS)zVCopy data and mode bits ("cp src dst").

    The destination may be a directory.

    N)r+r,isdirjoinbasenamerr	)r/r0rrr rs
cCs:tjj|r"tjj|tjj|}t||t||dS)z]Copy data and all stat info ("cp -p src dst").

    The destination may be a directory.

    N)r+r,rErFrGrr
)r/r0rrr 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}xD]}|jtj||q
Wt|S)N)extendfnmatchfilterset)r,names
ignored_namespattern)patternsrr _ignore_patternss
z)ignore_patterns.<locals>._ignore_patternsr)rOrPr)rOr rscCstj|}|dk	r|||}nt}tj|g}x|D]
}	|	|krJq:tjj||	}
tjj||	}yttjj|
rtj|
}|rtj||qtjj	|r|rw:||
|n(tjj
|
rt|
||||n
||
|Wq:tk
r}
z|j
|
jdWYdd}
~
Xq:tk
rD}z|j|
|t|fWYdd}~Xq:Xq:Wyt||WnPtk
r}z2tdk	rt|trn|j
||t|fWYdd}~XnX|rt|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+listdirrKmakedirsr,rFislinkreadlinksymlinkexistsrEr
rrHargsEnvironmentErrorappendstrr
r-WindowsError
isinstance)r/r0symlinksignoreZ
copy_functionZignore_dangling_symlinksrLrMerrorsnameZsrcnameZdstnameZlinktoerrrDrrr r
sD$


 *&c$Cst|rdd}n|dkrdd}ytjj|r4tdWn(tk
r^|tjj|tjdSXg}ytj|}Wn(tjk
r|tj|tjYnXx|D]}tjj||}ytj	|j
}Wntjk
rd}YnXtj|rt
|||qytj|Wqtjk
r0|tj|tjYqXqWytj|Wn*tjk
rn|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)rWrrr onerrorszrmtree.<locals>.onerrorNcWsdS)Nr)rWrrr rbsz%Cannot call rmtree on a symbolic linkr)r+r,rSr-sysexc_inforQerrorrFlstatr6r4S_ISDIRrremovermdir)r,
ignore_errorsrbrLr`fullnamer<rrr rs>



cCstjj|jtjjS)N)r+r,rGrstripsep)r,rrr 	_basename'srncCs|}tjj|rTt||r*tj||dStjj|t|}tjj|rTtd|ytj||Wnft	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'.T)r])r+r,rEr1renamerFrnrVrr-
_destinsrcr
rrunlink)r/r0Zreal_dstrrr r,s$



cCsNt|}t|}|jtjjs*|tjj7}|jtjjsD|tjj7}|j|S)N)rendswithr+r,rm
startswith)r/r0rrr rpTsrpcCsNtdks|dkrdSyt|}Wntk
r8d}YnX|dk	rJ|dSdS)z"Returns a gid, given a group name.N)rKeyError)r`resultrrr _get_gid]s
rwcCsNtdks|dkrdSyt|}Wntk
r8d}YnX|dk	rJ|dSdS)z"Returns an uid, given a user name.Nrt)rru)r`rvrrr _get_uidis
rxgzipc
sddd}ddi}	tr&d|d<d|	d<|d	k	rD||	krDtd
j||d|	j|d}
tjj|
}tjj|s|d	k	r|jd||stj	||d	k	r|jd
t
tfdd}|stj
|
d||}
z|
j||dWd	|
jX|
S)aCreate 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.
    Zgz)ryNryz.gzbz2bzip2z.bz2NzCbad value for 'compress', or compression format not supported : {0}z.tarzcreating %szCreating tar archivecs,dk	r|_|_dk	r(|_|_|S)N)gidZgnameuiduname)Ztarinfo)r}groupownerr~rr _set_uid_gidsz#_make_tarball.<locals>._set_uid_gidzw|%s)rJ)_BZ2_SUPPORTED
ValueErrorformatgetr+r,dirnamerVinforRrxrwrr7addclose)	base_namebase_dircompressverbosedry_runrrloggerZtar_compressionZcompress_extZarchive_namearchive_dirrtarr)r}rrr~r 
_make_tarballus4


	
rcCsd|r
d}nd}ddlm}ddlm}y|d|||g|dWn |k
r^td|YnXdS)	Nz-rz-rqr)DistutilsExecError)spawnzip)rzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)Zdistutils.errorsrZdistutils.spawnrr)rzip_filenamerrZ
zipoptionsrrrrr _call_external_zipsrcCs$|d}tjj|}tjj|sB|dk	r4|jd||sBtj|yddl}Wntk
rfd}YnX|dkrt||||n|dk	r|jd|||s |j	|d|j
d}xhtj|D]Z\}	}
}xN|D]F}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.zipNzcreating %srz#creating '%s' and adding '%s' to itw)Zcompressionzadding '%s')r+r,rrVrrRzipfileImportErrorrZipFileZZIP_DEFLATEDwalknormpathrFisfiler&r)rrrrrrrrrdirpathZdirnames	filenamesr`r,rrr 
_make_zipfiles8	



rrzgzip'ed tar-filer|zbzip2'ed tar-filezuncompressed tar filezZIP file)gztarbztarrrrcCsddtjD}|j|S)zReturns a list of supported formats for archiving and unarchiving.

    Each element of the returned sequence is a tuple (name, description)
    cSsg|]\}}||dfqS)rtr).0r`registryrrr 
<listcomp>sz'get_archive_formats.<locals>.<listcomp>)_ARCHIVE_FORMATSitemssort)formatsrrr rsrzcCs~|dkrg}t|tjs$td|t|ttfs:tdx0|D](}t|ttfs`t|dkr@tdq@W|||ft|<dS)auRegisters an archive format.

    name is the name of the format. function is the callable that will be
    used to create archives. If provided, extra_args is a sequence of
    (name, value) tuples that will be passed as arguments to the callable.
    description can be provided to describe the format, and will be returned
    by the get_archive_formats() function.
    NzThe %s object is not callablez!extra_args needs to be a sequencertz+extra_args elements are : (arg_name, value))r\collectionsCallable	TypeErrortuplelistlenr)r`function
extra_argsdescriptionelementrrr rs	
cCs
t|=dS)N)r)r`rrr rsc	Cstj}	|dk	r>|dk	r$|jd|tjj|}|s>tj||dkrLtj}||d}
yt|}Wn tk
rt	d|YnX|d}x|dD]\}
}||
|
<qW|dkr||
d<||
d	<z|||f|
}Wd|dk	r|dk	r|jd
|	tj|	X|S)aCreate an archive file (eg. zip or tar).

    'base_name' is the name of the file to create, minus any format-specific
    extension; 'format' is the archive format: one of "zip", "tar", "bztar"
    or "gztar".

    'root_dir' is a directory that will be the root directory of the
    archive; ie. we typically chdir into 'root_dir' before creating the
    archive.  'base_dir' is the directory where we start archiving from;
    ie. 'base_dir' will be the common prefix of all files and
    directories in the archive.  'root_dir' and 'base_dir' both default
    to the current directory.  Returns the name of the archive file.

    'owner' and 'group' are used when creating a tar archive. By default,
    uses the current owner and group.
    Nzchanging into '%s')rrzunknown archive format '%s'rrrrrzchanging back to '%s')
r+getcwddebugr,rchdircurdirrrur)rrZroot_dirrrrrrrZsave_cwdkwargsformat_infofuncargvalfilenamerrr r s6

cCsddtjD}|j|S)zReturns a list of supported formats for unpacking.

    Each element of the returned sequence is a tuple
    (name, extensions, description)
    cSs"g|]\}}||d|dfqS)rr)rr`rrrr r]sz&get_unpack_formats.<locals>.<listcomp>)_UNPACK_FORMATSrr)rrrr rWsc	Cszi}x.tjD]"\}}x|dD]}|||<q WqWx,|D]$}||kr:d}t||||fq:Wt|tjsvtddS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)rrr#r\rrr)	
extensionsrrZexisting_extensionsr`rZext	extensionmsgrrr _check_unpack_optionsbs
rcCs,|dkrg}t|||||||ft|<dS)aMRegisters an unpack format.

    `name` is the name of the format. `extensions` is a list of extensions
    corresponding to the format.

    `function` is the callable that will be
    used to unpack archives. The callable will receive archives to unpack.
    If it's unable to handle an archive, it needs to raise a ReadError
    exception.

    If provided, `extra_args` is a sequence of
    (name, value) tuples that will be passed as arguments to the callable.
    description can be provided to describe the format, and will be returned
    by the get_unpack_formats() function.
    N)rr)r`rrrrrrr rtscCs
t|=dS)z*Removes the pack format from the registry.N)r)r`rrr rscCs&tjj|}tjj|s"tj|dS)z1Ensure that the parent directory of `path` existsN)r+r,rrErR)r,rrrr _ensure_directorysrc	Csyddl}Wntk
r(tdYnX|j|s@td||j|}zx|jD]}|j}|jdsVd|krtqVtj	j
|f|jd}|sqVt||j
dsV|j|j}t|d}z|j|Wd|j~XqVWWd|jXdS)z+Unpack zip `filename` to `extract_dir`
    rNz/zlib not supported, cannot unpack this archive.z%s is not a zip file/z..r3)rrr"Z
is_zipfilerZinfolistrrsr+r,rFsplitrrrr%r7r&r)	rextract_dirrrrr`targetdatafrrr _unpack_zipfiles0



rcCsPytj|}Wn"tjk
r0td|YnXz|j|Wd|jXdS)z:Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
    z/%s is not a compressed or uncompressed tar fileN)rr7ZTarErrorr"Z
extractallr)rrZtarobjrrr _unpack_tarfilesrz.tar.gzz.tgzz.tarz.zip)rrrz.bz2cCs:x4tjD](\}}x|dD]}|j|r|SqWq
WdS)Nr)rrrr)rr`rrrrr _find_unpack_formats

rc
Cs|dkrtj}|dk	rhyt|}Wn"tk
rFtdj|YnX|d}|||ft|dnHt|}|dkrtdj|t|d}tt|d}|||f|dS)aUnpack an archive.

    `filename` is the name of the archive.

    `extract_dir` is the name of the target directory, where the archive
    is unpacked. If not provided, the current working directory is used.

    `format` is the archive format: one of "zip", "tar", or "gztar". Or any
    other registered format. If not provided, unpack_archive will use the
    filename extension and see if an unpacker was registered for that
    extension.

    In case none is found, a ValueError is raised.
    NzUnknown unpack format '{0}'rrtzUnknown archive format '{0}')	r+rrrurrdictrr")rrrrrrrrr rs@)r)FN)ryrrNNN)FF)rrN)rry)rr|)rN)rr|)Nrz)NNrrNNN)Nrz)NN)=r!r+rcr4Zos.pathrrIrrCrzrr{rrpwdrZgrpr__all__rXrrrr"	Exceptionr#r[	NameErrorrr1rr	r
rrrr
rrnrrprwrxrrrrrrrrrrrrrrrrrrrrrr <module>
s






Q
1(	
=

0






6
%

Back to Directory File Manager