-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
495 lines (474 loc) · 17.6 KB
/
Copy pathcli.py
File metadata and controls
495 lines (474 loc) · 17.6 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
from app import *
import sys
import string
class CLI:
def __init__(self):
self._app = App()
def start_programm(self):
print(
"""Hello, welcome to the TaskManager CLI! \n
-------------------------------------------------------------\n
To interact with this CLI,
please enter the character in the brackets,\n
e.g. [s] save: press 's' if you want to save"""
)
try:
self._app.load_app()
except:
pass
self._user_overview()
def _user_overview(self):
while True:
if self._app.is_empty():
entry = input(
"""There are no Users yet.
Please insert [1] to add a new User
or [s] to save the programm."""
)
try:
entry == 1 or entry == "s"
except ValueError:
print(
"""Please insert a valid command. \n
[1] create a new user \
[s] save programm"""
)
continue
if entry == "s":
self._app.save_app()
continue
elif entry == "1":
self._create_user()
continue
else:
continue
else:
print(
"""Here is an User overview. \n
Select a User by entering its number.\n
If you want to create a new User, please insert [n]. \n
If you want to save the programm, please insert [s]."""
)
print(self._app)
user = input()
if user == "n":
self._create_user()
continue
elif user == "s":
self._app.save_app()
try:
int(user)
except:
print("{} is no valid entry.".format(user))
continue
try:
self._get_selected_user(user)
except IndexError:
print("{} is no valid entry.".format(user))
continue
sel = input(
"""Your selected User is: {}.\n
Options: [1] select the User \
[2] edit the User \
[3] delete the User""".format(
self._selected_user.name
)
)
try:
int(sel)
except:
print("{} is no valid entry.".format(sel))
continue
selection = int(sel)
if selection == 1:
self._select_user()
elif selection == 2:
self._edit_user()
continue
elif selection == 3:
self._delete_user()
continue
else:
continue
def _get_selected_user(self, number):
num = int(number)
self._selected_user = self._app.projectmanagers[num]
def _create_user(self):
while True:
user_name = input("Please insert the User name: ")
print(
"""User name: {}. \n
If you want to save the User name, please insert [s]\n
If you want to change the User name,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
user_name
)
)
entry = input()
if entry == "s":
self.new_user = self._app.create_projectmanager()
self.new_user.name = user_name
break
elif entry == "c":
break
else:
continue
def _edit_user(self):
while True:
print("Current User name: {}".format(self._selected_user))
user_name = input("Please insert a new User name")
print(
"""User name: {}. \n
If you want to save the User name, please insert [s]\n \
If you want to change the User name,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
user_name
)
)
entry = input()
if entry == "s":
self._selected_user.name = user_name
break
elif entry == "c":
break
else:
continue
def _delete_user(self):
self._app.delete_projectmanager(self._selected_user)
self._selected_user = None
def _select_user(self):
while True:
if self._selected_user.is_empty():
print(
"""There are no Projects yet. \n
Please insert [1] to add a new Project."""
)
entry = input()
try:
entry == 1 or entry == "s"
except ValueError:
print(
"""Please insert a valid command. \n
[1] create a new project \
[s] save programm"""
)
continue
if entry == "s":
App.save_app()
continue
elif entry == "1":
self._create_project()
continue
else:
continue
else:
print(
"""Here is a Project overview. \n
Select a Project by entering its number.\n
If you want to create a new Project,
please insert [n]. \n
If you want to go back to User Overview,
please insert [u]. \n
If you want to save the programm, please insert [s]."""
)
print(self._selected_user)
pro = input()
if pro == "n":
self._create_project()
continue
elif pro == "u":
break
elif pro == "s":
self._app.save_app()
continue
try:
int(pro)
except:
print("{} is no valid entry.".format(pro))
continue
try:
self._get_selected_project(pro)
except IndexError:
print("{} is no valid entry.".format(pro))
continue
sel = input(
"""Your selected Project is: {}.\n
Options: [1] select the Project \
[2] edit the Project \
[3] delete the Project""".format(
self._selected_project.name
)
)
try:
int(sel)
except:
print("{} is no valid entry.".format(sel))
continue
selection = int(sel)
if selection == 1:
self._select_project()
continue
elif selection == 2:
self._edit_project()
continue
elif selection == 3:
self._delete_project()
continue
else:
continue
def _get_selected_project(self, number):
num = int(number)
self._selected_project = self._selected_user.projects[num]
def _create_project(self):
while True:
pro_name = input("Please insert the Project name: ")
pro_notes = input("Please insert Project notes: ")
print(
"""Project name: {}. \n
Project notes: {} \n
If you want to save the Project name, please insert [s]\n
If you want to change the Project name,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
pro_name, pro_notes
)
)
entry = input()
if entry == "s":
self.new_pro = self._selected_user.create_project()
self.new_pro.name = pro_name
self.new_pro.notes = pro_notes
break
elif entry == "c":
break
else:
continue
def _edit_project(self):
while True:
print(
"""Current Project name: {} \n
Current Project notes: {}
""".format(
self._selected_project.name, self._selected_project.notes
)
)
pro_name = input(
"""Please insert a new Project name.\n
If you do not want to change the name, insert [x]."""
)
pro_notes = input(
"""Please insert Project notes: \n
If you do not want to change the notes, insert [x]."""
)
if pro_name == "x":
pro_name = self._selected_project.name
if pro_notes == "x":
pro_notes = self._selected_project.notes
print(
"""Project name: {}. \n
Project notes: {} \n
If you want to save the changes, please insert [s]\n
If you want to change again,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
self._selected_project.name, self._selected_project.notes
)
)
entry = input()
if entry == "s":
self._selected_project.name = pro_name
self._selected_project.notes = pro_notes
break
elif entry == "c":
break
else:
continue
def _delete_project(self):
self._selected_user.delete_project(self._selected_project)
self._selected_project = None
def _select_project(self):
while True:
if self._selected_project.is_empty():
print(
"""There are no Tasks yet. \n
Please insert [1] to add a new Task."""
)
entry = input()
try:
entry == 1 or entry == "s"
except ValueError:
print(
"""Please insert a valid command. \n
[1] create a new project \
[s] save programm"""
)
continue
if entry == "s":
App.save_app()
continue
elif entry == "1":
self._create_task()
continue
else:
continue
else:
print(
"""Here is a Task overview. \n
Select a Task by entering its number.\n
If you want to create a new Task, please insert [n]. \n
If you want to save the programm, please insert [s]. \n
If you want to go back to the Project Overview,
please insert [p]."""
)
print(self._selected_project)
task = input()
if task == "n":
self._create_project()
continue
elif task == "p":
break
elif task == "s":
self._app.save_app()
continue
try:
int(task)
except:
print("{} is no valid entry.".format(task))
continue
try:
self._get_selected_task(task)
except IndexError:
print("{} is no valid entry.".format(task))
continue
sel = input(
"""Your selected Task is: {}.\n
Options: [1] change Task state \
[2] edit the Task \
[3] delete the Task""".format(
self._selected_task.name
)
)
try:
int(sel)
except:
print("{} is no valid entry.".format(sel))
continue
selection = int(sel)
if selection == 1:
self._change_state()
continue
elif selection == 2:
self._edit_task()
continue
elif selection == 3:
self._delete_task()
continue
else:
continue
def _get_selected_task(self, number):
num = int(number)
self._selected_task = self._selected_project.tasks[num]
def _change_state(self):
if self._selected_task.state == 0:
self._selected_task.do_task()
elif self._selected_task.state == 1:
self._selected_task.undo_task()
def _create_task(self):
while True:
task_name = input("Please insert the Task name: ")
task_notes = input("Please insert Task notes: ")
task_prio = input(
"""Please insert Task Priority:\n
[0] none \
[1] low \
[2] medium \
[3] high"""
)
task_priority = find_priority(task_prio)
print(
"""Task name: {}. \n
Task notes: {} \n
Task priority: {} \n
If you want to save the Task name, please insert [s]\n
If you want to change the Task name,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
task_name, task_notes, task_priority
)
)
entry = input()
if entry == "s":
self.new_task = self._selected_project.create_task()
self.new_task.name = task_name
self.new_task.notes = task_notes
self.new_task.priority = task_priority
break
elif entry == "c":
break
else:
continue
def _edit_task(self):
while True:
print(
"""Current Task name: {} \n
Current Task notes: {} \n
Current Task priority: {} \n
""".format(
self._selected_task.name,
self._selected_task.notes,
self._selected_task.priority,
)
)
task_name = input(
"""Please insert a new Task name.\n
If you do not want to change the name, insert [x]."""
)
task_notes = input(
"""Please insert new Task notes: \n
If you do not want to change the notes, insert [x]."""
)
task_priority = input(
"""Please insert a new Task priority: \n
[0] none \
[1] low \
[2] medium \
[3] high \n
If you do not want to change the priority, insert [x]."""
)
if task_name == "x":
task_name = self._selected_task.name
if task_notes == "x":
task_notes = self._selected_task.notes
if task_priority == "x":
task_priority = self._selected_task.priority
print(
"""Task name: {}. \n
Task notes: {} \n
Task priority: {} \n
If you want to save the changes, please insert [s]\n
If you want to change again,
please insert any character EXCEPT [s] and [c] \n
If you want to cancel, please insert [c].""".format(
self._selected_task.name,
self._selected_task.notes,
self._selected_task.priority,
)
)
entry = input()
if entry == "s":
self._selected_task.name = task_name
self._selected_task.notes = task_notes
self._selected_task.priority = task_priority
break
elif entry == "c":
break
else:
continue
def _delete_task(self):
self._selected_project.delete_task(self._selected_task)
self._selected_task = None
if __name__ == "__main__":
cli = CLI()
cli.start_programm()