original_docstring:  Deletes (with prejudice) a file or directory (recursively). Read-only files/directories are first set to writable, then deleted.
  
      @type target string
      @param target /path/to/dir or /path/to/file.ext
  
      @rtype bool
      @returns True if file/directory is deleted (or not there to begin with).
      
docstring: Deletes (with prejudice) a file or directory (recursively). Read-only files/directories are first set to writable, then deleted.
  
  @rtype bool
  @returns True if file/directory is deleted (or not there to begin with).
docstring_tokens: Deletes ( with prejudice ) a file or directory ( recursively ) . Read - only files / directories are first set to writable then deleted . @rtype bool @returns True if file / directory is deleted ( or not there to begin with ) .
code: def delete_file_or_directory(target):
      """ Deletes (with prejudice) a file or directory (recursively). Read-only files/directories are first set to writable, then deleted.
  
      @type target string
      @param target /path/to/dir or /path/to/file.ext
  
      @rtype bool
      @returns True if file/directory is deleted (or not there to begin with).
      """
  
      def make_writeable_and_try_again(func, path, exc_info):
          """ Error callback for shutil.rmtree.
              Sets parent directory writable (if necessary) and the file itself writeable, then reexecutes the function that previously failed. """
  
          if func in (os.rmdir, os.remove) and exc_info[1].errno == errno.EACCES:
              # ensure parent directory is writeable too
              pardir = os.path.abspath(os.path.join(path, os.path.pardir))
              if not os.access(pardir, os.W_OK):
                  os.chmod(pardir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
  
              os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)  # 0777
              func(path)
          else:
              raise
  
      if os.path.exists(target):
          if os.path.isfile(target):
              os.remove(target)
          else:
              try:
                  shutil.rmtree(target, ignore_errors=False, onerror=make_writeable_and_try_again)
              except OSError:
                  return False
  
      return True
code_tokens: def delete_file_or_directory ( target ) : def make_writeable_and_try_again ( func , path , exc_info ) : """ Error callback for shutil.rmtree.
              Sets parent directory writable (if necessary) and the file itself writeable, then reexecutes the function that previously failed. """ if func in ( os . rmdir , os . remove ) and exc_info [ 1 ] . errno == errno . EACCES : pardir = os . path . abspath ( os . path . join ( path , os . path . pardir ) ) if not os . access ( pardir , os . W_OK ) : os . chmod ( pardir , stat . S_IRWXU | stat . S_IRWXG | stat . S_IRWXO ) os . chmod ( path , stat . S_IRWXU | stat . S_IRWXG | stat . S_IRWXO ) func ( path ) else : raise if os . path . exists ( target ) : if os . path . isfile ( target ) : os . remove ( target ) else : try : shutil . rmtree ( target , ignore_errors = False , onerror = make_writeable_and_try_again ) except OSError : return False return True
short_docstring: Deletes (with prejudice) a file or directory (recursively).
short_docstring_tokens: Deletes ( with prejudice ) a file or directory ( recursively ) .
comment: """ Deletes (with prejudice) a file or directory (recursively). Read-only files/directories are first set to writable, then deleted.
  
      @type target string
      @param target /path/to/dir or /path/to/file.ext
  
      @rtype bool
      @returns True if file/directory is deleted (or not there to begin with).
      """$SEP$""" Error callback for shutil.rmtree.
              Sets parent directory writable (if necessary) and the file itself writeable, then reexecutes the function that previously failed. """$SEP$# ensure parent directory is writeable too$SEP$# 0777