当前位置: 首页>>代码示例>>Python>>正文


Python shutil.html方法代码示例

本文整理汇总了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) 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:24,代码来源:deployment.py

示例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) 
开发者ID:glotzerlab,项目名称:signac,代码行数:26,代码来源:syncutil.py

示例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) 
开发者ID:pettarin,项目名称:penelope,代码行数:24,代码来源:utilities.py

示例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 
开发者ID:mdangschat,项目名称:ctc-asr,代码行数:19,代码来源:storage.py


注:本文中的shutil.html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。