code: def prune_tree(path):
      
      try:
          os.unlink(path)
          return
      except OSError:
          e = sys.exc_info()[1]
          if not (os.path.isdir(path) and
                  e.args[0] in (errno.EPERM, errno.EISDIR)):
              LOG.error('prune_tree(%r): %s', path, e)
              return
  
      try:
          # Ensure write access for readonly directories. Ignore error in case
          # path is on a weird filesystem (e.g. vfat).
          os.chmod(path, int('0700', 8))
      except OSError:
          e = sys.exc_info()[1]
          LOG.warning('prune_tree(%r): %s', path, e)
  
      try:
          for name in os.listdir(path):
              if name not in ('.', '..'):
                  prune_tree(os.path.join(path, name))
          os.rmdir(path)
      except OSError:
          e = sys.exc_info()[1]
          LOG.error('prune_tree(%r): %s', path, e)
docs: Like shutil.rmtree(), but log errors rather than discard them, and do not
      waste multiple os.stat() calls discovering whether the object can be
      deleted, just try deleting it instead.