import
os,sys,time,wmi
from
pySMART
import
Device
thread_num_for_ssd
=
4
thread_num_for_hdd
=
1
thread_num_for_other
=
2
thread_num_for_error
=
1
def
allocate_thread_num_by_disk_hardware_type()
-
>
tuple
:
c
=
wmi.WMI()
section_to_physical_disk_dict
=
{}
for
physical_disk
in
c.Win32_DiskDrive():
for
partition
in
physical_disk.associators(
"Win32_DiskDriveToDiskPartition"
):
for
logical_disk
in
partition.associators(
"Win32_LogicalDiskToPartition"
):
section_to_physical_disk_dict[logical_disk.DeviceID]
=
physical_disk.Index
section
=
os.path.splitdrive(os.getcwd())[
0
]
print
(f
"所在盘符为:【{section}】"
)
disk_index
=
section_to_physical_disk_dict.get(section)
print
(f
"磁盘号为:【{disk_index}】"
)
print
(
"\n"
)
if
disk_index !
=
None
:
handle
=
Device(f
'/dev/pd{disk_index}'
)
spin , slot , is_SSD
=
handle.rotation_rate , handle.interface , handle.is_ssd
print
(f
"旋转速度:{spin}"
)
print
(f
"接口:【{slot}】"
)
print
(f
"是否为SSD:{is_SSD}"
)
print
(
"\n"
)
if
spin:
print
(
"硬件类型:机械硬盘"
)
disk_type
=
"HDD"
allocated_thread_num
=
thread_num_for_hdd
elif
(slot
=
=
"nvme"
)
or
is_SSD :
print
(
"硬件类型:固态硬盘"
)
disk_type
=
"SSD"
allocated_thread_num
=
thread_num_for_ssd
else
:
print
(
"硬件类型:未知,无旋转速度,可能为U盘"
)
disk_type
=
"other"
allocated_thread_num
=
thread_num_for_other
else
:
print
(
"获取磁盘号失败"
)
disk_type
=
"error"
allocated_thread_num
=
thread_num_for_error
return
(allocated_thread_num , disk_type)
thread_num , disk_hardware_type
=
allocate_thread_num_by_disk_hardware_type()
os.system(
"pause"
)
sys.exit(
0
)