Hi again guys.
I've been getting my hands a bit more dirty with 'for loops' and dictionaries, especially those that are nested.
I've adapted the code buran gave me so that it give me back the physical size of the hard drive in a given machine instead of the size of each of the individual volumes or partitions.
I've also added some formatting checks to get the size of the hard drives correct i.e no messy numbers such as 500.11 GB and also that SSD drives return a pretty binary value such as 128 GB etc.
for y in candidates2:
for item in y['_items']:
for item2 in item['_items']:
HDsize = item2['size']
typeofHD = item2['spsata_medium_type']
if len(HDsize) >= 5 and typeofHD == "Rotational":
HDsize = HDsize[0:3]
HDsize = HDsize + "GB"
elif len(HDsize) >= 5 and typeofHD == "Solid State":
HDsize = HDsize[0:3]
HDsize = HDsize + "GB-SSD"
if HDsize == "121GB-SSD":
HDsize = "128GB-SSD"
elif HDsize == "251GB-SSD":
HDsize = "256GB-SSD"
elif HDsize == "500GB-SSD":
HDsize = "512GB-SSD"
elif HDsize == "1 TB":
HDsize = "1TB"
One little snag that remains is that when the script is executed on .spx saved from a machine with a internal hard drive AND a Superdrive (for reading CDs/DVDs) the script crashed. I get a
KeyError: 'size' message. This is most likely due to two different devices being attached to the SATA bus and each having its own dictionary. The script does not know which one to read to get at HD size info etc.
I've run this to help isolate things down a bit...
for y in candidates2:
for item in y['_items']:
for item2 in item['_items']:
print item2
print ""
The output is two distinct dictionaries. The data I want to get at is always on the first.
Macs with just one internal drive always return one dictionary when I run the exact same 'for' loop.
{'spsata_portspeed': '3 Gigabit', 'spsata_negotiatedlinkspeed': '3 Gigabit', '_name': 'NVidia MCP79 AHCI', 'spsata_product': 'MCP79 AHCI', 'spsata_physical_interconnect': 'SATA', 'spsata_vendor': 'NVidia', 'spsata_portdescription': 'AHCI Version 1.20 Supported', '_items': [{'smart_status': 'Failing', 'detachable_drive': 'no', 'spsata_rotational_rate': 7200, 'spsata_ncq_depth': '32', 'device_model': 'ST3500418ASQ ', 'size_in_bytes': 500107862016, '_name': 'ST3500418ASQ', 'spsata_ncq': 'Yes', 'bsd_name': 'disk0', 'device_revision': 'AP24 ', 'volumes': [{'size': '209,7 MB', 'iocontent': 'EFI', 'bsd_name': 'disk0s1', 'size_in_bytes': 209715200, '_name': 'EFI'}, {'mount_point': u'/Volumes/*A\u0308U\u0308P\xdfO\u0308-IK9,JMU8HNZ7BGT6FRV54SWX3AQY2', 'size_in_bytes': 499248103424, 'iocontent': 'Apple_HFS', 'free_space': '498,8 GB', 'writable': 'yes', 'bsd_name': 'disk0s2', 'volume_uuid': '7E8EFE9A-C246-3382-AEF1-EAF6F4EFFFE8', '_name': u'*A\u0308U\u0308P\xdfO\u0308-IK9,JMU8HNZ7BGT6FRV54SWX3AQY2', 'free_space_in_bytes': 498799886336, 'file_system': 'Journaled HFS+', 'size': '499,25 GB'}, {'iocontent': 'Apple_Boot', '_name': 'Recovery HD', 'bsd_name': 'disk0s3', 'volume_uuid': '82E27D91-EFB0-381D-9DC8-8A1A25FEA879', 'size_in_bytes': 650002432, 'size': '650 MB'}], 'spsata_medium_type': 'Rotational', 'device_serial': ' 5VMASEQK', 'removable_media': 'no', 'partition_map_type': 'guid_partition_map_type', 'size': '500,11 GB'}]}
{'spsata_portspeed': '3 Gigabit', 'spsata_negotiatedlinkspeed': '1.5 Gigabit', '_name': 'NVidia MCP79 AHCI', 'spsata_product': 'MCP79 AHCI', 'spsata_physical_interconnect': 'SATA', 'spsata_vendor': 'NVidia', 'spsata_portdescription': 'AHCI Version 1.20 Supported', '_items': [{'detachable_drive': 'no', 'device_model': 'HL-DT-ST DVDRW GA11N ', 'spsata_power_off': 'No', '_name': 'HL-DT-ST DVDRW GA11N', 'spsata_ncq': 'No', 'spsata_async_notify': 'Yes', 'device_revision': 'JA18 ', 'device_serial': 'KZKA2AD2212 '}]}
I've done some research online but I tend to find the advice offered a bit to technical to digest.
The python code I've attached to the post. A sample SPX file (which crashes the script) is on my
dropbox.com
Thanks again,
Will