def get_model():
"""Obtain's the user's Mac model"""
# Obtain and parse the output of the system profiler command
try:
hardware_type_xml = run([
'system_profiler', 'SPHardwareDataType', '-xml'
])
except CampiesSubprocessError:
raise CampiesError(
'Unable to run the command required to obtain the model'
)
try:
hardware_type = loads_plist(hardware_type_xml)
except xml.parsers.expat.ExpatError:
raise CampiesError(
'Unable to parse hardware XML to obtain the model'
)
# We now need to grab the machine model which is buried in the data
# [{
# '_items': [
# {
# '_name': 'hardware_overview',
# 'machine_model': 'MacBookPro11,5',
# 'machine_name': 'MacBook Pro',
try:
model = hardware_type[0]['_items'][0]['machine_model']
except IndexError:
raise CampiesError(
'Unable to find model in the hardware XML'
)
return model
评论列表
文章目录