-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
67 lines (49 loc) · 1.62 KB
/
utils.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
import alp
import sys
import os
import search
SETTINGS_FILE = "settings.plist"
SETTINGS_PATH = os.path.join(alp.local(), SETTINGS_FILE)
def setKeyChainPassword(password):
keychain = alp.Keychain(alp.bundle())
settings = alp.readPlist(SETTINGS_PATH)
username = settings["username"]
if settings["passwordSet"] == "true":
keychain.modifyPassword(username, password)
else:
keychain.storePassword(username, password)
settings["passwordSet"] = "true"
settings["credentialsChanged"] = "true"
alp.writePlist(settings, SETTINGS_PATH)
def getKeyChainPassword():
keychain = alp.Keychain(alp.bundle())
settings = alp.readPlist(SETTINGS_PATH)
return keychain.retrievePassword(settings["username"])
def setUserName(username):
settings = alp.readPlist(SETTINGS_PATH)
settings["username"] = username
settings["credentialsChanged"] = "true"
alp.writePlist(settings, SETTINGS_PATH)
def setUpdateDatabase():
settings = alp.readPlist(SETTINGS_PATH)
settings["updateClips"] = "true"
alp.writePlist(settings, SETTINGS_PATH)
def main():
args = sys.argv[1:]
if len(args) < 1:
print "Error"
# Check if settings file exists
search.createSettingsFile()
if args[0] == "username":
setUserName(args[1])
print "Set Username to: " + args[1]
elif args[0] == "password":
setKeyChainPassword(args[1])
print "Set Password to: " + args[1]
elif args[0] == "update":
setUpdateDatabase()
print "Clips will be updated on next search"
else:
print "Error"
if __name__ == '__main__':
main()