docs: def filename_fix_existing(filename, dirname):
      """Expands name portion of filename with numeric ' (x)' suffix to
      return filename that doesn't exist already.
      """
      name, ext = filename.rsplit('.', 1)
      names = [x for x in os.listdir(dirname) if x.startswith(name)]
      names = [x.rsplit('.', 1)[0] for x in names]
      suffixes = [x.replace(name, '') for x in names]
      # filter suffixes that match ' (x)' pattern
      suffixes = [x[2:-1] for x in suffixes
                  if x.startswith(' (') and x.endswith(')')]
      indexes = [int(x) for x in suffixes
                 if set(x) <= set('0123456789')]
      idx = 1
      if indexes:
          idx += sorted(indexes)[-1]
      return '{0}({1}).{2}'.format(name, idx, ext)