本文整理汇总了Python中shutil.html方法的典型用法代码示例。如果您正苦于以下问题:Python shutil.html方法的具体用法?Python shutil.html怎么用?Python shutil.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shutil
的用法示例。
在下文中一共展示了shutil.html方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exclusion_policy
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import html [as 别名]
def exclusion_policy():
"""Returns a callable which, when passed a directory path and a list
of files in that directory, will return a subset of the files which should
be excluded from a copy or some other action.
See https://docs.python.org/3/library/shutil.html#shutil.ignore_patterns
"""
patterns = set(
[
".git",
"config.txt",
"*.db",
"*.dmg",
"node_modules",
"snapshots",
"data",
"server.log",
"__pycache__",
]
)
return shutil.ignore_patterns(*patterns)
示例2: copytree
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import html [as 别名]
def copytree(src, dst, copy_function=shutil.copy2, symlinks=False):
"Implementation adapted from https://docs.python.org/3/library/shutil.html#copytree-example'."
os.makedirs(dst)
names = os.listdir(src)
errors = []
for name in names:
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, copy_function, symlinks)
else:
copy_function(srcname, dstname)
except OSError as why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except shutil.Error as err:
errors.extend(err.args[0])
if errors:
raise shutil.Error(errors)
示例3: delete_directory
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import html [as 别名]
def delete_directory(path):
"""
Safely delete a directory.
:param path: the file path
:type path: string (path)
"""
def remove_readonly(func, path, _):
"""
Clear the readonly bit and reattempt the removal
Adapted from https://docs.python.org/3.5/library/shutil.html#rmtree-example
See also http://stackoverflow.com/questions/2656322/python-shutil-rmtree-fails-on-windows-with-access-is-denied
"""
try:
os.chmod(path, stat.S_IWRITE)
func(path)
except:
pass
if path is not None:
shutil.rmtree(path, onerror=remove_readonly)
示例4: delete_directory_if_exists
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import html [as 别名]
def delete_directory_if_exists(path):
"""Recursive delete of a folder and all contained files.
Args:
path (str): Directory path.
Returns:
Nothing.
"""
if os.path.exists(path) and os.path.isdir(path):
# https://docs.python.org/3/library/shutil.html#shutil.rmtree
# Doesn't state which errors are possible.
try:
shutil.rmtree(path)
except OSError as exception:
raise exception