def get_config_option(option_name, opts, optional=False):
  """Given option_name, checks if it is in appconfig. Raises ValueError if a mandatory option is missing"""
  option = opts.get(option_name)

  if not option and optional is False:
    err = "'{0}' is mandatory and is not set in the app.config file. You must set this value to run this function".format(option_name)
    raise ValueError(err)
  else:
    return option