~ubuntu-branches/ubuntu/utopic/awn-extras-applets/utopic

« back to all changes in this revision

Viewing changes to applets/maintained/hardware-sensors/interfaces/hddtempsensors.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-01-13 21:50:33 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100113215033-kd9otcdjrajmiag0
Tags: 0.3.9~bzr1944-0ubuntu1
* New upstream snapshot.
 - Catch error in weather applet (LP: #359668)
* debian/patches: Refresh.
* debian/*.install: 
 - Update to new location and new applets.
 - Disable dialect applet until python-xklavier is in the archive.
 - Disable MiMenu and Pandora applets, there are unmaintained and not stable.
* debian/awn-applets-c-core: Dropped, not needed.
* debian/control:
 - Update description with new applets.
 - Remove libawn-extras and python-awnlib, all merged in python-awn-extras.
 - Replace awn-manager by awn-settings.
 - Drop build-depends on libgnome-desktop-dev, python*-dev, python2.5,
   awn-manager, libglade2-dev and libgnomeui-dev.
 - Add build-depends on libdesktop-agnostic-bin and vala-awn.
 - Bump build-depends of libawn-dev (>= 0.3.9~bzr1890), valac (>= 0.7.7) and
   debhelper (>= 7.0.50~).
 - Bump Standards-Version to 3.8.3 (no change needed).
 - Demote gconf-editor to Suggest, it's only needed for very advanced
   settings.
 - Update Recommends for python applets with new applets.
 - Suggest python-gconf for notification-area and alacarte for YAMA.
 - Add a debug package for C applets.
* debian/libawn-extras*: Removed, libawn-extras was removed upstream.
* debian/python-awnlib*: Merged with python-awn-extras.
* debian/rules:
 - Rewrite to use overrides.
* debian/copyright:
 - Update copyright and licenses.
* debian/README.source: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#coding: utf-8
 
3
#
 
4
#   Copyright 2008-2009 Grega Podlesek <grega.podlesek@gmail.com>
 
5
#
 
6
#   This program is free software; you can redistribute it and/or modify
 
7
#   it under the terms of the GNU General Public License as published by
 
8
#   the Free Software Foundation; either version 2 of the License, or
 
9
#   (at your option) any later version.
 
10
#
 
11
#   This program is distributed in the hope that it will be useful,
 
12
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#   GNU General Public License for more details.
 
15
#
 
16
#   You should have received a copy of the GNU General Public License
 
17
#   along with this program; if not, write to the Free Software
 
18
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
#   MA 02110-1301, USA.
 
20
 
 
21
import time
 
22
import socket
 
23
import gobject
 
24
 
 
25
from sensorinterface import Sensor
 
26
from sensorinterface import Updater
 
27
from sensorvalues.tempvalue import TempValue
 
28
 
 
29
from sensorvalues import units
 
30
 
 
31
interface_name = "HDDTemp"
 
32
hddtemp_address = ("127.0.0.1", 7634)
 
33
 
 
34
 
 
35
class HDDTempSensor(Sensor):
 
36
 
 
37
    def __init__(self, name, seq_num, updater):
 
38
        Sensor.__init__(self, name, name, TempValue())
 
39
        self.__seq_num = seq_num
 
40
        self.updater = updater
 
41
        self.interface = interface_name
 
42
 
 
43
    def read_sensor(self):
 
44
        input = self.updater.get_update()
 
45
        if input is None:
 
46
            return False
 
47
        self.value = float(input[3 + 5 * self.__seq_num])
 
48
        return True
 
49
 
 
50
 
 
51
def get_hddtemp_output():
 
52
    try:
 
53
        htsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
54
        htsocket.connect(hddtemp_address)
 
55
        input = ''
 
56
        htin = htsocket.recv(256)
 
57
        while len(htin) > 0:
 
58
            input = input + htin
 
59
            htin = htsocket.recv(256)
 
60
        htsocket.close()
 
61
    except socket.error, (errno, errorstr):
 
62
        print "HDDTemp sensors interface:", \
 
63
                                     "Socket error(%s): %s" % (errno, errorstr)
 
64
        return None
 
65
    if len(input) == 0:
 
66
        return None
 
67
    return input.split('|')
 
68
 
 
69
 
 
70
def get_sensors():
 
71
    htsensors = []
 
72
    updater = Updater(60, get_hddtemp_output)
 
73
    input = get_hddtemp_output()
 
74
    if not input:
 
75
        return htsensors
 
76
    # Number of hdd sensors
 
77
    n = (len(input) - 1) / 5
 
78
    for i in xrange(0, n):
 
79
        new_sensor = HDDTempSensor(input[1 + 5 * i], i, updater)
 
80
        new_sensor.label = input[2 + 5 * i]
 
81
        unit = input[4 + 5 * i]
 
82
        # Set unit
 
83
        if unit is 'C':
 
84
            new_sensor.unit = units.UNIT_CELSIUS
 
85
        elif unit is 'F':
 
86
            new_sensor.unit = units.UNIT_FAHRENHEIT
 
87
        elif unit is 'K':
 
88
            new_sensor.unit = units.UNIT_KELVIN
 
89
        else:
 
90
            print "HDDTemp sensors interface: unknown unit:", unit
 
91
            continue
 
92
        htsensors.append(new_sensor)
 
93
    return htsensors