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

    if not option and not optional:
        err = '"{0}" is mandatory and not set in the app.config file.'.format(option_name)
        raise ValueError(err)
    else:
        return option