def replace_function_by_id(harness, function_id, function): """Replaces the current function with the new function. Returns the new function. """ collection = get_function_collection(harness) argument = db_utils.make_single_field_argument("_id", function_id) cursor = db_utils.mongo_replace_one(collection, function, argument) if cursor.matched_count == 1: 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
def replace_workflow_by_id(harness, workflow_id, workflow): """Replaces the current workflow with the new workflow. Returns the new workflow. """ collection = get_workflow_collection(harness) argument = db_utils.make_single_field_argument('_id', workflow_id) cursor = db_utils.mongo_replace_one(collection, workflow, argument) if cursor.matched_count == 1: cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) workflow_list = db_utils.unload_cursor(cursor) try: return workflow_list[0] except IndexError: return None
def replace_component_by_id(database, component_id, component): """Replaces the current component with the new component. Returns the new component. """ collection = get_component_collection(database) argument = db_utils.make_single_field_argument('_id', component_id) cursor = db_utils.mongo_replace_one(collection, component, argument) if cursor.matched_count == 1: 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
def replace_harness_by_id(harness_id, harness): """Replaces a harness matching the given id with the new harness object. Returns the new harness object. """ collection = get_harness_collection() argument = db_utils.make_single_field_argument("_id", harness_id) cursor = db_utils.mongo_replace_one(collection, harness, argument) if cursor.matched_count == 1: cursor = db_utils.mongo_find_records(collection, argument=argument, named_tuple=False) harness_list = db_utils.unload_cursor(cursor) try: return harness_list[0] except: return None return None