code: def main():
      parser = ArgumentParser(
          description=DESCRIP,
          epilog=EPILOG,
          formatter_class=RawDescriptionHelpFormatter,
      )
      parser.add_argument(
          "examples_path",
          type=str,
          help="filename of example or directory containing "
          "examples to run",
      )
      parser.add_argument(
          "--log-path",
          type=str,
          default="",
          help="path for output logs (default is cwd)",
      )
      parser.add_argument(
          "--excludex",
          type=str,
          action="append",
          default=[],
          help="regex for files to exclude (add more than one "
          "--excludex option for more than one regex filter",
      )
      args = parser.parse_args()
      # Proc runner
      eg_path = abspath(expanduser(args.examples_path))
      if args.log_path == "":
          log_path = abspath(os.getcwd())
      else:
          log_path = abspath(expanduser(args.log_path))
      excludexes = [re.compile(s) for s in args.excludex]
      if isfile(eg_path):  # example was a file
          proc_logger = PyProcLogger(
              log_path=log_path, working_path=dirname(eg_path)
          )
          print("Running " + eg_path)
          stdout, stderr, code = proc_logger.run_pipes(eg_path)
          print("==== Stdout ====")
          print(stdout)
          print("==== Stderr ====")
          print(stderr)
          sys.exit(code)
      # Multi-run with logging to file
      proc_logger = PyProcLogger(
          log_path=log_path, working_path=eg_path
      )
      fails = 0
      with open(pjoin(log_path, "summary.txt"), "w") as f:
          for dirpath, dirnames, filenames in os.walk(eg_path):
              for fname in filenames:
                  full_fname = pjoin(dirpath, fname)
                  if fname.endswith(".py"):
                      print(fname, end=": ")
                      sys.stdout.flush()
                      for excludex in excludexes:
                          if excludex.search(fname):
                              _record("SKIP", fname, f)
                              break
                      else:  # run test
                          cmd_name = full_fname.replace(
                              eg_path + psep, ""
                          )
                          cmd_name = cmd_name.replace(psep, "-")
                          code = proc_logger(
                              cmd_name, full_fname, cwd=dirpath
                          )
                          if code == 0:
                              _record("OK", fname, f)
                          else:
                              fails += 1
                              _record("FAIL", fname, f)
      sys.exit(fails if fails < 255 else 255)
  
file_path: nipy/tools/run_log_examples.py
imports: import os
  import re
  import sys
  from argparse import ArgumentParser, RawDescriptionHelpFormatter
  from os.path import abspath, dirname, expanduser, isfile
  from os.path import join
  from os.path import sep
  from subprocess import PIPE, Popen
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types