5
from utils.Struct import Struct
6
from libdesklets import convert
11
__REGEX = re.compile('\|(?P<device>.+?)\|(?P<name>.+?)\|(?P<value>\d+)\|(?P<unit>[CF])\|')
16
# |/dev/hda|TOSHIBA MK6025GAS|50|C|
17
# |/dev/hda|MAXTOR 6L040J2|41|C||/dev/hdh|IC35L040AVVN07-0|39|C|
19
def match_to_struct(m):
21
value = float(m['value'])
24
assert unit in ('C', 'F')
29
C = convert.fahrenheit_to_centigrade(value)
31
F = convert.centigrade_to_fahrenheit(C)
32
K = convert.centigrade_to_kelvin(C)
34
return Struct(device = m['device'],
36
temp = Struct(centigrade = C,
42
return [ match_to_struct(m.groupdict()) for m in __REGEX.finditer(data) ]
48
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
49
s.connect((__HOST, __PORT))
50
return s.makefile().read()
57
return __split( __socket_read() )
58
except Exception, exc:
59
log("Cannot retrieve HDD temperature. Error was %s" % (exc,))
64
def available_devices():
66
return [ s.device for s in poll_all() ]
74
if (s.device == device):
78
log("Cannot retrieve HDD temperature for device %s." % (device,))
84
if __name__ == '__main__':
86
print available_devices()
87
print poll('/dev/hda')