code: def clean_output_dir(path, retention):
      """Remove all files from output directory except those in retention list"""
  
      if not os.path.exists(path):
          logger.debug("Directory already removed: %s", path)
          return
  
      if not os.path.isdir(path):
          try:
              os.remove(path)
          except Exception as e:
              logger.error("Unable to delete file %s; %s", path, e)
          return
  
      # remove existing content from output folder unless in retention list
      for filename in os.listdir(path):
          file = os.path.join(path, filename)
          if any(filename == retain for retain in retention):
              logger.debug(
                  "Skipping deletion; %s is on retention list: %s",
                  filename,
                  file,
              )
          elif os.path.isdir(file):
              try:
                  shutil.rmtree(file)
                  logger.debug("Deleted directory %s", file)
              except Exception as e:
                  logger.error(
                      "Unable to delete directory %s; %s", file, e
                  )
          elif os.path.isfile(file) or os.path.islink(file):
              try:
                  os.remove(file)
                  logger.debug("Deleted file/link %s", file)
              except Exception as e:
                  logger.error("Unable to delete file %s; %s", file, e)
          else:
              logger.error(
                  "Unable to delete %s, file type unknown", file
              )
  
imports: import datetime
  import fnmatch
  import locale
  import logging
  import os
  import pathlib
  import re
  import shutil
  import sys
  import traceback
  import urllib
  from collections.abc import Hashable
  from contextlib import contextmanager
  from functools import partial
  from html import entities
  from html.parser import HTMLParser
  from itertools import groupby
  from operator import attrgetter
  import dateutil.parser
  from markupsafe import Markup
  import watchfiles
label_desc: Use image node_id 9 for calling a global function with example usage: clean_output_dir(path, retention) without return types