-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.py
More file actions
80 lines (72 loc) · 2.77 KB
/
driver.py
File metadata and controls
80 lines (72 loc) · 2.77 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
import cryptography
import login_db as DB
import sys
if len(sys.argv) < 3:
raise Exception('Not enough cmd line arguments.')
elif len(sys.argv) > 4:
raise Exception('Too many cmd line arguments.')
db_name = sys.argv[1]
admin_usr = sys.argv[2]
admin_pssd = ''
if len(sys.argv) == 4:
admin_pssd = sys.argv[3]
db = DB.login(db_name, admin_usr, admin_pssd)
while True:
usr = input('Enter usr?')
pssd = input('Enter pssd?')
try:
table = db.login(usr, pssd)
print('Successfully Logged in.')
break
except cryptography.fernet.InvalidToken:
print('Incorrect Login Information. Try again')
while True:
inp = input()
try:
cmd = inp.split()
if cmd[0] == 'search':
print(table.general_search(cmd[1]))
elif cmd[0] == 'entries':
print(table.get_entries())
elif cmd[0] == 'add':
entries = {'usr': '', 'pssd': '', 'name': '', 'url': '', 'description': ''}
for arg in cmd[1:]:
parts = arg.split('=')
if len(parts) != 2:
raise Exception('Incorrectly formatted flags')
if parts[0] in entries:
entries[parts[0]] = parts[1]
if entries[pssd] == '':
raise Exception('No passwod was entered')
entry_pssd = entries[pssd]
entries = { key: value for key, value in entries.items() if key != pssd }
table.add_entry(entry_pssd, entries)
elif cmd[0] == 'delete':
entries = { 'ID': None, 'url': None, 'name': None, 'description': None, 'usr': None, 'pssd': None }
for arg in cmd[1:]:
parts = arg.split('=')
if len(parts) != 2:
raise Exception('Incorrectly formatted flags')
if parts[0] in entries:
entries[parts[0]] = parts[1]
table.delete(**entries)
elif cmd[0] == 'edit':
entries = { 'ID': None, 'url': None, 'name': None, 'description': None, 'usr': None, 'pssd': None,
'new_url': None, 'new_name': None, 'new_description': None, 'new_usr': None, 'new_pssd': None }
for arg in cmd[1:]:
parts = arg.split('=')
if len(parts) != 2:
raise Exception('Incorrectly formatted flags')
if parts[0] in entries:
entries[parts[0]] = parts[1]
executed = table.edit(**entries)
if executed:
print('Successfully edited')
else:
print('Too many or no matches to search')
elif cmd[0] == 'exit':
break
else:
raise Exception()
except:
print(f'Your input of "{inp}" is incorrectly formatted.')