Example #1
0
def get_functions_for_component(harness, component, current=True):
    """Returns  functions for the given component for the given harness.
    Optional parameter allows user to return current or all functions.
    """
    collection = get_function_collection(harness)
    arguments = []
    if current:
        arguments.append(db_utils.make_single_field_argument("remove_date", None))
    arguments.append(db_utils.make_single_field_argument("component", component))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False)
    function_list = db_utils.unload_cursor(cursor)
    return function_list
Example #2
0
def get_enabled_functions(harness, current_only=True):
    """Returns the enabled functions for the specified harness.
    Optionally can return all records (including older) if current_only is set to False.
    """
    collection = get_function_collection(harness)
    arguments = []
    if current_only:
        arguments.append(db_utils.make_single_field_argument("remove_date", None))
    arguments.append(db_utils.make_single_field_argument("status", "enabled"))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False)
    function_list = db_utils.unload_cursor(cursor)
    return function_list
Example #3
0
def get_all_templates_by_structure_name(database, structure_name):
    """Returns all templates in storage for the given structure name.
    """
    collection = get_template_collection(database)
    arguments = []
    arguments.append(db_utils.make_single_field_argument('structure', structure_name))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument)
    template_list = db_utils.unload_cursor(cursor)
    try:
        return template_list
    except IndexError:
        return None
Example #4
0
def get_structure_by_id(database, structure_id):
    """Returns the current profile by name.
    """
    collection = get_structure_collection(database)
    arguments = []
    arguments.append(db_utils.make_single_field_argument('_id', structure_id))
    arguments.append(db_utils.make_single_field_argument('remove_date', None))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument)
    structure_list = db_utils.unload_cursor(cursor)
    try:
        return structure_list[0]
    except IndexError:
        return None
Example #5
0
def get_translator_by_id(database, translator_id):
    """Returns the current translator by id.
    """
    collection = get_translator_collection(database)
    arguments = []
    arguments.append(db_utils.make_single_field_argument('_id', translator_id))
    arguments.append(db_utils.make_single_field_argument('remove_date', None))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument)
    translator_list = db_utils.unload_cursor(cursor)
    try:
        return translator_list[0]
    except IndexError:
        return None
Example #6
0
def get_current_function_by_name(harness, name):
    """Returns the current function by name.
    """
    collection = get_function_collection(harness)
    arguments = []
    arguments.append(db_utils.make_single_field_argument("name", name))
    arguments.append(db_utils.make_single_field_argument("remove_date", None))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False)
    function_list = db_utils.unload_cursor(cursor)
    try:
        return function_list[0]
    except IndexError:
        return None
Example #7
0
def get_disabled_components(database, current_only=True):
    """Returns the disabled components for the specified database.
    Optionally can return all records (including older) if current_only is set to False.
    """
    collection = get_component_collection(database)
    arguments = []
    if current_only:
        arguments.append(db_utils.make_single_field_argument('remove_date', None))
    arguments.append(db_utils.make_single_field_argument('status', 'disabled'))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument,
                                         named_tuple=False)
    component_list = db_utils.unload_cursor(cursor)
    return component_list
Example #8
0
def get_template_by_id(database, template_id):
    """Returns the template by id.
    """
    collection = get_template_collection(database)
    template_id = db_utils.ensure_objectid(template_id)
    arguments = []
    arguments.append(db_utils.make_single_field_argument('_id', template_id))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument)
    template_list = db_utils.unload_cursor(cursor)
    try:
        return template_list[0]
    except IndexError:
        return None
Example #9
0
def get_program_stations_within_polygon(program, polygon, max_count=0):
    """Returns stations for a given program that are within a given polygon,
    for example a country or state. The polygon must be a GeoJSON geometry.
    """
    collection = get_station_collection()
    arguments = []
    arguments.append(db_utils.make_single_field_argument("program", program))
    arguments.append(db_utils.make_spatial_within_argument("location.point",
                                                           polygon.coordinates,
                                                           polygon.type))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument,
                                         named_tuple=False).limit(max_count)
    return db_utils.unload_cursor(cursor)
Example #10
0
def get_program_stations_by_geoindex(program, longitude, latitude, max_count=0,
                                     max_distance=None):
    """Returns stations for the given program. Uses a max count or max distance to
    search from the given location.
    """
    collection = get_station_collection()
    arguments = []
    arguments.append(db_utils.make_single_field_argument("program", program))
    arguments.append(db_utils.make_spatial_near_argument("location.point", longitude,
                                                         latitude, max_distance))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument,
                                         named_tuple=False).limit(max_count)
    return db_utils.unload_cursor(cursor)
Example #11
0
def get_current_component_by_name(database, name):
    """Returns the current component by name.
    """
    collection = get_component_collection(database)
    arguments = []
    arguments.append(db_utils.make_single_field_argument('name', name))
    arguments.append(db_utils.make_single_field_argument('remove_date', None))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument,
                                         named_tuple=False)
    component_list = db_utils.unload_cursor(cursor)
    try:
        return component_list[0]
    except IndexError:
        return None
Example #12
0
def get_translator_by_name(database, name, template, structure):
    """Returns the current translator by name. Must specify both an template name
    and a structure name. If no name specified, returns the default translator.
    """
    collection = get_translator_collection(database)
    arguments = []
    if not name:
        name = 'default'
    if not template:
        template = 'default'
    arguments.append(db_utils.make_single_field_argument('name', name))
    arguments.append(db_utils.make_single_field_argument('template', template))
    arguments.append(db_utils.make_single_field_argument('structure', structure))
    arguments.append(db_utils.make_single_field_argument('remove_date', None))
    argument = utils.merge_list_of_dicts(arguments)
    cursor = db_utils.mongo_find_records(collection, argument=argument)
    translator_list = db_utils.unload_cursor(cursor)
    try:
        return translator_list[0]
    except IndexError:
        return None