當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。