def run(prelaunch=False):
  if sys.argv[1] != '--main-name':
    raise Exception("launched wrong: expected --main-name <mainname> as first argument")
  main_name = sys.argv[2]
  del sys.argv[1:3] # remove the --main-name argument

  thirdpartydir = os.path.join(os.path.dirname(__file__), "../third_party")
  tracedir = os.path.join(thirdpartydir, "py_trace_event")

  # A recent change to py_trace_event leaves an old trace_event dir with .pyc files
  # hanging around. This prevents importing the new trace_event. Clobber it if it is found.
  tracedir_old_style_traceevent = os.path.join(tracedir, "trace_event")
  if os.path.exists(tracedir) and os.path.exists(tracedir_old_style_traceevent) and os.path.isdir(tracedir_old_style_traceevent):
    for root, dirs, files in os.walk(tracedir_old_style_traceevent, False, None, False):
      for f in files:
        os.unlink(os.path.join(root, f))
      for d in dirs:
        os.rmdir(os.path.join(root, d))
    os.rmdir(tracedir_old_style_traceevent)

  # Import trace event.
  sys.path.append(tracedir)
  try:
    __import__("trace_event")
  except:
    print "Could not find py_trace_event. Did you forget 'git submodule update --init'?"
    sys.exit(255)

  # Import python-daemon.
  sys.path.append(os.path.join(thirdpartydir, "python-daemon/daemon"))
  try:
    __import__("daemon")
  except:
    print "Could not find python-daemon. Did you forget 'git submodule update --init'?"
    sys.exit(255)

  # Import PyGithub.
  sys.path.append(os.path.join(thirdpartydir, "PyGithub/github"))
  try:
    __import__("Github")
  except:
    print "Could not find PyGithub. Did you forget 'git submodule update --init'?"
    sys.exit(255)

  mod = __import__(main_name, {}, {}, True)
  import optparse
  parser = optparse.OptionParser(usage=mod.main_usage())
  parser.add_option('--chrome', action="store_true", dest="chrome", help="Use chrome app UI")
  parser.add_option('--curses', action="store_true", dest="curses", help="Use curses UI")
  parser.add_option(
      '-v', '--verbose', action='count', default=0,
      help='Increase verbosity level (repeat as needed)')
  original_parse_args = parser.parse_args
  def parse_args_shim():
    options, args = original_parse_args()
    handle_options(options, args)
    return options, args
  parser.parse_args = parse_args_shim

  return mod.main(parser)
Called by bootstrapper when the environment is ready to run.
dataset/ETHPy150Open natduca/quickopen/src/bootstrap.py/run