moniteur/modules/hddtemp.py

57 lines
1.2 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from curses import color_pair as get_pair
hddtemp_addressport = ('localhost',7634)
def hddtemp ():
'''
Return an tuple of disks formated like (name, temp) where name is a string and temp a integer
'''
from socket import socket, AF_INET, SOCK_STREAM
from re import sub
data = []
tries = 0
while True:
tries += 1
s = socket(AF_INET, SOCK_STREAM)
s.connect(hddtemp_addressport)
d = s.recv(4096)
s.close()
data = d.decode ('utf-8').split('|')
if d != b'|':
break
temps = []
index = 0
while True:
try:
index += 1
name = sub ('/dev/', '', data [index])
index += 2
temp = int (data [index])
index +=2
temps.append ((name, temp))
except IndexError:
break
return (temps)
def main (line, screen):
screen.addstr (line, 0, '-->', get_pair (5))
screen.addstr (line, 3, 'Températures stockage :', get_pair (1))
line += 1
data = hddtemp ()
x = 0
for i in data:
screen.addstr (line, x, i [0] + ':', get_pair (2))
x += len (i [0]) + 2
if i [1] < 45:
screen.addstr (line, x, str (i [1]), get_pair (3))
else:
screen.addstr (line, x, str (i [1]), get_pair (4))
x += 2
screen.addstr (line, x, '°C', get_pair (1))
x += 4
line += 1
return (line)