Python shutil.html() Examples

The following are 4 code examples of shutil.html(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shutil , or try the search function .
Example #1
Source File: deployment.py    From Dallinger with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: syncutil.py    From signac with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #3
Source File: utilities.py    From penelope with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: storage.py    From ctc-asr with MIT License 6 votes vote down vote up
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