Removed dependency on python-plumbum
This commit is contained in:
parent
55f3f82313
commit
0731eb86a2
41
drivetemp.py
41
drivetemp.py
@ -1,41 +1,48 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
""" Check the temperature of the drive
|
"""Check the temperature of a drive.
|
||||||
Functions:
|
Functions:
|
||||||
verify_device_node(query)
|
verify_device_node(query)
|
||||||
- Check if query is a device node
|
- Check if query is a device node
|
||||||
retrieve_smart_temp(device_node)
|
retrieve_smart_temp(device_node)
|
||||||
- Retrieve specified drive temperature in mKelvin
|
- Retrieve specified drive temperature in mKelvin
|
||||||
calculate_temp(mkel_temp)
|
convert_to_celsius(mkel_temp)
|
||||||
- Given mkel_temp, convert it into °C
|
- Given mkel_temp, convert it into °C
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import subprocess
|
||||||
from plumbum.cmd import sudo
|
|
||||||
|
|
||||||
|
|
||||||
def verify_device_node(query):
|
def verify_device_node(query):
|
||||||
""" Check if query is a device node
|
"""Check if query is a device node.
|
||||||
Return True or False
|
:param query: input that refers to a device
|
||||||
|
:type query: a path-like object
|
||||||
|
:returns: True if query is a device node, False if otherwise
|
||||||
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return pathlib.Path(query).is_block_device()
|
return pathlib.Path(query).is_block_device()
|
||||||
|
|
||||||
|
|
||||||
def retrieve_smart_temp(device_node):
|
def retrieve_smart_temp(device_node):
|
||||||
""" Retrieve specified drive temperature in mKelvin
|
"""Retrieve specified drive's temperature.
|
||||||
device_node: the device to retrieve a temperature for
|
:param device_node: device to retrieve temperature for
|
||||||
Returns the output of skdump
|
:type device_node: str
|
||||||
|
:returns: output of skdump in mKelvin
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
dump_cmd = sudo['skdump', '--temperature', device_node]
|
dump_cmd = subprocess.run(['sudo', 'skdump', '--temperature',
|
||||||
output = dump_cmd()
|
device_node], capture_output=True,
|
||||||
return output
|
text=True)
|
||||||
|
return dump_cmd.stdout
|
||||||
|
|
||||||
|
|
||||||
def calculate_temp(mkel_temp):
|
def convert_to_celsius(mkel_temp):
|
||||||
""" Given mkel_temp, convert it into °C
|
"""Given mkel_temp, convert it into °C.
|
||||||
mkel_temp: the temperature in mKelvin
|
:param mkel_temp: the temperature in mKelvin
|
||||||
Returns the temperature converted into degrees celsius
|
:type mkel_temp: str
|
||||||
|
:returns: temperature converted into degrees celsius
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return (float(mkel_temp)/1000) - 273.15
|
return (float(mkel_temp)/1000) - 273.15
|
||||||
|
|
||||||
@ -50,7 +57,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if verify_device_node(dev):
|
if verify_device_node(dev):
|
||||||
mkel = retrieve_smart_temp(dev)
|
mkel = retrieve_smart_temp(dev)
|
||||||
print(f"{dev}: {calculate_temp(mkel)}°C")
|
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||||
else:
|
else:
|
||||||
print("Not a device node.")
|
print("Not a device node.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user