def delete_source(): from lib.core.state import State sources_dict = State.get_sources() tasks_dict = State.get_tasks() creator.print_title("Delete Source") changes_made = False while True: sources_list = [] for s in sources_dict: sources_list.append(sources_dict[s]) for i in range(len(sources_list)): print(f"{i} - {sources_list[i].name}") print("s - save and quit") print("q - quit without saving") tnum_str = creator.prompt_string("Delete source") if tnum_str == "s": save(sources_dict, sources_file) core.task.save(tasks_dict, tasks_file) return elif tnum_str == "q": if changes_made and creator.yes_no("Quit without saving", "n") == "y": return elif not changes_made: return if re.match("[0-9]+$", tnum_str): tnum = int(tnum_str) if tnum >= 0 and tnum < len(sources_list): if creator.yes_no(f"Delete {sources_list[tnum].name}", "y") == "y": used_by = get_tasks_using_source( sources_dict[sources_list[tnum].id], tasks_dict) if len(used_by) > 0: task_names = [] for u in used_by: task_names.append(f"'{u.name}'") print( f"Cannot delete source. It is being used by task(s): {','.join(task_names)}" ) print( "Delete those tasks or remove this notification agent from them first before deleting." ) else: do_delete_source(sources_list[tnum].id) changes_made = True
def edit_notif_agent(): creator.print_title("Edit Notification Agent") notif_agent = creator.prompt_complex_dict("Choose a notification agent", State.get_notif_agents(), "name", extra_options=["d"], extra_options_desc=["done"]) if notif_agent == "d": return else: notif_agent_creator(notif_agent)
def edit_task(): from lib.core.state import State creator.print_title("Edit Task") task = creator.prompt_complex_dict("Choose a task", State.get_tasks(), "name", extra_options=["d"], extra_options_desc=["done"]) if task == "d": return else: task_creator(task)
def delete_notif_agent(): notif_agents_dict = State.get_notif_agents() creator.print_title("Delete Notification Agent") changes_made = False while True: notif_agents_list = [] for n in notif_agents_dict: notif_agents_list.append(notif_agents_dict[n]) for i in range(len(notif_agents_list)): print(f"{i} - {notif_agents_list[i].name}") print("s - save and quit") print("q - quit without saving") tnum_str = creator.prompt_string("Delete notif_agent") if tnum_str == "s": State.save_notif_agents() State.save_tasks() break elif tnum_str == "q": if changes_made and creator.yes_no("Quit without saving", "n") == "y": return elif not changes_made: return if re.match("[0-9]+$", tnum_str): tnum = int(tnum_str) if tnum >= 0 and tnum < len(notif_agents_list): if creator.yes_no(f"Delete {notif_agents_list[tnum].name}", "y") == "y": used_by = get_tasks_using_notif_agent( notif_agents_dict[notif_agents_list[tnum].id]) if used_by is not None and len(used_by) > 0: task_names = [] for u in used_by: task_names.append(f"'{u.name}'") print( f"Cannot delete notification agent '{notif_agents_list[tnum].name}'. It is being used by: {','.join(task_names)}" ) print( "Delete tasks using this notification agent or remove this notification agent from those tasks first before deleting." ) else: do_delete_notif_agent(notif_agents_list[tnum].id) changes_made = True
def create_task(): if len(sources) == 0: log.error_print( "No sources found. Please add a source before creating a task") return if len(notif_agents) == 0: log.error_print( "No notification agents found. Please add a notification agent before creating a task" ) return creator.print_title("Add Task") task_creator(Task())
def edit_source(): from lib.core.state import State sources = State.get_sources() modules = State.get_source_modules() creator.print_title("Edit Source") source = creator.prompt_complex_dict("Choose a source", sources, "name", extra_options=["d"], extra_options_desc=["done"]) if source == "d": return else: source_creator(source)
def choose_task(msg, title, options_dict=None, confirm_msg=None): from lib.core.state import State tasks = State.get_tasks() creator.print_title(title) while True: tasks_list = list(tasks.values()) for i in range(len(tasks_list)): print(f"{i} - {tasks_list[i].name}") if options_dict is not None: for o in options_dict: print(f"{o} - {options_dict[o]}") tnum_str = creator.prompt_string(msg) if options_dict is not None: for o in options_dict: if re.match(tnum_str, o): return o if not re.match("[0-9]+$", tnum_str): continue tnum = int(tnum_str) if tnum < 0 and tnum >= len(tasks): continue task = tasks_list[tnum] print(task) if confirm_msg is not None: if creator.yes_no(format_task_string(confirm_msg, task)) == "n": continue print("****") print(tasks_list[tnum]) return tasks_list[tnum]
def create_notif_agent(): creator.print_title("Add Notification Agent") notif_agent_creator(NotifAgent())
def create_source(): creator.print_title("Add Source") source_creator(Source())