forked from MLSA-SRM/Python-CLIK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_functions.py
91 lines (70 loc) · 2.25 KB
/
menu_functions.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
from utils import message, debug, init_default_key_storage, printy, STORAGE_DIR, STORE_KEY_F
from json_convert import jsonToDict, dictToJson, display_json
def add(fileName):
dictkeys = jsonToDict(fileName)
def getKeyValue(keyName):
key = message.prompt(keyName + ' value')
if(key!=''):
dictkeys[keyName] = key
elif(key==''):
message.error('Value cannot be empty.')
getKeyValue(keyName)
while(True):
keyName = message.prompt('Key (done)')
if(keyName!=''):
getKeyValue(keyName)
elif (keyName==''):
break
try:
dictToJson(dictkeys, fileName)
message.success('New keys added successfully!')
except:
message.error('Some error occured!')
return False
def subtract(fileName):
dictkeys = jsonToDict(fileName)
def removeKeyValue(keyName):
try:
del dictkeys[keyName]
except:
message.error('No such Key exists!')
while(True):
keyName = message.prompt('Enter Key to be removed (done)')
if(keyName!=''):
removeKeyValue(keyName)
elif (keyName==''):
break
try:
dictToJson(dictkeys, fileName)
message.success('Keys removed successfully!')
except:
message.error('Some error occured!')
return False
def modify(fileName):
dictkeys = jsonToDict(fileName)
def modifyKeyValue(keyName):
if keyName in dictkeys:
key = message.prompt(keyName + ' new value')
if(key!=''):
dictkeys[keyName] = key
elif(key==''):
message.error('Value cannot be empty.')
getKeyValue(keyName)
else:
message.error('No such Key exists!')
while(True):
keyName = message.prompt('Enter Key to be modified (done)')
if(keyName!=''):
modifyKeyValue(keyName)
elif (keyName==''):
break
try:
dictToJson(dictkeys,fileName)
message.success('Keys modified successfully!')
except:
message.error('Some error occured!')
return False
#test functions
#add(fileName)
#subtract(fileName)
#modify(fileName)