Exemple #1
0
def get_query_from_yaml(config_path):
    """Creates a Query object from a yaml file found in config_path.

    The Query object is created from the configuration found in the yaml file.
    Filters objects are created from the yaml file aswell and are attached
    to the Query.
    :param config_path: Path to the configuration yaml file.
    :return: A Query object along with the filters in the file, if found.
    """
    try:
        with open(config_path) as config_file:
            yaml_contents = yaml.load(config_file)

    except IOError:
        sys.exit('The config.yaml path you provided, `{0}`, does not '
                 'lead to an existing file.'.format(config_path))

    yaml_config = yaml_contents['query_config']
    yaml_filters = yaml_contents['filters']

    qc = QueryConfig.from_yaml(yaml_config)
    filters = [Filter.from_yaml(yaml_filter) for yaml_filter in yaml_filters]

    query = Query.from_config(qc)
    query.attach_filters(filters)

    return query
Exemple #2
0
def get_query_from_args(args):
    """Creates a Query object from the CLI arguments.

    Filter objects are created from the CLI argument and attached to the
    Query object.
    :param args: CLI arguments
    :return: A Query object along with the created filters, if found.
    """
    qc = QueryConfig.from_args(args)
    filters = get_filters_from_args(args)

    query = Query.from_config(qc)
    query.attach_filters(filters)

    return query