-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Plist.py
executable file
·40 lines (31 loc) · 996 Bytes
/
Plist.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
#!/usr/bin/env python3
# encoding: utf-8
import plistlib
class Plist:
def __init__(self):
self.info = self.readPlist('info.plist')
def deleteVariable(self, variable):
try:
del self.info['variables'][variable]
self.writePlist(self.info, 'info.plist')
except KeyError:
pass
def getConfig(self):
return self.info['variables']
def getVariable(self, variable):
try:
return self.info['variables'][variable]
except KeyError:
pass
@staticmethod
def readPlist(filepath):
with open(filepath, 'rb') as fp:
plistData = plistlib.load(fp)
return plistData
def setVariable(self, variable, value):
self.info['variables'][variable] = value
self.writePlist(self.info, 'info.plist')
@staticmethod
def writePlist(dataObject, filepath):
with open(filepath, 'wb') as fp:
plistlib.dump(dataObject, fp)