code: def with_result_progress(
      fn, label="Total", unit=" Files", log_filter=None
  ):
      """Wrap a progress bar, with status counts, around a function.
  
      Parameters
      ----------
      fn : generator function
          This function should accept a collection of items as a
          positional argument and any number of keyword arguments.  After
          processing each item in the collection, it should yield a status
          dict.
      log_filter : callable, optional
          If defined, only result records for which callable evaluates to True will be
          passed to log_progress
  
      label, unit : str
          Passed to log.log_progress.
  
      Returns
      -------
      A variant of `fn` that shows a progress bar.  Note that the wrapped
      function is not a generator function; the status dicts will be
      returned as a list.
      """
      # FIXME: This emulates annexrepo.ProcessAnnexProgressIndicators.  It'd be
      # nice to rewire things so that it could be used directly.
  
      def count_str(count, verb, omg=False):
          if count:
              msg = "{:d} {}".format(count, verb)
              if omg:
                  msg = colors.color_word(msg, colors.RED)
              return msg
  
      base_label = label
  
      def _wrap_with_result_progress_(items, *args, **kwargs):
          counts = defaultdict(int)
  
          pid = "%s:%s" % (fn, random.randint(0, 100000))
  
          label = base_label
          log_progress(
              lgr.info,
              pid,
              "%s: starting",
              label,
              total=len(items),
              label=label,
              unit=unit,
              noninteractive_level=5,
          )
  
          for res in fn(items, *args, **kwargs):
              if not (log_filter and not log_filter(res)):
                  counts[res["status"]] += 1
                  count_strs = (
                      count_str(*args)
                      for args in [
                          (counts["notneeded"], "skipped", False),
                          (counts["error"], "failed", True),
                      ]
                  )
                  if counts["notneeded"] or counts["error"]:
                      label = "{} ({})".format(
                          base_label,
                          ", ".join(filter(None, count_strs)),
                      )
  
                  log_progress(
                      lgr.error
                      if res["status"] == "error"
                      else lgr.info,
                      pid,
                      "%s: processed result%s",
                      base_label,
                      " for " + res["path"] if "path" in res else "",
                      label=label,
                      update=1,
                      increment=True,
                      noninteractive_level=5,
                  )
              yield res
          log_progress(
              lgr.info,
              pid,
              "%s: done",
              base_label,
              noninteractive_level=5,
          )
  
      def _wrap_with_result_progress(items, *args, **kwargs):
          return list(
              _wrap_with_result_progress_(items, *args, **kwargs)
          )
  
      return (
          _wrap_with_result_progress_
          if inspect.isgeneratorfunction(fn)
          else _wrap_with_result_progress
      )
  
imports: from contextlib import contextmanager
  from functools import partial
  import inspect
  import logging
  import os
  import sys
  import platform
  import random
  import logging.handlers
  import warnings
  from os.path import basename, dirname
  from collections import defaultdict
  from .utils import is_interactive, optional_args
  from .support import ansi_colors
label_desc: Use image node_id 4 for calling a global function with example usage: with_result_progress(fn, label, unit, log_filter) and returns: unknown, list, msg