#NEWLINE# def rmtree( path , ignore_errors = False , onerror = None ) : #NEWLINE# #INDENT# 'Recursively delete a directory tree.\n\n    If ignore_errors is set, errors are ignored; otherwise, if onerror\n    is set, it is called to handle the error with arguments (func,\n    path, exc_info) where func is os.listdir, os.remove, or os.rmdir;\n    path is the argument to that function that caused it to fail; and\n    exc_info is a tuple returned by sys.exc_info().  If ignore_errors\n    is false and onerror is None, an exception is raised.\n\n    ' #NEWLINE# if ignore_errors : #NEWLINE# #INDENT# def onerror( * args ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( onerror is None ) : #NEWLINE# #INDENT# def onerror( * args ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# if os . path . islink ( path ) : #NEWLINE# #INDENT# raise OSError ( 'Cannot call rmtree on a symbolic link' ) #NEWLINE# #UNINDENT# #UNINDENT# except OSError : #NEWLINE# #INDENT# onerror ( os . path . islink , path , sys . exc_info ( ) ) #NEWLINE# return #NEWLINE# #UNINDENT# names = [ ] #NEWLINE# try : #NEWLINE# #INDENT# names = os . listdir ( path ) #NEWLINE# #UNINDENT# except os . error : #NEWLINE# #INDENT# onerror ( os . listdir , path , sys . exc_info ( ) ) #NEWLINE# #UNINDENT# for name in names : #NEWLINE# #INDENT# fullname = os . path . join ( path , name ) #NEWLINE# try : #NEWLINE# #INDENT# mode = os . lstat ( fullname ) . st_mode #NEWLINE# #UNINDENT# except os . error : #NEWLINE# #INDENT# mode = 0 #NEWLINE# #UNINDENT# if stat . S_ISDIR ( onerror ) : #NEWLINE# #INDENT# rmtree ( fullname , ignore_errors , onerror ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . remove ( fullname ) #NEWLINE# #UNINDENT# except os . error : #NEWLINE# #INDENT# onerror ( os . remove , fullname , sys . exc_info ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# os . rmdir ( path ) #NEWLINE# #UNINDENT# except os . error : #NEWLINE# #INDENT# onerror ( os . rmdir , path , sys . exc_info ( ) )