Beispiel #1
0
def remove_template(database, template):
    """Removes the given template from the template collection in the given database.
    """
    collection = get_template_collection(database)
    template_id = mongo_utils.ensure_objectid(template['_id'])
    arguments = []
    arguments.append(mongo_utils.make_single_field_argument(
        '_id', template_id))
    argument = general_utils.merge_list_of_dicts(arguments)
    result = mongo_utils.mongo_remove_one(collection, argument)
    return result
Beispiel #2
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(
        mongo_utils.make_single_field_argument('structure', structure_name))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    template_list = mongo_utils.unload_cursor(cursor)
    try:
        return template_list
    except IndexError:
        return None
Beispiel #3
0
def get_template_by_id(database, template_id):
    """Returns the template by id.
    """
    collection = get_template_collection(database)
    template_id = mongo_utils.ensure_objectid(template_id)
    arguments = []
    arguments.append(mongo_utils.make_single_field_argument(
        '_id', template_id))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    template_list = mongo_utils.unload_cursor(cursor)
    try:
        return template_list[0]
    except IndexError:
        return None
Beispiel #4
0
def get_default_profile(database):
    """Returns the current profile by name.
    """
    collection = get_profile_collection(database)
    arguments = []
    arguments.append(mongo_utils.make_single_field_argument('default', True))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    profile_list = mongo_utils.unload_cursor(cursor)
    try:
        return profile_list[0]
    except IndexError:
        return None
Beispiel #5
0
def get_translator_by_id(database, translator_id):
    """Returns the current translator by id.
    """
    collection = get_translator_collection(database)
    arguments = []
    arguments.append(
        mongo_utils.make_single_field_argument('_id', translator_id))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    translator_list = mongo_utils.unload_cursor(cursor)
    try:
        return translator_list[0]
    except IndexError:
        return None
Beispiel #6
0
def get_all_structures(database, args=None):
    """Returns all the structures in storage.
    """
    collection = get_structure_collection(database)
    if args:
        arguments = [
            mongo_utils.make_single_field_argument(arg['key'],
                                                   arg['value'],
                                                   arg_type=arg['operation'])
            for arg in args
        ]
        argument = general_utils.merge_list_of_dicts(arguments)
        cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    else:
        cursor = mongo_utils.mongo_find_records(collection)
    return mongo_utils.unload_cursor(cursor)
Beispiel #7
0
def get_template_by_name(database, structure, name):
    """Returns the current template by name.
    """
    collection = get_template_collection(database)
    arguments = []
    arguments.append(
        mongo_utils.make_single_field_argument('structure', structure))
    arguments.append(mongo_utils.make_single_field_argument('name', name))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    template_list = mongo_utils.unload_cursor(cursor)
    try:
        return template_list[0]
    except IndexError:
        return None
Beispiel #8
0
def get_current_evaluation_by_name(project, name):
    """Returns the current evaluation by name.
    """
    collection = get_evaluation_collection(project)
    arguments = []
    arguments.append(mongo_utils.make_single_field_argument('name', name))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    evaluation_list = mongo_utils.unload_cursor(cursor)
    try:
        return evaluation_list[0]
    except IndexError:
        return None
Beispiel #9
0
def get_workflow_evaluations_by_name(project, workflow, name):
    """Returns all evaluations in the given workflow with the given name.
    """
    collection = get_evaluation_collection(project)
    arguments = []
    arguments.append(mongo_utils.make_single_field_argument('name', name))
    arguments.append(
        mongo_utils.make_single_field_argument('workflow', workflow))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    evaluation_list = mongo_utils.unload_cursor(cursor)
    try:
        return evaluation_list
    except IndexError:
        return None
Beispiel #10
0
def get_structure_by_id(database, structure_id):
    """Returns the current profile by name.
    """
    structure_id = mongo_utils.ensure_objectid(structure_id)
    collection = get_structure_collection(database)
    arguments = []
    arguments.append(
        mongo_utils.make_single_field_argument('_id', structure_id))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    structure_list = mongo_utils.unload_cursor(cursor)
    try:
        return structure_list[0]
    except IndexError:
        return None
Beispiel #11
0
def get_current_structures(database, args=None):
    """Returns all the structures that haven't been removed.
    """
    collection = get_structure_collection(database)
    arguments = []
    if args:
        arguments = [
            mongo_utils.make_single_field_argument(arg['key'],
                                                   arg['value'],
                                                   arg_type=arg['operation'])
            for arg in args
        ]
    arguments.append(
        mongo_utils.make_single_field_argument("remove_date", None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    return mongo_utils.unload_cursor(cursor)
Beispiel #12
0
def get_enabled_functions(project, current_only=True):
    """Returns the enabled functions for the specified project.
    Optionally can return all records (including older) if current_only is set to False.
    """
    collection = get_function_collection(project)
    arguments = []
    if current_only:
        arguments.append(
            mongo_utils.make_single_field_argument('remove_date', None))
    arguments.append(
        mongo_utils.make_single_field_argument('status', 'enabled'))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    function_list = mongo_utils.unload_cursor(cursor)
    return function_list
Beispiel #13
0
def get_functions_for_component(project, component, current=True):
    """Returns  functions for the given component for the given project.
    Optional parameter allows user to return current or all functions.
    """
    collection = get_function_collection(project)
    arguments = []
    if current:
        arguments.append(
            mongo_utils.make_single_field_argument('remove_date', None))
    arguments.append(
        mongo_utils.make_single_field_argument('component', component))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    function_list = mongo_utils.unload_cursor(cursor)
    return function_list
Beispiel #14
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(
            mongo_utils.make_single_field_argument('remove_date', None))
    arguments.append(
        mongo_utils.make_single_field_argument('status', 'disabled'))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    component_list = mongo_utils.unload_cursor(cursor)
    return component_list
Beispiel #15
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(mongo_utils.make_single_field_argument('name', name))
    arguments.append(
        mongo_utils.make_single_field_argument('template', template))
    arguments.append(
        mongo_utils.make_single_field_argument('structure', structure))
    arguments.append(
        mongo_utils.make_single_field_argument('remove_date', None))
    argument = general_utils.merge_list_of_dicts(arguments)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    translator_list = mongo_utils.unload_cursor(cursor)
    try:
        return translator_list[0]
    except IndexError:
        return None