-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand.py
More file actions
468 lines (439 loc) · 18.5 KB
/
command.py
File metadata and controls
468 lines (439 loc) · 18.5 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
# from base import Base
from user import User
from task import Task
from group import Group
import os
groupname_to_group = {'groupname1':Group('groupname1')}
username_to_user = {'name1': User('name1','000',[groupname_to_group['groupname1']])}
current_user = None
current_group = None
def register():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
while True:
username = input('username: ')
if username in username_to_user:
print('Sorry, this username has already been taken!')
else: break
while True:
password = input('password: ')
confirm_password = input('confirm_password: ')
if password!=confirm_password:
print('Password does not match, please type again')
else: break
while True:
print('username: ',username)
print('password: ',password)
print('1. Confirm')
print('2. Deny')
confirm = input('')
if confirm == '1': return username,password
elif confirm == '2': break
else: continue
def signin():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
username = input('username: ')
password = input('password: ')
if username not in username_to_user :
print('Invalid username or password:')
print('No user found! Maybe you want to register?')
else:
user = username_to_user[username]
if not user.check_password(password):
print('Invalid username or password:')
print('Incorrect password')
else: break
return user
def main_page():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
# if current_group:
current_group = None
# comment because not working
# os.system('clr')
# os.system('clear')
print("Welcome,", current_user.username)
if current_user.groups != []:
print("Groups: ")
i = 1
for group in current_user.groups:
print(' '+str(i)+'.',group.groupname)
i+=1
print("Options: ")
print(" 1. Choose a Group")
print(" 2. New Group")
print(" 3. Delete Group")
print(" 4. Settings")
print(" 5. Log Out")
option = input('Enter an option: ')
if option == "1": choose_group()
elif option == "2": new_group()
elif option == "3": delete_group()
elif option == "4": the_settings()
elif option == "5": welcome()
else: print('Please Enter a valid option:'); continue
else:
print("Options: ")
print(" 1. New Group")
print(" 2. Settings")
print(" 3. Log Out")
option = input('Enter an option: ')
if option == "1": new_group()
elif option == "2": the_settings()
elif option == "3": welcome()
else: print('Please Enter a valid option:'); continue
def choose_group():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
groupname = input("Enter a group: ")
if groupname == '':
return
elif groupname not in groupname_to_group:
print("Group cannot be found, please enter an existing group, or press Enter to go back.")
continue
else:
while True:
current_group = groupname_to_group[groupname]
if current_group.tasks == []: print("All the tasks are done, yay!")
else:
print('Tasks in',current_group.groupname,'are:')
for i_,t_ in enumerate(current_group.tasks):
print(' ',str(i_),'.',t_.taskname)
print("Options: ")
print(" 1. Create a task")
print(" 2. View a task")
print(" 3. Complete a task")
print(" 4. Remove a task")
print(" 5. Invite")
print(" 6. Remove member")
print(" 7. Return to main page")
option = input("Enter an option: ")
if option == "1":
create_task()
# elif current_group.tasks == []:
# print("All the tasks are done, yay!")
# continue
elif option == '2':
op_task = None
while op_task!='3':
print('Tasks in',current_group.groupname,'are:')
for i_,t_ in enumerate(current_group.tasks):
print(' ',str(i_),'.',t_.taskname)
task_num = input('Enter a task number: ')
if task_num == '': break
try:
read_only_task = current_group.tasks[task_num]
except:
print('Please enter a valid task number or press Enter to return.')
continue
print(read_only_task)
print('The task information is as the above,')
while True:
print("Options: ")
print(" 1. Modify this task")
print(" 2. View another task")
print(" 3. Return to group page")
op_task = input('Enter an option: ')
if op_task == "1":
t_name = read_only_task.taskname
t_due_date = read_only_task.due_date
t_description = read_only_task.description
t_divisions = read_only_task.divisions
t_add_date = read_only_task.add_date
create_task(t_name, t_due_date, t_description, t_divisions, t_add_date)
elif op_task == '2':
break
elif op_task == '3':
break
else:
print('Please enter a valid option: ')
elif option == '3':
if current_group.tasks == []:
print("All the tasks are done, yay!")
continue
cp_task = None
while cp_task != '2':
print('Tasks in',current_group.groupname,'are:')
for i_,t_ in enumerate(current_group.tasks):
print(' ',str(i_),'.',t_.taskname)
task_num = input('Enter a task number: ')
if task_num == '': break
try:
read_only_task = current_group.tasks[task_num]
except:
print('Please enter a valid task number or press Enter to return.')
continue
current_group.complete_task(read_only_task,current_user)
while True:
print("Options: ")
print(" 1. Complete another task")
print(" 2. Return to group page")
cp_task = input('Enter an option: ')
if cp_task in '12':
break
else:
print("Please enter a valid option: ")
elif option == '4':
if current_group.tasks == []:
print("All the tasks are done, yay!")
continue
rm_task = None
while rm_task != '2':
print('Tasks in',current_group.groupname,'are:')
for i_,t_ in enumerate(current_group.tasks):
print(' ',str(i_),'.',t_.taskname)
task_num = input('Enter a task number: ')
if task_num == '': break
try:
read_only_task = current_group.tasks[task_num]
except:
print('Please enter a valid task number or press Enter to return.')
continue
current_group.delete_task(read_only_task)
while True:
print("Options: ")
print(" 1. Remove another task")
print(" 2. Return to group page")
rm_task = input('Enter an option: ')
if rm_task in '12':
break
else:
print("Please enter a valid option: ")
elif option == '5':
invitee = input("Please enter invitee's username: ")
if invitee not in username_to_user:
print("Invitee not found!")
else:
current_user.invite(username_to_user[invitee], current_group)
elif option == "6": print("Remove member still work in progress.")
elif option == "7": return
else: print('Please Enter a valid option:'); continue
def create_task(taskname = None, due_date = [], description = None, divisions = [],add_date=None):
global groupname_to_group
global username_to_user
global current_user
global current_group
if taskname != None:
for task in current_group.tasks:
if task.taskname == taskname:
current_group.delete_task(task)
break
while True:
print("Options: ")
print(" 1. Task name: " + str(taskname))
print(" 2. Due date: " + '/'.join(due_date))
print(" 3. Description: " + str(description))
print(" 4. Divisions:\n " +"\n ".join(divisions))
print(" 5. Confirm task")
print(" 6. Return to main group")
option = input("Enter an option: ")
if option == "1":
while True:
new_taskname = input('task name: ')
if new_taskname in current_group.tasks:
print("The task "+new_taskname+" has already existed, please enter a different taskname.")
else:
confirm = input('Update task name "'+new_taskname+'"? y/n')
if confirm == "y":
taskname = new_taskname
break
elif option == "2":
while True:
new_due_date = input('due date(YYYY/MM/DD/hh/mm): ')
try:
new_due_date = new_due_date.split('/')
confirm = input('Update due date'+ '/'.join(new_due_date) +'? y/n')
if confirm == "yes":
due_date = new_due_date
break
except:
print("The due date is invalid.")
elif option == "3":
new_description = input('task description: ')
confirm = input('Update task description? y/n')
if confirm == "y":
description = new_description
break
elif option == "4":
while len(divisions) != 0:
print("Options: ")
print(" 1. Add to current divisions")
print(" 2. Rewrite the division")
print(" 3. Back")
division_option = input('Enter an option: ')
if division_option == '1':
new_divisions = divisions
elif division_option == '2':
new_divisions = []
elif division_option == '3': break
else: print('Please Enter a valid option:'); continue
while not division_option == '3':
if len(new_divisions)==0: print('Current divisions is empty')
else:
print('Current divisions has:')
for d in new_divisions:
print(' ',', '.join([u_.usernames for u_ in d]))
print("Group Members")
for i, u in enumerate(current_group.users):
print(i,".",u.username)
usernames = input("Please choose a divition from group members(i.e. a,b,c): ")
try:
usernames = usernames.split(',')
add = input('Adding '+ usernames + " as one division? y/n")
if add == 'n': continue
except:
print('Some usernames are not in the group')
users_ = set([username_to_user[username_] for username_ in usernames])
new_divisions.append(users_)
print('Current divisions has: ')
for d in new_divisions:
print(', '.join([u_.usernames for u_ in d]))
confirm_division = input('Add more divisions? y/n')
if confirm_division == 'n':
divisions = new_divisions
elif option == "5":
confirm = input('Update the task? y/n')
if confirm == "n": continue
if divisions == []:
print('Must assign divisions to the task')
continue
else:
current_task = Task(taskname,description,current_group,due_date,divisions,add_date = add_date)
current_user.add_task(current_group,current_task)
current_group.add_task(current_task)
break
elif option == "6":
return
else: print('Please enter a valid option:'); continue
def new_group():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
print("Options: ")
print(" 1. Create a group")
print(" 2. Enter a group")
print(" 3. Return to main page")
choice = input("Enter an option: ")
if choice == '1':
while True:
new_groupname = input('New Groupname:')
if new_groupname == '':break
elif new_groupname not in groupname_to_group:
new_group = Group(new_groupname)
new_group.add_user(current_user)
groupname_to_group[new_groupname] = new_group
return
else:
print('The groupname exists or is in valid, please try again or press Enter to return.')
elif choice == '2':
while True:
e_groupname = input('Groupname:')
if e_groupname == '': break
elif e_groupname in groupname_to_group:
current_user.enter_group(groupname_to_group[e_groupname])
return
else:
print('Please enter an existing groupname or press Enter to return.')
elif choice == '3':
return
else:
print('Please enter a valid option:')
continue
def delete_group():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
print("Groups: ")
i = 1
for group in current_user.groups:
print(' '+str(i)+'.',group.groupname)
i+=1
group_num = input('Please enter the number of the group to be deleted: ')
if group_num == '': return
try:
read_only_group = current_user.groups[int(group_num)]
except:
print('Please enter a valid group number or press Enter to exit.')
continue
dl_group_name = current_user.groups.pop(group_num)
del groupname_to_group[dl_group_name]
return
def the_settings():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
print("Options: ")
print(" 1. Change username")
print(" 2. Change password")
print(" 3. Return to main page")
choice = input("Enter an option: ")
if choice == '1':
while True:
new_username = input('Enter the modified username: ')
if new_username == '': break
elif new_username not in username_to_user:
old_ = current_user.username
current_user.change_username(old_, new_username)
username_to_user[new_username] = current_user
del username_to_user[old_]
current_user = username_to_user[new_username]
return
else:
print('The new username has been occupied, please try again or press Enter to return.')
elif choice == '2':
while True:
old_pw = input('Current password: ')
if current_user.check_password(old_pw):
new_pw = input('New password: ')
cf_pw = input('confirm password: ')
if new_pw != cf_pw:
print('The passwords is inconsistant')
continue
else:
current_user.change_password(old_pw,new_pw)
return
else: print('The password is incorrect')
elif choice == '3':
return
else:
print('Please enter a valid option:'); continue
def welcome():
global groupname_to_group
global username_to_user
global current_user
global current_group
while True:
print("Welcome to Assignment Due")
print("1.register")
print("2.log in")
print("3.exit")
choice = input("choose a number: ")
if choice == '1':
username,password = register()
current_user = User(username,password)
username_to_user[username] = current_user
elif choice == '2':
current_user = signin()
main_page()
else: break
if __name__ == "__main__":
welcome()