Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python2....
File: shutil.py
"""Utility functions for copying and archiving files and directory trees.
[0] Fix | Delete
[1] Fix | Delete
XXX The functions here don't copy the resource fork or other metadata on Mac.
[2] Fix | Delete
[3] Fix | Delete
"""
[4] Fix | Delete
[5] Fix | Delete
import os
[6] Fix | Delete
import sys
[7] Fix | Delete
import stat
[8] Fix | Delete
from os.path import abspath
[9] Fix | Delete
import fnmatch
[10] Fix | Delete
import collections
[11] Fix | Delete
import errno
[12] Fix | Delete
[13] Fix | Delete
try:
[14] Fix | Delete
from pwd import getpwnam
[15] Fix | Delete
except ImportError:
[16] Fix | Delete
getpwnam = None
[17] Fix | Delete
[18] Fix | Delete
try:
[19] Fix | Delete
from grp import getgrnam
[20] Fix | Delete
except ImportError:
[21] Fix | Delete
getgrnam = None
[22] Fix | Delete
[23] Fix | Delete
__all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
[24] Fix | Delete
"copytree", "move", "rmtree", "Error", "SpecialFileError",
[25] Fix | Delete
"ExecError", "make_archive", "get_archive_formats",
[26] Fix | Delete
"register_archive_format", "unregister_archive_format",
[27] Fix | Delete
"ignore_patterns"]
[28] Fix | Delete
[29] Fix | Delete
class Error(EnvironmentError):
[30] Fix | Delete
pass
[31] Fix | Delete
[32] Fix | Delete
class SpecialFileError(EnvironmentError):
[33] Fix | Delete
"""Raised when trying to do a kind of operation (e.g. copying) which is
[34] Fix | Delete
not supported on a special file (e.g. a named pipe)"""
[35] Fix | Delete
[36] Fix | Delete
class ExecError(EnvironmentError):
[37] Fix | Delete
"""Raised when a command could not be executed"""
[38] Fix | Delete
[39] Fix | Delete
try:
[40] Fix | Delete
WindowsError
[41] Fix | Delete
except NameError:
[42] Fix | Delete
WindowsError = None
[43] Fix | Delete
[44] Fix | Delete
def copyfileobj(fsrc, fdst, length=16*1024):
[45] Fix | Delete
"""copy data from file-like object fsrc to file-like object fdst"""
[46] Fix | Delete
while 1:
[47] Fix | Delete
buf = fsrc.read(length)
[48] Fix | Delete
if not buf:
[49] Fix | Delete
break
[50] Fix | Delete
fdst.write(buf)
[51] Fix | Delete
[52] Fix | Delete
def _samefile(src, dst):
[53] Fix | Delete
# Macintosh, Unix.
[54] Fix | Delete
if hasattr(os.path, 'samefile'):
[55] Fix | Delete
try:
[56] Fix | Delete
return os.path.samefile(src, dst)
[57] Fix | Delete
except OSError:
[58] Fix | Delete
return False
[59] Fix | Delete
[60] Fix | Delete
# All other platforms: check for same pathname.
[61] Fix | Delete
return (os.path.normcase(os.path.abspath(src)) ==
[62] Fix | Delete
os.path.normcase(os.path.abspath(dst)))
[63] Fix | Delete
[64] Fix | Delete
def copyfile(src, dst):
[65] Fix | Delete
"""Copy data from src to dst"""
[66] Fix | Delete
if _samefile(src, dst):
[67] Fix | Delete
raise Error("`%s` and `%s` are the same file" % (src, dst))
[68] Fix | Delete
[69] Fix | Delete
for fn in [src, dst]:
[70] Fix | Delete
try:
[71] Fix | Delete
st = os.stat(fn)
[72] Fix | Delete
except OSError:
[73] Fix | Delete
# File most likely does not exist
[74] Fix | Delete
pass
[75] Fix | Delete
else:
[76] Fix | Delete
# XXX What about other special files? (sockets, devices...)
[77] Fix | Delete
if stat.S_ISFIFO(st.st_mode):
[78] Fix | Delete
raise SpecialFileError("`%s` is a named pipe" % fn)
[79] Fix | Delete
[80] Fix | Delete
with open(src, 'rb') as fsrc:
[81] Fix | Delete
with open(dst, 'wb') as fdst:
[82] Fix | Delete
copyfileobj(fsrc, fdst)
[83] Fix | Delete
[84] Fix | Delete
def copymode(src, dst):
[85] Fix | Delete
"""Copy mode bits from src to dst"""
[86] Fix | Delete
if hasattr(os, 'chmod'):
[87] Fix | Delete
st = os.stat(src)
[88] Fix | Delete
mode = stat.S_IMODE(st.st_mode)
[89] Fix | Delete
os.chmod(dst, mode)
[90] Fix | Delete
[91] Fix | Delete
def copystat(src, dst):
[92] Fix | Delete
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst"""
[93] Fix | Delete
st = os.stat(src)
[94] Fix | Delete
mode = stat.S_IMODE(st.st_mode)
[95] Fix | Delete
if hasattr(os, 'utime'):
[96] Fix | Delete
os.utime(dst, (st.st_atime, st.st_mtime))
[97] Fix | Delete
if hasattr(os, 'chmod'):
[98] Fix | Delete
os.chmod(dst, mode)
[99] Fix | Delete
if hasattr(os, 'chflags') and hasattr(st, 'st_flags'):
[100] Fix | Delete
try:
[101] Fix | Delete
os.chflags(dst, st.st_flags)
[102] Fix | Delete
except OSError, why:
[103] Fix | Delete
for err in 'EOPNOTSUPP', 'ENOTSUP':
[104] Fix | Delete
if hasattr(errno, err) and why.errno == getattr(errno, err):
[105] Fix | Delete
break
[106] Fix | Delete
else:
[107] Fix | Delete
raise
[108] Fix | Delete
[109] Fix | Delete
def copy(src, dst):
[110] Fix | Delete
"""Copy data and mode bits ("cp src dst").
[111] Fix | Delete
[112] Fix | Delete
The destination may be a directory.
[113] Fix | Delete
[114] Fix | Delete
"""
[115] Fix | Delete
if os.path.isdir(dst):
[116] Fix | Delete
dst = os.path.join(dst, os.path.basename(src))
[117] Fix | Delete
copyfile(src, dst)
[118] Fix | Delete
copymode(src, dst)
[119] Fix | Delete
[120] Fix | Delete
def copy2(src, dst):
[121] Fix | Delete
"""Copy data and all stat info ("cp -p src dst").
[122] Fix | Delete
[123] Fix | Delete
The destination may be a directory.
[124] Fix | Delete
[125] Fix | Delete
"""
[126] Fix | Delete
if os.path.isdir(dst):
[127] Fix | Delete
dst = os.path.join(dst, os.path.basename(src))
[128] Fix | Delete
copyfile(src, dst)
[129] Fix | Delete
copystat(src, dst)
[130] Fix | Delete
[131] Fix | Delete
def ignore_patterns(*patterns):
[132] Fix | Delete
"""Function that can be used as copytree() ignore parameter.
[133] Fix | Delete
[134] Fix | Delete
Patterns is a sequence of glob-style patterns
[135] Fix | Delete
that are used to exclude files"""
[136] Fix | Delete
def _ignore_patterns(path, names):
[137] Fix | Delete
ignored_names = []
[138] Fix | Delete
for pattern in patterns:
[139] Fix | Delete
ignored_names.extend(fnmatch.filter(names, pattern))
[140] Fix | Delete
return set(ignored_names)
[141] Fix | Delete
return _ignore_patterns
[142] Fix | Delete
[143] Fix | Delete
def copytree(src, dst, symlinks=False, ignore=None):
[144] Fix | Delete
"""Recursively copy a directory tree using copy2().
[145] Fix | Delete
[146] Fix | Delete
The destination directory must not already exist.
[147] Fix | Delete
If exception(s) occur, an Error is raised with a list of reasons.
[148] Fix | Delete
[149] Fix | Delete
If the optional symlinks flag is true, symbolic links in the
[150] Fix | Delete
source tree result in symbolic links in the destination tree; if
[151] Fix | Delete
it is false, the contents of the files pointed to by symbolic
[152] Fix | Delete
links are copied.
[153] Fix | Delete
[154] Fix | Delete
The optional ignore argument is a callable. If given, it
[155] Fix | Delete
is called with the `src` parameter, which is the directory
[156] Fix | Delete
being visited by copytree(), and `names` which is the list of
[157] Fix | Delete
`src` contents, as returned by os.listdir():
[158] Fix | Delete
[159] Fix | Delete
callable(src, names) -> ignored_names
[160] Fix | Delete
[161] Fix | Delete
Since copytree() is called recursively, the callable will be
[162] Fix | Delete
called once for each directory that is copied. It returns a
[163] Fix | Delete
list of names relative to the `src` directory that should
[164] Fix | Delete
not be copied.
[165] Fix | Delete
[166] Fix | Delete
XXX Consider this example code rather than the ultimate tool.
[167] Fix | Delete
[168] Fix | Delete
"""
[169] Fix | Delete
names = os.listdir(src)
[170] Fix | Delete
if ignore is not None:
[171] Fix | Delete
ignored_names = ignore(src, names)
[172] Fix | Delete
else:
[173] Fix | Delete
ignored_names = set()
[174] Fix | Delete
[175] Fix | Delete
os.makedirs(dst)
[176] Fix | Delete
errors = []
[177] Fix | Delete
for name in names:
[178] Fix | Delete
if name in ignored_names:
[179] Fix | Delete
continue
[180] Fix | Delete
srcname = os.path.join(src, name)
[181] Fix | Delete
dstname = os.path.join(dst, name)
[182] Fix | Delete
try:
[183] Fix | Delete
if symlinks and os.path.islink(srcname):
[184] Fix | Delete
linkto = os.readlink(srcname)
[185] Fix | Delete
os.symlink(linkto, dstname)
[186] Fix | Delete
elif os.path.isdir(srcname):
[187] Fix | Delete
copytree(srcname, dstname, symlinks, ignore)
[188] Fix | Delete
else:
[189] Fix | Delete
# Will raise a SpecialFileError for unsupported file types
[190] Fix | Delete
copy2(srcname, dstname)
[191] Fix | Delete
# catch the Error from the recursive copytree so that we can
[192] Fix | Delete
# continue with other files
[193] Fix | Delete
except Error, err:
[194] Fix | Delete
errors.extend(err.args[0])
[195] Fix | Delete
except EnvironmentError, why:
[196] Fix | Delete
errors.append((srcname, dstname, str(why)))
[197] Fix | Delete
try:
[198] Fix | Delete
copystat(src, dst)
[199] Fix | Delete
except OSError, why:
[200] Fix | Delete
if WindowsError is not None and isinstance(why, WindowsError):
[201] Fix | Delete
# Copying file access times may fail on Windows
[202] Fix | Delete
pass
[203] Fix | Delete
else:
[204] Fix | Delete
errors.append((src, dst, str(why)))
[205] Fix | Delete
if errors:
[206] Fix | Delete
raise Error, errors
[207] Fix | Delete
[208] Fix | Delete
def rmtree(path, ignore_errors=False, onerror=None):
[209] Fix | Delete
"""Recursively delete a directory tree.
[210] Fix | Delete
[211] Fix | Delete
If ignore_errors is set, errors are ignored; otherwise, if onerror
[212] Fix | Delete
is set, it is called to handle the error with arguments (func,
[213] Fix | Delete
path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
[214] Fix | Delete
path is the argument to that function that caused it to fail; and
[215] Fix | Delete
exc_info is a tuple returned by sys.exc_info(). If ignore_errors
[216] Fix | Delete
is false and onerror is None, an exception is raised.
[217] Fix | Delete
[218] Fix | Delete
"""
[219] Fix | Delete
if ignore_errors:
[220] Fix | Delete
def onerror(*args):
[221] Fix | Delete
pass
[222] Fix | Delete
elif onerror is None:
[223] Fix | Delete
def onerror(*args):
[224] Fix | Delete
raise
[225] Fix | Delete
try:
[226] Fix | Delete
if os.path.islink(path):
[227] Fix | Delete
# symlinks to directories are forbidden, see bug #1669
[228] Fix | Delete
raise OSError("Cannot call rmtree on a symbolic link")
[229] Fix | Delete
except OSError:
[230] Fix | Delete
onerror(os.path.islink, path, sys.exc_info())
[231] Fix | Delete
# can't continue even if onerror hook returns
[232] Fix | Delete
return
[233] Fix | Delete
names = []
[234] Fix | Delete
try:
[235] Fix | Delete
names = os.listdir(path)
[236] Fix | Delete
except os.error, err:
[237] Fix | Delete
onerror(os.listdir, path, sys.exc_info())
[238] Fix | Delete
for name in names:
[239] Fix | Delete
fullname = os.path.join(path, name)
[240] Fix | Delete
try:
[241] Fix | Delete
mode = os.lstat(fullname).st_mode
[242] Fix | Delete
except os.error:
[243] Fix | Delete
mode = 0
[244] Fix | Delete
if stat.S_ISDIR(mode):
[245] Fix | Delete
rmtree(fullname, ignore_errors, onerror)
[246] Fix | Delete
else:
[247] Fix | Delete
try:
[248] Fix | Delete
os.remove(fullname)
[249] Fix | Delete
except os.error, err:
[250] Fix | Delete
onerror(os.remove, fullname, sys.exc_info())
[251] Fix | Delete
try:
[252] Fix | Delete
os.rmdir(path)
[253] Fix | Delete
except os.error:
[254] Fix | Delete
onerror(os.rmdir, path, sys.exc_info())
[255] Fix | Delete
[256] Fix | Delete
[257] Fix | Delete
def _basename(path):
[258] Fix | Delete
# A basename() variant which first strips the trailing slash, if present.
[259] Fix | Delete
# Thus we always get the last component of the path, even for directories.
[260] Fix | Delete
sep = os.path.sep + (os.path.altsep or '')
[261] Fix | Delete
return os.path.basename(path.rstrip(sep))
[262] Fix | Delete
[263] Fix | Delete
def move(src, dst):
[264] Fix | Delete
"""Recursively move a file or directory to another location. This is
[265] Fix | Delete
similar to the Unix "mv" command.
[266] Fix | Delete
[267] Fix | Delete
If the destination is a directory or a symlink to a directory, the source
[268] Fix | Delete
is moved inside the directory. The destination path must not already
[269] Fix | Delete
exist.
[270] Fix | Delete
[271] Fix | Delete
If the destination already exists but is not a directory, it may be
[272] Fix | Delete
overwritten depending on os.rename() semantics.
[273] Fix | Delete
[274] Fix | Delete
If the destination is on our current filesystem, then rename() is used.
[275] Fix | Delete
Otherwise, src is copied to the destination and then removed.
[276] Fix | Delete
A lot more could be done here... A look at a mv.c shows a lot of
[277] Fix | Delete
the issues this implementation glosses over.
[278] Fix | Delete
[279] Fix | Delete
"""
[280] Fix | Delete
real_dst = dst
[281] Fix | Delete
if os.path.isdir(dst):
[282] Fix | Delete
if _samefile(src, dst):
[283] Fix | Delete
# We might be on a case insensitive filesystem,
[284] Fix | Delete
# perform the rename anyway.
[285] Fix | Delete
os.rename(src, dst)
[286] Fix | Delete
return
[287] Fix | Delete
[288] Fix | Delete
real_dst = os.path.join(dst, _basename(src))
[289] Fix | Delete
if os.path.exists(real_dst):
[290] Fix | Delete
raise Error, "Destination path '%s' already exists" % real_dst
[291] Fix | Delete
try:
[292] Fix | Delete
os.rename(src, real_dst)
[293] Fix | Delete
except OSError:
[294] Fix | Delete
if os.path.isdir(src):
[295] Fix | Delete
if _destinsrc(src, dst):
[296] Fix | Delete
raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
[297] Fix | Delete
copytree(src, real_dst, symlinks=True)
[298] Fix | Delete
rmtree(src)
[299] Fix | Delete
else:
[300] Fix | Delete
copy2(src, real_dst)
[301] Fix | Delete
os.unlink(src)
[302] Fix | Delete
[303] Fix | Delete
def _destinsrc(src, dst):
[304] Fix | Delete
src = abspath(src)
[305] Fix | Delete
dst = abspath(dst)
[306] Fix | Delete
if not src.endswith(os.path.sep):
[307] Fix | Delete
src += os.path.sep
[308] Fix | Delete
if not dst.endswith(os.path.sep):
[309] Fix | Delete
dst += os.path.sep
[310] Fix | Delete
return dst.startswith(src)
[311] Fix | Delete
[312] Fix | Delete
def _get_gid(name):
[313] Fix | Delete
"""Returns a gid, given a group name."""
[314] Fix | Delete
if getgrnam is None or name is None:
[315] Fix | Delete
return None
[316] Fix | Delete
try:
[317] Fix | Delete
result = getgrnam(name)
[318] Fix | Delete
except KeyError:
[319] Fix | Delete
result = None
[320] Fix | Delete
if result is not None:
[321] Fix | Delete
return result[2]
[322] Fix | Delete
return None
[323] Fix | Delete
[324] Fix | Delete
def _get_uid(name):
[325] Fix | Delete
"""Returns an uid, given a user name."""
[326] Fix | Delete
if getpwnam is None or name is None:
[327] Fix | Delete
return None
[328] Fix | Delete
try:
[329] Fix | Delete
result = getpwnam(name)
[330] Fix | Delete
except KeyError:
[331] Fix | Delete
result = None
[332] Fix | Delete
if result is not None:
[333] Fix | Delete
return result[2]
[334] Fix | Delete
return None
[335] Fix | Delete
[336] Fix | Delete
def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
[337] Fix | Delete
owner=None, group=None, logger=None):
[338] Fix | Delete
"""Create a (possibly compressed) tar file from all the files under
[339] Fix | Delete
'base_dir'.
[340] Fix | Delete
[341] Fix | Delete
'compress' must be "gzip" (the default), "bzip2", or None.
[342] Fix | Delete
[343] Fix | Delete
'owner' and 'group' can be used to define an owner and a group for the
[344] Fix | Delete
archive that is being built. If not provided, the current owner and group
[345] Fix | Delete
will be used.
[346] Fix | Delete
[347] Fix | Delete
The output tar file will be named 'base_name' + ".tar", possibly plus
[348] Fix | Delete
the appropriate compression extension (".gz", or ".bz2").
[349] Fix | Delete
[350] Fix | Delete
Returns the output filename.
[351] Fix | Delete
"""
[352] Fix | Delete
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: ''}
[353] Fix | Delete
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2'}
[354] Fix | Delete
[355] Fix | Delete
# flags for compression program, each element of list will be an argument
[356] Fix | Delete
if compress is not None and compress not in compress_ext.keys():
[357] Fix | Delete
raise ValueError, \
[358] Fix | Delete
("bad value for 'compress': must be None, 'gzip' or 'bzip2'")
[359] Fix | Delete
[360] Fix | Delete
archive_name = base_name + '.tar' + compress_ext.get(compress, '')
[361] Fix | Delete
archive_dir = os.path.dirname(archive_name)
[362] Fix | Delete
[363] Fix | Delete
if archive_dir and not os.path.exists(archive_dir):
[364] Fix | Delete
if logger is not None:
[365] Fix | Delete
logger.info("creating %s", archive_dir)
[366] Fix | Delete
if not dry_run:
[367] Fix | Delete
os.makedirs(archive_dir)
[368] Fix | Delete
[369] Fix | Delete
[370] Fix | Delete
# creating the tarball
[371] Fix | Delete
import tarfile # late import so Python build itself doesn't break
[372] Fix | Delete
[373] Fix | Delete
if logger is not None:
[374] Fix | Delete
logger.info('Creating tar archive')
[375] Fix | Delete
[376] Fix | Delete
uid = _get_uid(owner)
[377] Fix | Delete
gid = _get_gid(group)
[378] Fix | Delete
[379] Fix | Delete
def _set_uid_gid(tarinfo):
[380] Fix | Delete
if gid is not None:
[381] Fix | Delete
tarinfo.gid = gid
[382] Fix | Delete
tarinfo.gname = group
[383] Fix | Delete
if uid is not None:
[384] Fix | Delete
tarinfo.uid = uid
[385] Fix | Delete
tarinfo.uname = owner
[386] Fix | Delete
return tarinfo
[387] Fix | Delete
[388] Fix | Delete
if not dry_run:
[389] Fix | Delete
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
[390] Fix | Delete
try:
[391] Fix | Delete
tar.add(base_dir, filter=_set_uid_gid)
[392] Fix | Delete
finally:
[393] Fix | Delete
tar.close()
[394] Fix | Delete
[395] Fix | Delete
return archive_name
[396] Fix | Delete
[397] Fix | Delete
def _call_external_zip(base_dir, zip_filename, verbose=False, dry_run=False):
[398] Fix | Delete
# XXX see if we want to keep an external call here
[399] Fix | Delete
if verbose:
[400] Fix | Delete
zipoptions = "-r"
[401] Fix | Delete
else:
[402] Fix | Delete
zipoptions = "-rq"
[403] Fix | Delete
from distutils.errors import DistutilsExecError
[404] Fix | Delete
from distutils.spawn import spawn
[405] Fix | Delete
try:
[406] Fix | Delete
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
[407] Fix | Delete
except DistutilsExecError:
[408] Fix | Delete
# XXX really should distinguish between "couldn't find
[409] Fix | Delete
# external 'zip' command" and "zip failed".
[410] Fix | Delete
raise ExecError, \
[411] Fix | Delete
("unable to create zip file '%s': "
[412] Fix | Delete
"could neither import the 'zipfile' module nor "
[413] Fix | Delete
"find a standalone zip utility") % zip_filename
[414] Fix | Delete
[415] Fix | Delete
def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
[416] Fix | Delete
"""Create a zip file from all the files under 'base_dir'.
[417] Fix | Delete
[418] Fix | Delete
The output zip file will be named 'base_name' + ".zip". Uses either the
[419] Fix | Delete
"zipfile" Python module (if available) or the InfoZIP "zip" utility
[420] Fix | Delete
(if installed and found on the default search path). If neither tool is
[421] Fix | Delete
available, raises ExecError. Returns the name of the output zip
[422] Fix | Delete
file.
[423] Fix | Delete
"""
[424] Fix | Delete
zip_filename = base_name + ".zip"
[425] Fix | Delete
archive_dir = os.path.dirname(base_name)
[426] Fix | Delete
[427] Fix | Delete
if archive_dir and not os.path.exists(archive_dir):
[428] Fix | Delete
if logger is not None:
[429] Fix | Delete
logger.info("creating %s", archive_dir)
[430] Fix | Delete
if not dry_run:
[431] Fix | Delete
os.makedirs(archive_dir)
[432] Fix | Delete
[433] Fix | Delete
# If zipfile module is not available, try spawning an external 'zip'
[434] Fix | Delete
# command.
[435] Fix | Delete
try:
[436] Fix | Delete
import zipfile
[437] Fix | Delete
except ImportError:
[438] Fix | Delete
zipfile = None
[439] Fix | Delete
[440] Fix | Delete
if zipfile is None:
[441] Fix | Delete
_call_external_zip(base_dir, zip_filename, verbose, dry_run)
[442] Fix | Delete
else:
[443] Fix | Delete
if logger is not None:
[444] Fix | Delete
logger.info("creating '%s' and adding '%s' to it",
[445] Fix | Delete
zip_filename, base_dir)
[446] Fix | Delete
[447] Fix | Delete
if not dry_run:
[448] Fix | Delete
with zipfile.ZipFile(zip_filename, "w",
[449] Fix | Delete
compression=zipfile.ZIP_DEFLATED) as zf:
[450] Fix | Delete
path = os.path.normpath(base_dir)
[451] Fix | Delete
zf.write(path, path)
[452] Fix | Delete
if logger is not None:
[453] Fix | Delete
logger.info("adding '%s'", path)
[454] Fix | Delete
for dirpath, dirnames, filenames in os.walk(base_dir):
[455] Fix | Delete
for name in sorted(dirnames):
[456] Fix | Delete
path = os.path.normpath(os.path.join(dirpath, name))
[457] Fix | Delete
zf.write(path, path)
[458] Fix | Delete
if logger is not None:
[459] Fix | Delete
logger.info("adding '%s'", path)
[460] Fix | Delete
for name in filenames:
[461] Fix | Delete
path = os.path.normpath(os.path.join(dirpath, name))
[462] Fix | Delete
if os.path.isfile(path):
[463] Fix | Delete
zf.write(path, path)
[464] Fix | Delete
if logger is not None:
[465] Fix | Delete
logger.info("adding '%s'", path)
[466] Fix | Delete
[467] Fix | Delete
return zip_filename
[468] Fix | Delete
[469] Fix | Delete
_ARCHIVE_FORMATS = {
[470] Fix | Delete
'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
[471] Fix | Delete
'bztar': (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
[472] Fix | Delete
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
[473] Fix | Delete
'zip': (_make_zipfile, [],"ZIP file")
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
def get_archive_formats():
[477] Fix | Delete
"""Returns a list of supported formats for archiving and unarchiving.
[478] Fix | Delete
[479] Fix | Delete
Each element of the returned sequence is a tuple (name, description)
[480] Fix | Delete
"""
[481] Fix | Delete
formats = [(name, registry[2]) for name, registry in
[482] Fix | Delete
_ARCHIVE_FORMATS.items()]
[483] Fix | Delete
formats.sort()
[484] Fix | Delete
return formats
[485] Fix | Delete
[486] Fix | Delete
def register_archive_format(name, function, extra_args=None, description=''):
[487] Fix | Delete
"""Registers an archive format.
[488] Fix | Delete
[489] Fix | Delete
name is the name of the format. function is the callable that will be
[490] Fix | Delete
used to create archives. If provided, extra_args is a sequence of
[491] Fix | Delete
(name, value) tuples that will be passed as arguments to the callable.
[492] Fix | Delete
description can be provided to describe the format, and will be returned
[493] Fix | Delete
by the get_archive_formats() function.
[494] Fix | Delete
"""
[495] Fix | Delete
if extra_args is None:
[496] Fix | Delete
extra_args = []
[497] Fix | Delete
if not isinstance(function, collections.Callable):
[498] Fix | Delete
raise TypeError('The %s object is not callable' % function)
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function