def removed_link(key_first_task, key_second_task): try: manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) manager.delete_link(key_first_task, key_second_task) print("Link between task N{0} and N{1} was removed".format( key_first_task, key_second_task)) except Exception as e: print(e)
def add_member(key_task, name_user): try: manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) manager.add_member_in_task(key_task, name_user) print("User '{0}' was added how member to task N{1}".format( name_user, key_task)) except Exception as e: print(e)
def remove_admin(key_task, name_user): try: manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) manager.delete_admin_in_task(key_task, name_user) print("User '{0}' was removed how admin to task N{1}".format( name_user, key_task)) except Exception as e: print(e)
def delete_task(key_task): try: manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) manager.delete_task(key_task) print("Task N{0} and subtasks was removed".format(key_task)) except Exception as e: print(e)
def view_messages_user(name_user): manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) messages = manager.get_message_user(name_user) if messages: for mes in messages: print(mes) else: not_found_user(name_user)
def view_all_users(): """Output name all users mentioned in Task.admins and Task.members""" manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) users = manager.get_all_users() if users: for user in users: print(user) else: print("No users")
def view_all_tasks(): manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) tasks = manager.get_all_tasks() if tasks: for task in tasks: print(task) manager.save_task(task) else: print("No tasks")
def main(): Config.set_new_config_path( os.path.dirname(__file__) + '/configuration.txt') my_logger = Logger(path_to_logger_output=Config.get_logger_output_path()) if Config.get_status_logger(): my_logger.on_logger() else: my_logger.off_logger() parser = create_parser() run_namespace(parser, my_logger)
def finish_task(key_task): """Set status task = ended""" manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) task = manager.get_task(key_task) if task: task.status = "ended" print("Task N{0} was completed".format(key_task)) manager.save_task(task) else: not_found_task(key_task)
def removed_all_links(key_task): try: manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) task = manager.get_task(key_task) if not task: raise Exception("Task N{0} not found in file".format(key_task)) linked_task = task.links.copy() manager.save_task(task) for link in linked_task: removed_link(key_task, link) except Exception as e: print(e)
def remove_user(name_user): manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) tasks = manager.get_user_task(name_user) if tasks: for task in tasks: if name_user in task.admins: task.admins.remove(name_user) if name_user in task.members: task.members.remove(name_user) manager.save_task(task) print("User '{0}' was removed".format(name_user)) else: not_found_user(name_user)
def view_all_project(): """Ouput information each task with its sutasks, admins and members""" manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) keys_tasks = manager.get_keys_tasks() if keys_tasks: number_project = 0 for key_task in keys_tasks: task = manager.get_task(key_task) if not task.parent: q = deque() q.append(task) list_tasks_project = [task] queue_on_project(q, list_tasks_project, manager) number_project += 1 print("Project N" + str(number_project)) admins = set() members = set() for project_task in list_tasks_project: for user in project_task.admins: admins.add(user) for user in project_task.members: members.add(user) print("Admins:") for admin in admins: print(admin, end=" ") print("\nMembers:") for member in members: print(member, end=" ") print("\n\nTasks:") for project_task in list_tasks_project: print(project_task) print("\n") manager.save_task(task) else: print("No projects")
def view_task_user(name_user, more_information=False): """View all task when thiw user was mentioned. If view=True displays more information about task""" manager = Manager(Config.get_tasks_file(), Config.get_messages_file()) tasks = manager.get_user_task(name_user) if tasks: admin_task = [] member_task = [] for task in tasks: if name_user in task.admins: admin_task.append(task.key) if name_user in task.members: member_task.append(task.key) manager.save_task(task) print("Admin in tasks: ") for key_task in admin_task: print(key_task, end=" ") print("\nMember in task: ") for key_task in member_task: print(key_task, end=" ") if more_information: print("\n") priority_tasks = [] for key_task in set(admin_task + member_task): priority_tasks.append(manager.get_task(key_task)) for task in sorted(priority_tasks, key=lambda x: x.priority, reverse=True): manager.save_task(task) view_task(task.key) print() else: print("No task this user")
def change_status_logger(status): """ON/OFF logger""" Config.set_status_logger(status) print("Status logger was changed on {}".format(status))