def rmtree(path, use_shutil=True, followlinks=False, retries=<NUM_LIT:10>):
if use_shutil and not followlinks:<EOL><INDENT>try:<EOL><INDENT>shutil.rmtree(path)<EOL>return<EOL><DEDENT>except Exception as exc:<EOL><INDENT>logger.info('<STR_LIT>', path)<EOL>logger.debug('<STR_LIT>', traceback.format_exc(exc))<EOL><DEDENT><DEDENT>if not os.path.isdir(path):<EOL><INDENT>os.remove(path)<EOL>return<EOL><DEDENT>for root, dir_names, file_names in os.walk(path, topdown=False, followlinks=followlinks):<EOL><INDENT>for fname in file_names:<EOL><INDENT>fpath = os.path.join(root, fname)<EOL>tries = <NUM_LIT:0><EOL>while tries < retries:<EOL><INDENT>tries += <NUM_LIT:1><EOL>try:<EOL><INDENT>os.remove(fpath)<EOL>break<EOL><DEDENT>except Exception as exc:<EOL><INDENT>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT>if os.path.exists(fpath):<EOL><INDENT>logger.critical('<STR_LIT>', fpath)<EOL>logger.critical('<STR_LIT>', traceback.format_exc(exc))<EOL><DEDENT><DEDENT>for dname in dir_names:<EOL><INDENT>full_path = os.path.join(root, dname)<EOL>if os.path.islink(full_path):<EOL><INDENT>real_path = os.path.realpath(full_path)<EOL>os.remove(full_path)<EOL>full_path = real_path<EOL><DEDENT>os.rmdir(full_path)<EOL><DEDENT><DEDENT>if os.path.exists(path):<EOL><INDENT>os.rmdir(path)<EOL><DEDENT>
remove all files and directories below path, including path
    itself; works even when shutil.rmtree fails because of read-only
    files in NFS and Windows.  Follows symlinks.

    `use_shutil` defaults to True; useful for testing

    `followlinks` defaults to False; if set to True, shutil.rmtree is
    not used.