def onerror(func, path, _exc_info):
if not os.access(path, os.W_OK):<EOL><INDENT>os.chmod(path, stat.S_IWUSR)<EOL>func(path)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT>
Error handler for `shutil.rmtree`.

If the error is due to an access error (read only file)
it attempts to add write permission and then retries.

If the error is for another reason it re-raises the error.

Copyright Michael Foord 2004
Released subject to the BSD License
ref: http://www.voidspace.org.uk/python/recipebook.shtml#utils

Usage : `shutil.rmtree(path, onerror=onerror)`