async def purge(req): """ Delete all unreferenced HMMs and hide the rest. """ db = req.app["db"] await virtool.hmm.db.purge(db, req.app["settings"]) hmm_path = os.path.join(req.app["settings"]["data_path"], "hmm/profiles.hmm") try: await req.app["run_in_thread"](virtool.utils.rm, hmm_path) except FileNotFoundError: pass await db.status.find_one_and_update( {"_id": "hmm"}, {"$set": { "installed": None, "process": None, "updates": list() }}) await virtool.hmm.db.fetch_and_update_release(req.app) return no_content()
async def remove(req): """ Remove a job. """ db = req.app["db"] job_id = req.match_info["job_id"] document = await db.jobs.find_one(job_id) if not document: return not_found() if virtool.jobs.is_running_or_waiting(document): return conflict("Job is running or waiting and cannot be removed") # Removed the documents associated with the job ids from the database. await db.jobs.delete_one({"_id": job_id}) try: # Calculate the log path and remove the log file. If it exists, return True. path = os.path.join(req.app["settings"]["data_path"], "logs", "jobs", job_id + ".log") await req.app["run_in_thread"](virtool.utils.rm, path) except OSError: pass return no_content()
async def remove(req): """ Remove a sample document and all associated analyses. """ db = req.app["db"] sample_id = req.match_info["sample_id"] try: if not await virtool.samples.db.check_rights(db, sample_id, req["client"]): return insufficient_rights() except virtool.errors.DatabaseError as err: if "Sample does not exist" in str(err): return not_found() raise await virtool.samples.db.remove_samples( db, req.app["settings"], [sample_id] ) return no_content()
async def remove_sequence(req): """ Remove a sequence from an isolate. """ db = req.app["db"] otu_id = req.match_info["otu_id"] isolate_id = req.match_info["isolate_id"] sequence_id = req.match_info["sequence_id"] if not await db.sequences.count_documents({"_id": sequence_id}): return not_found() document = await db.otus.find_one({"_id": otu_id, "isolates.id": isolate_id}, ["reference"]) if document is None: return not_found() if not await virtool.references.db.check_right(req, document["reference"]["id"], "modify_otu"): return insufficient_rights() await asyncio.shield(virtool.otus.sequences.remove( req.app, otu_id, isolate_id, sequence_id, req["client"].user_id )) return no_content()
async def remove_all_api_keys(req): """ Remove all API keys for the session account. """ await req.app["db"].keys.delete_many({"user.id": req["client"].user_id}) return no_content()
async def remove(req): db = req.app["db"] settings = req.app["settings"] subtraction_id = req.match_info["subtraction_id"] updated_count = await asyncio.shield(virtool.subtractions.db.delete(req.app, subtraction_id)) if updated_count == 0: return not_found() return no_content()
async def remove_api_key(req): db = req.app["db"] user_id = req["client"].user_id key_id = req.match_info["key_id"] delete_result = await db.keys.delete_one({ "id": key_id, "user.id": user_id }) if delete_result.deleted_count == 0: return not_found() return no_content()
async def remove(req): """ Remove a group. """ db = req.app["db"] group_id = req.match_info["group_id"] delete_result = await db.groups.delete_one({"_id": group_id}) if not delete_result.deleted_count: return not_found() await virtool.groups.db.update_member_users(db, group_id, remove=True) return no_content()
async def remove(req): """ Remove an analysis document by its id. """ db = req.app["db"] analysis_id = req.match_info["analysis_id"] document = await db.analyses.find_one({"_id": analysis_id}, ["job", "ready", "sample"]) if not document: return not_found() sample_id = document["sample"]["id"] sample = await db.samples.find_one({"_id": sample_id}, virtool.samples.db.PROJECTION) if not sample: return bad_request("Parent sample does not exist") read, write = virtool.samples.utils.get_sample_rights( sample, req["client"]) if not read or not write: return insufficient_rights() if not document["ready"]: return conflict("Analysis is still running") await db.analyses.delete_one({"_id": analysis_id}) path = os.path.join(req.app["settings"]["data_path"], "samples", sample_id, "analysis", analysis_id) await req.app["run_in_thread"](virtool.utils.rm, path, True) await virtool.samples.db.recalculate_workflow_tags(db, sample_id) return no_content()
async def delete_user(req): db = req.app["db"] ref_id = req.match_info["ref_id"] user_id = req.match_info["user_id"] document = await db.references.find_one( { "_id": ref_id, "users.id": user_id }, ["groups", "users"]) if document is None: return not_found() if not await virtool.references.db.check_right(req, ref_id, "modify"): return insufficient_rights() await virtool.references.db.delete_group_or_user(db, ref_id, user_id, "users") return no_content()
async def remove(req): """ Remove a user. """ db = req.app["db"] user_id = req.match_info["user_id"] if user_id == req["client"].user_id: return bad_request("Cannot remove own account") delete_result = await db.users.delete_one({"_id": user_id}) # Remove user from all references. await db.references.update_many({}, {"$pull": {"users": {"id": user_id}}}) if delete_result.deleted_count == 0: return not_found() return no_content()
async def revert(req): """ Remove the change document with the given ``change_id`` and any subsequent changes. """ db = req.app["db"] change_id = req.match_info["change_id"] document = await db.history.find_one(change_id, ["reference"]) if not document: return not_found() if not await virtool.references.db.check_right( req, document["reference"]["id"], "modify_otu"): return insufficient_rights() try: await virtool.history.db.revert(req.app, change_id) except virtool.errors.DatabaseError: return conflict("Change is already built") return no_content()