51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
import os
|
|
|
|
from .utilities import log, runCmd
|
|
|
|
|
|
def findHddIdInNt():
|
|
return {}
|
|
|
|
def findHddIdInPosix():
|
|
hddDict = {}
|
|
results = runCmd("blkid").split("\n")
|
|
for line in results:
|
|
if line == "":
|
|
continue
|
|
|
|
hddInfoList = line.split(" ")
|
|
if len(hddInfoList) > 1 and hddInfoList[0].startswith("/dev/sd"):
|
|
hddName = hddInfoList[0].replace(":", "")
|
|
hddDict[hddName] = {}
|
|
for hddInfoline in hddInfoList[1:]:
|
|
kvList = hddInfoline.split("=")
|
|
if len(kvList) > 1:
|
|
hddDict[hddName][kvList[0].replace("\"", "")] = kvList[1].replace("\"", "")
|
|
return hddDict
|
|
|
|
|
|
def findHddId():
|
|
hddDict = {}
|
|
if os.name == "nt":
|
|
hddDict = findHddIdInNt()
|
|
elif os.name == "posix":
|
|
hddDict = findHddIdInPosix()
|
|
return hddDict
|
|
|
|
|
|
def findHddTemp(hddDict):
|
|
for hddName in sorted(hddDict.keys()):
|
|
cmd = f"smartctl -A {hddName} | grep Temperature_Celsius"
|
|
hddTempString = runCmd(cmd)
|
|
log.logI(f'hddTempString = {hddTempString}')
|
|
hddTempList = hddTempString.split(" ")
|
|
hddTempList = [item for item in hddTempList if item != ""]
|
|
if len(hddTempList) > 9:
|
|
hddDict[hddName]["temp"] = int(hddTempList[9])
|
|
|
|
|
|
def getHddTemp():
|
|
hddDict = findHddId()
|
|
findHddTemp(hddDict)
|
|
return hddDict
|