1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 __all__ = ['kwallet_available', 'kwallet_get', 'kwallet_put']
23
24 import subprocess
25
26
28 """
29 Return True if kwalletcli can be run, False otherwise
30 """
31 try:
32 p = subprocess.Popen(["kwalletcli", "-qV"])
33 except Exception:
34 return False
35 p.communicate()
36 if p.returncode == 0:
37 return True
38 return False
39
40
42 """
43 Retrieve a passphrase from the KDE Wallet via kwalletcli
44
45 Arguments:
46 • folder: The top-level category to use (normally the programme name)
47 • entry: The key of the entry to retrieve
48
49 Returns the passphrase as unicode, False if it cannot be found,
50 or None if an error occured.
51 """
52 p = subprocess.Popen(["kwalletcli", "-q", "-f", folder.encode('utf-8'),
53 "-e", entry.encode('utf-8')], stdout=subprocess.PIPE)
54 pw = p.communicate()[0]
55 if p.returncode == 0:
56 return unicode(pw.decode('utf-8'))
57 if p.returncode == 1 or p.returncode == 4:
58
59 return False
60
61 return None
62
63
65 """
66 Store a passphrase into the KDE Wallet via kwalletcli
67
68 Arguments:
69 • folder: The top-level category to use (normally the programme name)
70 • entry: The key of the entry to store
71 • passphrase: The value to store
72
73 Returns True on success, False otherwise.
74 """
75 p = subprocess.Popen(["kwalletcli", "-q", "-f", folder.encode('utf-8'),
76 "-e", entry.encode('utf-8'), "-P"], stdin=subprocess.PIPE)
77 p.communicate(passphrase.encode('utf-8'))
78 if p.returncode == 0:
79 return True
80 return False
81