Hi,

I'm just getting started with freevo, so, I've decided to make my first plugin. It displays harddisk temperatures on the idlebar using hddtemp. It is capable of polling at a given interval and displays maximun temperatures of on or more sets of harddisk devices.

The plugin should be put in src/plugins/. See attachment for the script, instructions for activating it are inside the script. And ... I'm going to make it look nicer :-)

Let me know about bugs, idea's etc.

- Richard.

#if 0 /*
#  -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# name:     hddtemp.py - IdleBar hddtemp plugin
# version:  0.1 - 26 oct 2003
# author:   [EMAIL PROTECTED]
# location: src/plugins/hddtemp.py
# -----------------------------------------------------------------------
#
# Idlebar plugin for displaying harddisk temperatures.
# Polls all given drives and displays highest temperature.
#
# Notes:
#   To activate the hddtemp idle bar plugin, put the following in
#   your local_config.py, e.g.:
#
#      plugin.activate('hddtemp', level=10, args=('/dev/hdb'))
#      plugin.activate('hddtemp', level=10, args=('/dev/hdc /dev/hdd'))
#
#   The above example displays 2 temperatures in the idlebar, the
#   first is hdb temp and the second is the highest from hdc and hdb.
#
#   Add the path to hddtemp utility in freevo.conf:
#
#      hddtemp = /usr/bin/hddtemp
#
#   Add in local_cofig.py:
#
#       # get hddtemp command:
#       HDDTEMP_COMMAND = CONF.hddtemp
#       # set poll interval to 5 minutes:
#       HDDTEMP_INTERVAL = 300
#
#   Note: hddtemp must have suid 0 if freevo is not run as root:
#
#       chmod +s /usr/bin/hddtemp
#
# ----------------------------------------------------------------------- */
#endif

import os
import re
import time
import config
from idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    idlebar plugin for displaying harddisk temperatures
    """
    def __init__(self, drives=""):
        """
        init idlebar hddtemp plugin
        """
        IdleBarPlugin.__init__(self)
        # get current time minus poll interval
        self.time = time.time() - config.HDDTEMP_INTERVAL - 1
        # initialize temperature
        self.temp = 0
        self.drives = drives

    def draw(self, (type, object), x, osd):
        """
        draw idlebar hddtemp plugin
        """
        if (time.time() - self.time > config.HDDTEMP_INTERVAL):
            # need to remeasure temperatures
            self.time = time.time()
            cmd = "%s %s" % (config.HDDTEMP_COMMAND, self.drives)
            f = os.popen(cmd, "r")
            s = f.read()
            f.close()
            # extract from hddtemp output
            t = re.compile(".+: .+: (\d+) .+\n")
            u = t.split(s)
            # get max temperature
            i,self.temp = 1,-1
            while len(u) >= (i+1):
                self.temp = max(self.temp, u[i])
                i += 2   
        # using clock font for now
        temp  = "|%s|"%self.temp
        font  = osd.get_font('clock')
        width = font.font.stringsize(temp)
        # note: idlebar height (=60) is hard-coded in idlebar :-(
        osd.write_text(temp, font, None, x, osd.y, width+1, 60, "left", "center")
        return width

Reply via email to