forked from chilcote/pylab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpysystemprofiler.py
executable file
·229 lines (199 loc) · 8.47 KB
/
pysystemprofiler.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python
'''
This script collects data from system_profiler
'''
##############################################################################
# Copyright 2014 Joseph Chilcote
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##############################################################################
import os, sys, subprocess
import plistlib
from pprint import pprint
class SystemProfiler(object):
'''This object returns dictionaries of data from system_profiler'''
def __init__(self):
pass
def get_data(self, category):
'''This method is called by all the get methods to gather
category specific system_profiler data'''
cmd = '/usr/sbin/system_profiler', category, '-xml'
task = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = task.communicate()
plist = plistlib.readPlistFromString(out)[0]
return plist
def get_SPStorageDataType(self):
'''Returns a dict containing storage device data'''
d = self.get_data('SPStorageDataType')['_items']
if 'com.apple.corestorage.lvg' in d:
return d['_items']['com.apple.corestorage.lvg'][0]
return d[0]
def get_SPHardwareDataType(self):
'''Returns a dict containing hardware data'''
d = self.get_data('SPHardwareDataType')['_items']
return d[0]
def get_SPUniversalAccessDataType(self):
'''Returns a dict containing universal access data'''
d = self.get_data('SPUniversalAccessDataType')['_items']
return d[0]
def get_SPDeveloperToolsDataType(self):
'''Returns a dict containing dev tools data'''
d = self.get_data('SPDeveloperToolsDataType')['_items']
return d[0]
def get_SPConfigurationProfileDataType(self):
'''Returns a dict containing configuration profile data'''
d = self.get_data('SPConfigurationProfileDataType')
print type(d)
if d['_items']:
return d['_items'][0]['_items'][0]
return {}
def get_SPInstallHistoryDataType(self):
'''Returns a dict containing install history data'''
d = self.get_data('SPInstallHistoryDataType')['_items']
d1 = {}
for item in d:
d1[item['_name']] = item['install_date']
return d1
def get_SPDiagnosticsDataType(self):
'''Returns a dict containing diagnostic data'''
d = self.get_data('SPDiagnosticsDataType')['_items']
return d[0]
def get_SPFirewallDataType(self):
'''Returns a dict containing firewall data'''
d = self.get_data('SPFirewallDataType')['_items']
return d[0]
def get_SPDisplaysDataType(self):
'''Returns a dict containing display data'''
d = self.get_data('SPDisplaysDataType')['_items']
return d[0]
def get_SPNetworkLocationDataType(self):
'''Returns a dict containing network location data'''
d = self.get_data('SPNetworkLocationDataType')['_items']
return d[0]['spnetworklocation_services'][0]
def SPManagedClientDataType(self):
'''Returns a dict containing managed client data'''
d = self.get_data('SPManagedClientDataType')['_items']
if d:
return d[0]['_items'][0]
return {}
def get_SPMemoryDataType(self):
'''Returns a list of dicts containing memory module data'''
d = self.get_data('SPMemoryDataType')['_items']
l = []
for item in d[0]['_items']:
l.append(item)
return l
def get_SPNetworkDataType(self):
'''Returns a list of dicts containing network interface data'''
d = self.get_data('SPNetworkDataType')['_items']
l = []
for item in d:
l.append(item)
return l
def get_SPPowerDataType(self):
'''Returns a dict containing power data'''
d = self.get_data('SPPowerDataType')['_items']
d1 = {}
for item in d:
d1.update(item)
return d1
def get_SPPrefPaneDataType(self):
'''Returns a list of dicts containing pref pane data'''
d = self.get_data('SPPrefPaneDataType')['_items']
l = []
for item in d:
l.append(item)
return l
def get_SPPrintersDataType(self):
'''Returns a list of dicts containing printer data'''
d = self.get_data('SPPrintersDataType')['_items']
l = []
for item in d:
l.append(item)
return l
def get_SPSerialATADataType(self):
'''Returns a dict containing sata data'''
d = self.get_data('SPSerialATADataType')['_items']
return d[0]['_items'][0]
def get_SPSoftwareDataType(self):
'''Returns a dict containing system software data'''
d = self.get_data('SPSoftwareDataType')['_items']
return d[0]
def get_SPNetworkVolumeDataType(self):
'''Returns a list of dicts network volume data'''
d = self.get_data('SPNetworkVolumeDataType')['_items']
l = []
for item in d:
l.append(item)
return l
def get_SPAirPortDataType(self):
'''Returns a dict containing airport data'''
d = self.get_data('SPAirPortDataType')['_items']
d1 = {}
for item in d[0]['spairport_airport_interfaces']:
d1.update(item)
d1.update(d[0]['spairport_software_information'])
return d1
def print_data(title, dct):
print '\n%s\n-------------------' % title
for k, v in dct.items():
print '%s: %s' % (k,v)
def main():
sysprofiler = SystemProfiler()
storage_data = sysprofiler.get_SPStorageDataType()
print_data('STORAGE DATA', storage_data)
hardware_data = sysprofiler.get_SPHardwareDataType()
print_data('HARDWARE DATA', hardware_data)
universal_access = sysprofiler.get_SPUniversalAccessDataType()
print_data('UNIVERSAL ACCESS', universal_access)
dev_tools = sysprofiler.get_SPDeveloperToolsDataType()
print_data('DEVELOPER TOOLS', dev_tools)
config_profile = sysprofiler.get_SPConfigurationProfileDataType()
print_data('CONFIGURATION PROFILE', config_profile)
install_history = sysprofiler.get_SPInstallHistoryDataType()
print_data('INSTALL HISTORY', install_history)
diagnostic_data = sysprofiler.get_SPDiagnosticsDataType()
print_data('DIAGNOSTIC DATA', diagnostic_data)
firewall_settings = sysprofiler.get_SPFirewallDataType()
print_data('FIREWALL SETTINGS', firewall_settings)
display_data = sysprofiler.get_SPDisplaysDataType()
print_data('DISPLAY DATA', display_data)
network_location = sysprofiler.get_SPNetworkLocationDataType()
print_data('NETWORK LOCATIONS', network_location)
managed_client_data = sysprofiler.SPManagedClientDataType()
print_data('MANAGED CLIENT DATA', managed_client_data)
memory_data = sysprofiler.get_SPMemoryDataType()
for item in memory_data:
print_data('MEMORY DATA', item)
network_data = sysprofiler.get_SPNetworkDataType()
for item in network_data:
print_data('NETWORK DATA', item)
power_data = sysprofiler.get_SPPowerDataType()
print_data('POWER DATA', power_data)
pref_data = sysprofiler.get_SPPrefPaneDataType()
for item in pref_data:
print_data('PREFERENCE PANE DATA', item)
printer_data = sysprofiler.get_SPPrintersDataType()
for item in printer_data:
print_data('PRINTER DATA', item)
sata_data = sysprofiler.get_SPSerialATADataType()
print_data('SATA DATA', sata_data)
software_data = sysprofiler.get_SPSoftwareDataType()
print_data('SOFTWARE DATA', software_data)
network_volume_data = sysprofiler.get_SPNetworkVolumeDataType()
for item in network_volume_data:
print_data('NETWORK VOLUME DATA', item)
airport_data = sysprofiler.get_SPAirPortDataType()
print_data('AIRPORT DATA', airport_data)
if __name__ == "__main__":
main()