Ejemplo n.º 1
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
Ejemplo n.º 2
0
def get_current_translators(database):
    """Returns all the translators that haven't been removed.
    """
    collection = get_translator_collection(database)
    argument = mongo_utils.make_single_field_argument("remove_date", None)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 3
0
def get_current_records(database, structure):
    """Returns all the records that haven't been removed for a given structure.
    """
    collection = get_record_collection(database, structure)
    argument = mongo_utils.make_single_field_argument("remove_date", None)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def update_function(project, function, changes):
    """Updates the given parameter set by adding changes for the given changed
    parameters to the current record.
    """
    collection = get_language_collection(project)
    if type(function) in [dict, OrderedDict]:
        function_id = function['_id']
    else:
        function_id = function
    argument = mongo_utils.make_single_field_argument('_id', function_id)
    updates = []
    for change in changes:
        if '.' in change:
            nested_changes = change.split('.')
            nested_value_string = 'workflow'
            for nested_change in nested_changes:
                nested_value_string += '["' "{0}" '"]'.format(nested_change)
            updates.append(
                mongo_utils.make_update_argument(change,
                                                 eval(nested_value_string)))
        else:
            updates.append(
                mongo_utils.make_update_argument(change, function[change]))
    update = mongo_utils.merge_update_args(updates)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    if cursor.matched_count == 1:
        return get_function_by_id(project, function_id)
    return None
Ejemplo n.º 6
0
def update_evaluation(project, evaluation, changes):
    """Updates the given evaluation by adding changes for the given changed
    parameters to the current record.
    """
    collection = get_evaluation_collection(project)
    evaluation_id = evaluation['_id']
    argument = mongo_utils.make_single_field_argument('_id', evaluation_id)
    updates = []
    for change in changes:
        if '.' in change:
            nested_changes = change.split('.')
            nested_value_string = 'evaluation'
            for nested_change in nested_changes:
                nested_value_string += '["' "{0}" '"]'.format(nested_change)
            updates.append(
                mongo_utils.make_update_argument(change,
                                                 eval(nested_value_string)))
        else:
            updates.append(
                mongo_utils.make_update_argument(change, evaluation[change]))
    update = mongo_utils.merge_update_args(updates)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    if cursor.matched_count == 1:
        return get_evaluation_by_id(project, evaluation_id)
    return None
Ejemplo n.º 7
0
def remove_project_record_by_name(project_name):
    """Removes a single record from the project database with the specified project name.
    """
    collection = get_project_collection()
    argument = mongo_utils.make_single_field_argument("name", project_name)
    removal = mongo_utils.mongo_remove_one(collection, argument)
    return removal
Ejemplo n.º 8
0
def update_template(database, template, changes):
    """Updates the given template by adding changes for the given changed
    parameters to the current record.
    """
    collection = get_template_collection(database)
    template_id = mongo_utils.ensure_objectid(template['_id'])
    argument = mongo_utils.make_single_field_argument('_id', template_id)
    updates = []
    for change in changes:
        if '.' in change:
            nested_changes = change.split('.')
            nested_value_string = 'template'
            for nested_change in nested_changes:
                nested_value_string += '["' "{0}" '"]'.format(nested_change)
            updates.append(
                mongo_utils.make_update_argument(change,
                                                 eval(nested_value_string)))
        else:
            updates.append(
                mongo_utils.make_update_argument(change, template[change]))
    update = mongo_utils.merge_update_args(updates)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    if cursor.matched_count == 1:
        return get_template_by_id(database, template_id)
    return None
Ejemplo n.º 9
0
def get_current_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))
    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
    except IndexError:
        return None
Ejemplo n.º 10
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)
Ejemplo n.º 11
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
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def update_function_vcs_status_by_id(project, function_id, status):
    """Updates the vcs status of the given function with the specified status.
    """
    collection = get_function_collection(project)
    argument = mongo_utils.make_single_field_argument('_id', function_id)
    update = mongo_utils.make_update_argument('vcs.status', status)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    return cursor
Ejemplo n.º 14
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
Ejemplo n.º 15
0
def get_all_current_groups(database):
    """Returns all groups that are current (no removal date) in the current
    database.
    """
    collection = get_group_collection(database)
    argument = mongo_utils.make_single_field_argument('remove_date', None)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 16
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
Ejemplo n.º 17
0
def update_component_vcs_status_by_id(database, component_id, status):
    """Updates the vcs status of the given component with the specified status.
    """
    collection = get_component_collection(database)
    argument = mongo_utils.make_single_field_argument('_id', component_id)
    update = mongo_utils.make_update_argument('vcs.status', status)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    return cursor
Ejemplo n.º 18
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
Ejemplo n.º 19
0
def update_evaluation_status_by_id(project, evaluation_id, status):
    """Updates the status of the evaluation with the given id to the given status.
    """
    collection = get_evaluation_collection(project)
    argument = mongo_utils.make_single_field_argument('_id', evaluation_id)
    update = mongo_utils.make_update_argument('status', status)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    return cursor
Ejemplo n.º 20
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
Ejemplo n.º 21
0
def get_components_by_name(database, name):
    """ Returns all the components by name, if it exists, otherwise returns False
    """
    collection = get_component_collection(database)
    argument = mongo_utils.make_single_field_argument('name', name)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 22
0
def get_evaluations_by_name(project, name):
    """ Returns all the evaluations by name, if it exists, otherwise returns False
    """
    collection = get_evaluation_collection(project)
    argument = mongo_utils.make_single_field_argument('name', name)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 23
0
def remove_component_by_id(database, component_id, timestamp):
    """Updates the component with the given id to have a removal datetime of the given
    datetime and sets the component status to removed.
    """
    update_component_status_by_id(database, component_id, 'removed')
    collection = get_component_collection(database)
    argument = mongo_utils.make_single_field_argument('_id', component_id)
    update = mongo_utils.make_update_argument('remove_date', timestamp)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    return cursor
Ejemplo n.º 24
0
def get_removed_evaluations(project):
    """Returns evaluations that have been removed from the specified project.
    Optionally can return all records (including older) if current_only is set to False.
    """
    collection = get_evaluation_collection(project)
    argument = mongo_utils.make_single_field_argument('status', 'removed')
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 25
0
def get_all_current_evaluations(project):
    """Returns all evaluations that are current (no removal date) in the current
    project.
    """
    collection = get_evaluation_collection(project)
    argument = mongo_utils.make_single_field_argument('remove_date', None)
    cursor = mongo_utils.mongo_find_records(collection,
                                            argument=argument,
                                            named_tuple=False)
    return mongo_utils.unload_cursor(cursor)
Ejemplo n.º 26
0
def remove_evaluation_by_id(project, evaluation_id, timestamp):
    """Updates the evaluation with the given id to have a removal datetime of the given
    datetime and sets the evaluation status to removed.
    """
    update_evaluation_status_by_id(project, evaluation_id, 'removed')
    collection = get_evaluation_collection(project)
    argument = mongo_utils.make_single_field_argument('_id', evaluation_id)
    update = mongo_utils.make_update_argument('remove_date', timestamp)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    return cursor
Ejemplo n.º 27
0
def get_group_by_id(database, group_id):
    """Returns the group by the given id.
    """
    collection = get_group_collection(database)
    argument = mongo_utils.make_single_field_argument('_id', group_id)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    group_list = mongo_utils.unload_cursor(cursor)
    try:
        return group_list[0]
    except IndexError:
        return None
Ejemplo n.º 28
0
def get_record_by_id(database, collection, record_id):
    """Returns the record for the given id.
    """
    collection = get_record_collection(database, collection)
    argument = mongo_utils.make_single_field_argument('_id', record_id)
    cursor = mongo_utils.mongo_find_records(collection, argument=argument)
    record_list = mongo_utils.unload_cursor(cursor)
    try:
        return record_list[0]
    except IndexError:
        return None
Ejemplo n.º 29
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
Ejemplo n.º 30
0
def update_component_functions_by_id(database, component_id, functions):
    """Updates the status of the component with the given id to the given status.
    """
    collection = get_component_collection(database)
    argument = mongo_utils.make_single_field_argument('_id', component_id)
    update = mongo_utils.make_update_argument('functions', functions)
    cursor = mongo_utils.mongo_update_one(collection, argument, update)
    updated_component = None
    if cursor.modified_count == 1:
        updated_component = get_component_by_id(database, component_id)
    return updated_component