-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.py
148 lines (131 loc) · 5.16 KB
/
utility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pickle # Import the pickle module for object serialization
from termcolor import colored # Import the colored function from termcolor module
import os # Import the os module for file operations
class Task:
def __init__(self, task_name, assignee, reporter, deadline, priority):
# Initialize task attributes
self.task_name = task_name
self.assignee = assignee
self.reporter = reporter
self.deadline = deadline
self.priority = priority
def add_status_field(self, field_name, field_value):
# Method to add additional status fields to a task
setattr(self, field_name, field_value)
def display(self):
# Method to display task details
print("Task:", self.task_name)
print("Assignee:", self.assignee)
print("Reporter:", self.reporter)
print("Deadline:", self.deadline)
print("Priority: ", self.priority)
class Kanban:
def __init__(self, name):
# Initialize Kanban board attributes
self.name = name
self.task_list = []
def display_tasks(self):
# Display tasks in the Kanban board
if len(self.task_list) != 0:
# Sort tasks by priority
priority_order = {"high": 3, "medium": 2, "low": 1}
self.task_list.sort(key=lambda x: priority_order.get(x.priority.lower(), 0), reverse=True)
for i in self.task_list:
print()
i.display()
else:
print("No Tasks Here")
def display(self, color):
# Display Kanban board with colored header
print()
print("--------------------------------------------------------------------")
print(colored(self.name, color))
self.display_tasks()
print("--------------------------------------------------------------------")
print()
def move_task(self, task_name, destination_board):
# Move task from current board to destination board
task = self.find_task(task_name)
if task:
destination_board.task_list.append(task)
self.task_list.remove(task)
print(f"Task '{task_name}' moved to {destination_board.name}")
else:
print(f"Task '{task_name}' not found in {self.name}")
def find_task(self, task_name):
# Find task in the Kanban board
for task in self.task_list:
if task.task_name == task_name:
return task
return None
def remove_task(self, task_name):
# Remove task from the Kanban board
task = self.find_task(task_name)
if task:
self.task_list.remove(task)
print(f"Task '{task_name}' removed from {self.name}")
else:
print(f"Task '{task_name}' not found in {self.name}")
def create_task():
# Create a new task with user input
name = input("Enter Task Name: ")
assignee = input("Enter Task Assignee: ")
reporter = input("Enter Task Reporter: ")
deadline = input("Enter Task Deadline: ")
while True:
priority = input("Enter Task Priority (high/medium/low): ").lower()
if priority in {"high", "medium", "low"}:
break
else:
print("Invalid priority. Please enter 'high', 'medium', or 'low'.")
print()
return Task(name, assignee, reporter, deadline, priority)
def display_kanban_boards(todo, prog, done):
# Display all Kanban boards
todo.display("red")
prog.display("yellow")
done.display("green")
def save_data(todo, prog, done):
# Save Kanban board data to file using pickle
with open("kanban_data.pickle", "wb") as f:
pickle.dump((todo, prog, done), f)
def load_data():
# Load Kanban board data from file
try:
with open("kanban_data.pickle", "rb") as f:
return pickle.load(f)
except FileNotFoundError:
print("No previous data found.")
return None, None, None
def move_task_between_boards(todo, prog, done):
# Move task between Kanban boards
task_name = input("Enter task name to move: ")
source_board_name = input("Enter source board (TODO, In Progress, Done): ")
destination_board_name = input("Enter destination board (TODO, In Progress, Done): ")
source_board = None
destination_board = None
if source_board_name.lower() == "todo":
source_board = todo
elif source_board_name.lower() == "in progress":
source_board = prog
elif source_board_name.lower() == "done":
source_board = done
else:
print("Invalid source board.")
if destination_board_name.lower() == "todo":
destination_board = todo
elif destination_board_name.lower() == "in progress":
destination_board = prog
elif destination_board_name.lower() == "done":
destination_board = done
else:
print("Invalid destination board.")
if source_board and destination_board:
source_board.move_task(task_name, destination_board)
def wipe_data():
# Wipe Kanban board data by removing the pickle file
try:
os.remove("kanban_data.pickle")
print("Data wiped successfully.")
except FileNotFoundError:
print("No data file found.")