コード例 #1
0
ファイル: notif_agent.py プロジェクト: himay81/Trackyr
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
コード例 #2
0
def save():
    from lib.core.state import State
    State.save_tasks()