-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrid_plist_parser.py
92 lines (72 loc) · 2.38 KB
/
grid_plist_parser.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
92
import datetime
import json
import plistlib
import sys
'''
NOTE: This is tuned to parse only //Library/Receipts/InstallHistory.plist for
now.
'''
# Arcane crap to json encode datetimes.
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date) else None
def parsePlistFile(plist_file):
plist = plistlib.readPlist(plist_file)
if "installhistory" in plist_file.lower():
parseInstallHistoryPlist(plist)
else:
parseNetworkSettingsPlist(plist)
def parseNetworkSettingsPlist(plist):
unformatted_output = {'events':[]}
plist = plist['Signatures']
# Create an event for each item.
for i in range(0, len(plist)):
event = {}
event['start'] = plist[i]['Timestamp']
event['title'] = plist[i]['Identifier']
unformatted_output['events'].append(event)
print json.dumps(unformatted_output, default=dthandler)
def parseInstallHistoryPlist(plist):
unformatted_output = {'events':[], 'columns':[]}
col1 = {}
col1['name'] = "Install Date"
col1['id'] = "date"
col1['isDate'] = True
unformatted_output['columns'].append(col1)
col2 = {}
col2['name'] = "Install Name"
col2['id'] = "name"
col2['isDate'] = False
unformatted_output['columns'].append(col2)
col3 = {}
col3['name'] = "Version"
col3['id'] = "version"
col3['isDate'] = False
unformatted_output['columns'].append(col3)
col4 = {}
col4['name'] = "Process"
col4['id'] = "process"
col4['isDate'] = False
unformatted_output['columns'].append(col4)
col5 = {}
col5['name'] = "Packages"
col5['id'] = "packages"
col5['isDate'] = False
unformatted_output['columns'].append(col5)
# Create an event for each item.
for i in range(0, len(plist)):
event = {}
event['date'] = plist[i]['date']
event['name'] = plist[i]['displayName']
if (plist[i]['displayVersion'] == ''):
plist[i]['displayVersion'] = '-'
event['version'] = plist[i]['displayVersion']
event['process'] = plist[i]['processName']
event['packages'] = ""
for j in range(0, len(plist[i]['packageIdentifiers'])):
event['packages'] += "<div>" + plist[i]['packageIdentifiers'][j] +"</div>"
unformatted_output['events'].append(event)
print json.dumps(unformatted_output, default=dthandler)
if __name__ == '__main__':
if (len(sys.argv) < 2):
print "usage: ./plist_parser_custom.py plistfile"
sys.exit()
parsePlistFile(sys.argv[1])