Commits

Anonymous committed e19e686

First revision. (Yes I already hacked too much on it without version control. ☺)

Comments (0)

Files changed (13)

+include *.txt
+recursive-include docs *.txt
+=========
+PySensors
+=========
+
+:author: Marc 'BlackJack' Rintsch
+:date: 2011-10-04
+
+Python bindings for ``libsensors.so`` from the `lm-sensors` project via
+`ctypes`.
+
+Trying to support the last two libsensors APIs — versions 3 and 4.
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = _build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PySensors.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PySensors.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/PySensors"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PySensors"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	make -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
+# -*- coding: utf-8 -*-
+#
+# PySensors documentation build configuration file, created by
+# sphinx-quickstart on Tue Oct  4 13:32:08 2011.
+#
+# This file is execfile()d with the current directory set to its containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.insert(0, os.path.abspath(os.pardir))
+import sensors
+
+# -- General configuration -----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.txt'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'PySensors'
+copyright = u'2011, Marc \'BlackJack\' Rintsch'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = sensors.__version__
+# The full version, including alpha/beta/rc tags.
+release = version
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output ---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'PySensorsdoc'
+
+
+# -- Options for LaTeX output --------------------------------------------------
+
+# The paper size ('letter' or 'a4').
+latex_paper_size = 'a4'
+
+# The font size ('10pt', '11pt' or '12pt').
+#latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'PySensors.tex', u'PySensors Documentation',
+   u'Marc \'BlackJack\' Rintsch', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Additional stuff for the LaTeX preamble.
+#latex_preamble = ''
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'pysensors', u'PySensors Documentation',
+     [u'Marc \'BlackJack\' Rintsch'], 1)
+]
+
+
+# -- Options for Epub output ---------------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = u'PySensors'
+epub_author = u'Marc \'BlackJack\' Rintsch'
+epub_publisher = u'Marc \'BlackJack\' Rintsch'
+epub_copyright = u'2011, Marc \'BlackJack\' Rintsch'
+
+# The language of the text. It defaults to the language option
+# or en if the language is not set.
+#epub_language = ''
+
+# The scheme of the identifier. Typical schemes are ISBN or URL.
+#epub_scheme = ''
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#epub_identifier = ''
+
+# A unique identification for the text.
+#epub_uid = ''
+
+# HTML files that should be inserted before the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#epub_pre_files = []
+
+# HTML files shat should be inserted after the pages created by sphinx.
+# The format is a list of tuples containing the path and title.
+#epub_post_files = []
+
+# A list of files that should not be packed into the epub file.
+#epub_exclude_files = []
+
+# The depth of the table of contents in toc.ncx.
+#epub_tocdepth = 3
+
+# Allow duplicate toc entries.
+#epub_tocdup = True
+.. PySensors documentation master file, created by
+   sphinx-quickstart on Tue Oct  4 13:32:08 2011.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to PySensors's documentation!
+=====================================
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+
+Overview
+========
+
+
+Requirements
+------------
+
+* Python (>=2.6),
+* version 2.x or 3.x of :file:`libsensors.so` from ``lm-sensors``.
+
+
+Executing the package as program
+================================
+
+.. module:: sensors.cli
+
+The :mod:`sensors.cli` module can be started as a program with the :option:`-m`
+command line option of Python.  It simply…
+
+
+The :mod:`sensors` package
+==========================
+
+.. module:: sensors
+
+
+:class:`Chip` objects
+---------------------
+
+.. class:: Chip
+
+
+:class:`Feature` objects
+------------------------
+
+.. class:: Feature
+
+
+:class:`Subfeature` objects
+---------------------------
+
+.. class:: Subfeature
+
+
+Environment
+===========
+
+:envvar:`SENSORS_LIB`
+
+
+License
+=======
+
+GPL v2 (forced by sensors 2.x API).
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\PySensors.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\PySensors.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+:end

sensors/__init__.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from functools import partial
+
+from common import *
+
+if MAJOR_VERSION < 3:
+    from api3 import *
+else:
+    from api4 import *
+
+
+__version__ = '0.0.1'
+__date__ = '2011-10-04'
+__author__ = "Marc 'BlackJack' Rintsch"
+__contact__ = 'marc@rintsch.de'
+# 
+# Due to lm-sensors 2.x using this license.
+# 
+__license__ = 'GPL v2'
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from ctypes import *
+from pprint import pprint
+
+import stdc
+from common import *
+
+__all__ = ['API_VERSION', 'DEFAULT_CONFIG_FILENAME', 'iter_detected_chips']
+
+API_VERSION = 3
+DEFAULT_CONFIG_FILENAME = '/etc/sensors.conf'
+
+class Feature(Structure):
+    _fields_ = [
+        ('number', c_int),
+        ('name', c_char_p),
+        ('mapping', c_int),
+        ('compute_mapping', c_int),
+        ('mode', c_int),
+    ]
+    
+    NO_MAPPING = -1
+    
+    def __repr__(self):
+        return '<%s number=%d name=%r mapping=%d compute_mapping=%d mode=%d' % (
+            self.__class__.__name__,
+            self.number,
+            self.name,
+            self.mapping,
+            self.compute_mapping,
+            self.mode
+        )
+    
+    def __iter__(self):
+        return self.chip._iter_features(self.number)
+    
+    @property
+    def label(self):
+        result_p = c_char_p()
+        _get_label(self.chip, self.number, byref(result_p))
+        result = result_p.value
+        stdc.free(result_p)
+        return result
+    
+    def get_value(self):
+        result = c_double()
+        _get_feature(self.chip, self.number, byref(result))
+        return result.value
+
+FEATURE_P = POINTER(Feature)
+
+
+class Chip(Structure):
+    # 
+    # TODO Implement a `__str__()` method.
+    # TODO Move common stuff into `AbstractChip` class.
+    # 
+    _fields_ = [
+        ('prefix', c_char_p),
+        ('bus', c_int),
+        ('addr', c_int),
+        ('busname', c_char_p),
+    ]
+    
+    def __new__(cls, *args):
+        result = super(Chip, cls).__new__(cls)
+        if args:
+            _parse_chip_name(args[0], byref(result))
+        return result
+    
+    def __init__(self, *_args):
+        Structure.__init__(self)
+    
+    def __repr__(self):
+        return '<%s prefix=%r bus=%r addr=%r busname=%r>' % (
+            (
+                self.__class__.__name__,
+                self.prefix,
+                self.bus,
+                self.addr,
+                self.busname
+            )
+        )
+    
+    def __iter__(self):
+        return self._iter_features()
+    
+    @property
+    def has_wildcards(self):
+        return bool(_chip_name_has_wildcards(self))
+    
+    @property
+    def adapter_name(self):
+        return _get_adapter_name(self.bus)
+    
+    def match(self, other):
+        return bool(_match_chip(self, other))
+    
+    def _iter_features(self, parent=Feature.NO_MAPPING):
+        nr1, nr2 = c_int(0), c_int(0)
+        while True:
+            result_p = _get_all_features(self, byref(nr1), byref(nr2))
+            if not result_p:
+                break
+            result = result_p.contents
+            if result.mapping == parent:
+                result.chip = self
+                result.subfeatures = dict()
+                yield result
+
+CHIP_P = POINTER(Chip)
+
+
+# 
+# TODO Implement a handler for at least `sensors_parse_error`.
+# 
+
+_parse_chip_name = SENSORS_LIB.sensors_parse_chip_name
+_parse_chip_name.argtypes = [c_char_p, CHIP_P]
+_parse_chip_name.restype = c_int
+_parse_chip_name.errcheck = _error_check
+
+_match_chip = SENSORS_LIB.sensors_match_chip
+_match_chip.argtypes = [Chip, Chip]
+_match_chip.restype = c_int
+
+_chip_name_has_wildcards = SENSORS_LIB.sensors_chip_name_has_wildcards
+_chip_name_has_wildcards.argtypes = [Chip]
+_chip_name_has_wildcards.restype = c_int
+
+_get_adapter_name = SENSORS_LIB.sensors_get_adapter_name
+_get_adapter_name.argtypes = [c_int]
+_get_adapter_name.restype = c_char_p
+
+_get_label = SENSORS_LIB.sensors_get_label
+_get_label.argtypes = [Chip, c_int, POINTER(c_char_p)]
+_get_label.restype = c_int
+_parse_chip_name.errcheck = _error_check
+
+# 
+# TODO sensors_get_ignored()
+# 
+
+_get_feature = SENSORS_LIB.sensors_get_feature
+_get_feature.argtypes = [Chip, c_int, POINTER(c_double)]
+_get_feature.restype = c_int
+_parse_chip_name.errcheck = _error_check
+
+# 
+# TODO sensors_set_feature()
+# TODO sensors_do_chip_sets()
+# TODO sensors_do_all_sets()    (common function)
+# 
+
+_get_detected_chips = SENSORS_LIB.sensors_get_detected_chips
+_get_detected_chips.argtypes = [POINTER(c_int)]
+_get_detected_chips.restype = CHIP_P
+
+_get_all_features = SENSORS_LIB.sensors_get_all_features
+_get_all_features.argtypes = [Chip, POINTER(c_int), POINTER(c_int)]
+_get_all_features.restype = FEATURE_P
+
+
+def iter_detected_chips(chip_name='*-*'):
+    chip = Chip(chip_name)
+    number = c_int(0)
+    while True:
+        result_p = _get_detected_chips(byref(number))
+        if not result_p:
+            break
+        result = result_p.contents
+        # 
+        # TODO Add ignore check.
+        # 
+        if chip.match(result):
+            yield result
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from ctypes import *
+from pprint import pprint
+
+import stdc
+from common import *
+
+__all__ = ['API_VERSION', 'DEFAULT_CONFIG_FILENAME', 'iter_detected_chips']
+
+API_VERSION = 4
+DEFAULT_CONFIG_FILENAME = '/etc/sensors3.conf'
+
+
+class Subfeature(Structure):
+    _fields_ = [
+        ('name', c_char_p),
+        ('number', c_int),
+        ('type', c_int),
+        ('mapping', c_int),
+        ('flags', c_uint),
+    ]
+    
+    def __repr__(self):
+        return '<%s name=%r number=%d type=%d mapping=%d flags=%08x>' % (
+            self.__class__.__name__,
+            self.name,
+            self.number,
+            self.type,
+            self.mapping,
+            self.flags
+        )
+    
+    def get_value(self):
+        result = c_double()
+        _get_value(byref(self.parent.chip), self.number, byref(result))
+        return result.value
+
+SUBFEATURE_P = POINTER(Subfeature)
+
+
+class Feature(Structure):
+    _fields_ = [
+        ('name', c_char_p),
+        ('number', c_int),
+        ('type', c_int),
+        ('_first_subfeature', c_int),
+        ('_padding1', c_int),
+    ]
+    
+    def __repr__(self):
+        return '<%s name=%r number=%r type=%r>' % (
+            self.__class__.__name__,
+            self.name,
+            self.number,
+            self.type
+        )
+    
+    def __iter__(self):
+        number = c_int(0)
+        while True:
+            result_p = _get_all_subfeatures(
+                byref(self.chip),
+                byref(self),
+                byref(number)
+            )
+            if not result_p:
+                break
+            result = result_p.contents
+            result.chip = self.chip
+            result.parent = self
+            yield result
+    
+    @property
+    def label(self):
+        # 
+        # TODO Maybe this is a memory leak!
+        # 
+        return _get_label(byref(self.chip), byref(self))
+    
+    def get_value(self):
+        # 
+        # TODO Is the first always the correct one for all feature types?
+        # 
+        return iter(self).next().get_value()
+
+FEATURE_P = POINTER(Feature)
+
+
+class Bus(Structure):
+    TYPE_ANY = -1
+    NR_ANY = -1
+    
+    _fields_ = [
+        ('type', c_short),
+        ('nr', c_short),
+    ]
+    
+    def __str__(self):
+        return (
+            '*' if self.type == self.TYPE_ANY
+                else _get_adapter_name(byref(self))
+        )
+    
+    def __repr__(self):
+        return '%s(%r, %r)' % (self.__class__.__name__, self.type, self.nr)
+    
+    @property
+    def has_wildcards(self):
+        return self.type == self.TYPE_ANY or self.nr == self.NR_ANY
+
+BUS_P = POINTER(Bus)
+
+
+class Chip(Structure):
+    # 
+    # TODO Move common stuff into `AbstractChip` class.
+    # 
+    _fields_ = [
+        ('prefix', c_char_p),
+        ('bus', Bus),
+        ('addr', c_int),
+        ('path', c_char_p),
+    ]
+    
+    PREFIX_ANY = None
+    ADDR_ANY = -1
+    
+    def __new__(cls, *args):
+        result = super(Chip, cls).__new__(cls)
+        if args:
+            _parse_chip_name(args[0], byref(result))
+        return result
+        
+    def __init__(self, *_args):
+        Structure.__init__(self)
+        # 
+        # Need to bind the following to the instance so it is available in
+        #  `__del__()` when the interpreter shuts down.
+        # 
+        self._free_chip_name = _free_chip_name
+        self.byref = byref
+    
+    def __del__(self):
+        if self._b_needsfree_:
+            self._free_chip_name(self.byref(self))
+    
+    def __repr__(self):
+        return '<%s prefix=%r bus=%r addr=%r path=%r>' % (
+            (
+                self.__class__.__name__,
+                self.prefix,
+                self.bus,
+                self.addr,
+                self.path
+            )
+        )
+    
+    def __str__(self):
+        buffer_size = 200
+        result = create_string_buffer(buffer_size)
+        used = _snprintf_chip_name(result, len(result), byref(self))
+        assert used < buffer_size
+        return result.value
+    
+    def __iter__(self):
+        number = c_int(0)
+        while True:
+            result_p = _get_features(byref(self), byref(number))
+            if not result_p:
+                break
+            result = result_p.contents
+            result.chip = self
+            yield result
+    
+    @property
+    def adapter_name(self):
+        return str(self.bus)
+    
+    @property
+    def has_wildcards(self):
+        return (
+            self.prefix == self.PREFIX_ANY
+            or self.addr == self.ADDR_ANY
+            or self.bus.has_wildcards
+        )
+
+CHIP_P = POINTER(Chip)
+
+
+_parse_chip_name = SENSORS_LIB.sensors_parse_chip_name
+_parse_chip_name.argtypes = [c_char_p, CHIP_P]
+_parse_chip_name.restype = c_int
+_parse_chip_name.errcheck = _error_check
+
+_free_chip_name = SENSORS_LIB.sensors_free_chip_name
+_free_chip_name.argtypes = [CHIP_P]
+_free_chip_name.restype = None
+
+_snprintf_chip_name = SENSORS_LIB.sensors_snprintf_chip_name
+_snprintf_chip_name.argtypes = [c_char_p, c_size_t, CHIP_P]
+_snprintf_chip_name.restype = c_int
+_snprintf_chip_name.errcheck = _error_check
+
+_get_adapter_name = SENSORS_LIB.sensors_get_adapter_name
+_get_adapter_name.argtypes = [BUS_P]
+_get_adapter_name.restype = c_char_p
+
+_get_label = SENSORS_LIB.sensors_get_label
+_get_label.argtypes = [CHIP_P, FEATURE_P]
+_get_label.restype = c_char_p
+
+_get_value = SENSORS_LIB.sensors_get_value
+_get_value.argtypes = [CHIP_P, c_int, POINTER(c_double)]
+_get_value.restype = c_int
+_get_value.errcheck = _error_check
+
+# 
+# TODO sensors_set_value()
+# TODO sensors_do_chip_sets()
+# 
+
+_get_detected_chips = SENSORS_LIB.sensors_get_detected_chips
+_get_detected_chips.argtypes = [CHIP_P, POINTER(c_int)]
+_get_detected_chips.restype = CHIP_P
+
+_get_features = SENSORS_LIB.sensors_get_features
+_get_features.argtypes = [CHIP_P, POINTER(c_int)]
+_get_features.restype = FEATURE_P
+
+_get_all_subfeatures = SENSORS_LIB.sensors_get_all_subfeatures
+_get_all_subfeatures.argtypes = [CHIP_P, FEATURE_P, POINTER(c_int)]
+_get_all_subfeatures.restype = SUBFEATURE_P
+
+# 
+# TODO sensors_get_subfeature() ?
+# 
+
+def iter_detected_chips(chip_name='*-*'):
+    chip = Chip(chip_name)
+    number = c_int(0)
+    while True:
+        result = _get_detected_chips(byref(chip), byref(number))
+        if not result:
+            break
+        yield result.contents
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import sensors
+
+
+def main():
+    sensors.init(sensors.DEFAULT_CONFIG_FILENAME)
+    
+    #chip_a = Chip('k8temp-pci-00c3')
+    #chip_b = Chip('k8temp-*')
+    #chip_c = Chip('test-*')
+    #print repr(chip_a)
+    #print repr(chip_b)
+    #print repr(chip_c)
+
+    #print chip_a.has_wildcards
+    #print chip_b.has_wildcards
+
+    #print chip_a.adapter_name
+    #print chip_b.adapter_name
+
+    for chip in sensors.iter_detected_chips():
+        print chip
+        print 'Adapter:', chip.adapter_name
+        for feature in chip:
+            print '%s (%r): %.1f' % (
+                feature.name, feature.label, feature.get_value()
+            )
+            for subfeature in feature:
+                print '  %s: %.1f' % (subfeature.name, subfeature.get_value())
+        print
+    
+    sensors.cleanup()
+
+
+if __name__ == '__main__':
+    main()

sensors/common.py

+# -*- coding: utf-8 -*-
+import os
+from ctypes import *
+from ctypes.util import find_library
+
+import stdc
+
+__all__ = [
+    'SENSORS_LIB', 'VERSION', 'MAJOR_VERSION', 'SensorsError', '_error_check',
+    'init', 'cleanup'
+]
+
+LIB_FILENAME = os.environ.get('SENSORS_LIB') or find_library('sensors')
+SENSORS_LIB = CDLL(LIB_FILENAME)
+VERSION = c_char_p.in_dll(SENSORS_LIB, 'libsensors_version').value
+MAJOR_VERSION = int(VERSION.split('.', 1)[0])
+
+
+class SensorsError(Exception):
+    def __init__(self, message, error_number=None):
+        Exception.__init__(self, message)
+        self.error_number = error_number
+
+
+def _error_check(result, _func, _arguments):
+    if result < 0:
+        raise SensorsError(_strerror(result), result)
+
+_strerror = SENSORS_LIB.sensors_strerror
+_strerror.argtypes = [c_int]
+_strerror.restype = c_char_p
+
+_init = SENSORS_LIB.sensors_init
+_init.argtypes = [c_void_p]
+_init.restype = c_int
+_init.errcheck = _error_check
+
+cleanup = SENSORS_LIB.sensors_cleanup
+cleanup.argtypes = None
+cleanup.restype = None
+
+
+def init(config_filename):
+    file_p = stdc.fopen(config_filename, 'r')
+    if file_p is None:
+        error_number = get_errno()
+        raise OSError(error_number, os.strerror(error_number), config_filename)
+    try:
+        _init(file_p)
+    finally:
+        stdc.fclose(file_p)
+# -*- coding: utf-8 -*-
+from ctypes import *
+from ctypes.util import find_library
+
+STDC_LIB = CDLL(find_library('c'), use_errno=True)
+
+fopen = STDC_LIB.fopen
+fopen.argtypes = [c_char_p, c_char_p]
+fopen.restype = c_void_p
+
+fclose = STDC_LIB.fclose
+fclose.argtypes = [c_void_p]
+fclose.restype = c_int
+
+free = STDC_LIB.free
+free.argtypes = [c_void_p]
+free.restype = None
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from distutils.core import setup
+import sensors
+
+setup(
+    name='PySensors',
+    version=sensors.__version__,
+    author=sensors.__author__,
+    author_email=sensors.__contact__,
+    packages=['sensors'],
+    #scripts=[],
+    url='http://pypi.python.org/pypi/PySensors/',
+    #download_url='',
+    license=sensors.__license__,
+    description='Python bindings to libsensors (via ctypes)',
+    long_description=open('README.rst').read(),
+    keywords=['sensors', 'hardware', 'monitoring'],
+    classifiers=[
+        'Development Status :: 1 - Planning',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved',
+        'License :: OSI Approved :: GNU General Public License (GPL)',
+        'Operating System :: POSIX :: Linux',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.6',
+        'Topic :: System',
+        'Topic :: System :: Hardware',
+        'Topic :: System :: Monitoring',
+    ]
+)