Imported Upstream version 2.6.0

This commit is contained in:
arnaud.quette@free.fr 2011-01-26 10:35:08 +01:00
parent 26fb71b504
commit 459aaf9392
510 changed files with 40508 additions and 18859 deletions

View file

@ -1,9 +1,20 @@
EXTRA_DIST = nut-usbinfo.pl device-recorder.sh
EXTRA_DIST = nut-usbinfo.pl nut-hclinfo.py device-recorder.sh svn2cl.authors
website:
@if python -c pass; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
./nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Python is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
# only call the USB info script upon "make dist", and if Perl is present
dist-hook:
@if test -x /usr/bin/perl; then \
@if perl -e 1; then \
echo "Regenerating the USB helper files."; \
$(distdir)/nut-usbinfo.pl; \
else \

View file

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.11 from Makefile.am.
# Makefile.in generated by automake 1.11.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@ -37,12 +37,13 @@ target_triplet = @target@
subdir = tools
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
$(top_srcdir)/m4/ax_create_stdint_h.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/nut_arg_with.m4 \
$(top_srcdir)/m4/nut_check_ipv6.m4 \
$(top_srcdir)/m4/nut_check_asciidoc.m4 \
$(top_srcdir)/m4/nut_check_libgd.m4 \
$(top_srcdir)/m4/nut_check_libhal.m4 \
$(top_srcdir)/m4/nut_check_libneon.m4 \
@ -52,6 +53,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
$(top_srcdir)/m4/nut_check_libusb.m4 \
$(top_srcdir)/m4/nut_check_libwrap.m4 \
$(top_srcdir)/m4/nut_check_os.m4 \
$(top_srcdir)/m4/nut_config_libhal.m4 \
$(top_srcdir)/m4/nut_report_feature.m4 \
$(top_srcdir)/m4/nut_type_socklen_t.m4 \
$(top_srcdir)/configure.in
@ -64,9 +66,11 @@ CONFIG_CLEAN_VPATH_FILES =
SOURCES =
DIST_SOURCES =
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
A2X = @A2X@
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AR = @AR@
ASCIIDOC = @ASCIIDOC@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
@ -79,8 +83,10 @@ CONFPATH = @CONFPATH@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DBLATEX = @DBLATEX@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DOC_BUILD_LIST = @DOC_BUILD_LIST@
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
DRIVER_MAN_LIST = @DRIVER_MAN_LIST@
@ -97,7 +103,6 @@ HAL_CALLOUTS_PATH = @HAL_CALLOUTS_PATH@
HAL_DEVICE_MATCH_KEY = @HAL_DEVICE_MATCH_KEY@
HAL_FDI_PATH = @HAL_FDI_PATH@
HAL_USER = @HAL_USER@
HAVE_GLIB_2_14 = @HAVE_GLIB_2_14@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@ -108,22 +113,22 @@ LDFLAGS = @LDFLAGS@
LIBGD_CFLAGS = @LIBGD_CFLAGS@
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
LIBHAL_LDFLAGS = @LIBHAL_LDFLAGS@
LIBHAL_LIBS = @LIBHAL_LIBS@
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
LIBNEON_LDFLAGS = @LIBNEON_LDFLAGS@
LIBNEON_LIBS = @LIBNEON_LIBS@
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
LIBNETSNMP_LDFLAGS = @LIBNETSNMP_LDFLAGS@
LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@
LIBOBJS = @LIBOBJS@
LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@
LIBPOWERMAN_LDFLAGS = @LIBPOWERMAN_LDFLAGS@
LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@
LIBS = @LIBS@
LIBSSL_CFLAGS = @LIBSSL_CFLAGS@
LIBSSL_LDFLAGS = @LIBSSL_LDFLAGS@
LIBSSL_LIBS = @LIBSSL_LIBS@
LIBTOOL = @LIBTOOL@
LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
LIBUSB_LDFLAGS = @LIBUSB_LDFLAGS@
LIBUSB_LIBS = @LIBUSB_LIBS@
LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@
LIBWRAP_LDFLAGS = @LIBWRAP_LDFLAGS@
LIBWRAP_LIBS = @LIBWRAP_LIBS@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
@ -219,7 +224,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
udevdir = @udevdir@
EXTRA_DIST = nut-usbinfo.pl device-recorder.sh
EXTRA_DIST = nut-usbinfo.pl nut-hclinfo.py device-recorder.sh svn2cl.authors
all: all-am
.SUFFIXES:
@ -409,9 +414,20 @@ uninstall-am:
uninstall uninstall-am
website:
@if python -c pass; then \
echo "Regenerating the HTML and JSON formated HCL tables."; \
./nut-hclinfo.py; \
else \
echo "----------------------------------------------------------------------"; \
echo "Warning: Python is not available."; \
echo "Skipping the HTML and JSON formated HCL tables regeneration."; \
echo "----------------------------------------------------------------------"; \
fi
# only call the USB info script upon "make dist", and if Perl is present
dist-hook:
@if test -x /usr/bin/perl; then \
@if perl -e 1; then \
echo "Regenerating the USB helper files."; \
$(distdir)/nut-usbinfo.pl; \
else \

268
tools/nut-hclinfo.py Executable file
View file

@ -0,0 +1,268 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009 - Arnaud Quette <arnaud.quette@gmail.com>
# Copyright (c) 2010 - Sébastien Volle <sebastien.volle@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# This script convert the driver.list into HTML and JSON formated tables
# These tables are then used by the AsciiDoc generated website and
# documentation
try:
import json
except ImportError:
import simplejson as json # Required for Python < 2.6
import re
import sys
# HCL file location and name
rawHCL="../data/driver.list";
# Website output
webJsonHCL = "../docs/website/scripts/ups_data.js";
webStaticHCL = "../docs/ups-html.txt";
# from http://wiki.python.org/moin/EscapingHtml
html_escape_table = {
"&": "&amp;",
'"': "&quot;",
"'": "&apos;",
">": "&gt;",
"<": "&lt;",
}
def html_escape(text):
"""Produce entities within text."""
return "".join(html_escape_table.get(c,c) for c in text)
# # #
class WrongFieldNumberException(Exception):
pass
def buildData(deviceDataFile):
"""
Read and parse data file under provided path.
Return a bi-dimensional list representing parsed data.
"""
deviceData = []
numFields = 6 # Manufacturer, type, support level, model comment, driver
try:
file = open(deviceDataFile, "r")
except IOError:
print "Cannot open", deviceDataFile
exit(1)
for line in file:
# Ignore empty lines or comments
if re.match(r"^$|^\s*#", line):
continue
# Strip all trailing whitespace chars
line = re.sub(r"\s+$", "", line)
# Replace all tabs by commas
line = re.sub(r"\t", ",", line)
# Remove trailing comma
line = re.sub(r",$", "", line)
# Split fields and append result to device data list
# We suppose there are no double-quotes in fields
row = re.findall(r'"([^"]*)",?', line)
if len(row) != numFields:
print "Warning: Unexpected number of fields in line: %s" % row
print "\tLine will be skipped."
else:
deviceData.append(re.findall(r'"([^"]*)",?', line))
return deviceData
def buildHTMLTable(deviceData):
"""
Convert provided device data into an HTML table.
Return string representation of the HTML table.
Identical cells are merged vertically with rowspan attribute.
The driver column is color-coded on support level.
A support level column is also provided. It should be hidden in a graphic
browser but should be visible from a console based browser (w3m).
"""
from lxml import etree, html
from lxml.builder import E
if not type(deviceData).__name__ == "list" or len(deviceData) == 0:
raise Exception("Incorrect data was provided")
# HTML table columns definition
columns = [
{
"name": "manufacturer", "id": "manufacturer-col",
"text": "Manufacturer", "fields": ["manufacturer"]
},
{
"name": "model", "id": "model-col",
"text": "Model", "fields": ["model", "comment"]
},
{
"name": "driver", "id": "driver-col",
"text": "Driver", "fields": ["driver"]
},
{
"name": "support-level", "id": "support-level-col",
"text": "Support Level", "fields": ["support-level"]
},
]
# Device data fields definition
dataFields = [
"manufacturer", "device-type", "support-level",
"model", "comment", "driver"
]
# FIXME: CSS classes should be defined in script global settings
supportLevelClasses = {
"0": "", "1": "red", "2": "orange",
"3": "yellow", "4": "blue", "5": "green"
}
hiddenClass = "hidden"
# Build table header
table = E.table(id="ups_list", border="1")
header = E.tr()
for column in columns:
td = E.td(column.get("text"), id=column.get("id"))
if column["id"] == "support-level-col":
td.set("class", hiddenClass)
header.append(td)
table.append(E.thead(header))
# Build table body
tbody = E.tbody(id="ups_list_body")
cellHistory = []
rowHistory = deviceData[0][0]
rows = []
classes = ("even", "odd")
currentClass = 0
manufIndex = dataFields.index("manufacturer")
# Build table rows
for device in deviceData:
# Devices are expected to have a specified number of fields
if len(device) < len(dataFields):
print "Unexpected number of fields in device: %s" % device
print "Device will not be included in result set."
continue
# Alternate CSS class if current manufacturer is different from the last
if device[manufIndex] != rowHistory :
currentClass = (currentClass + 1) % 2
rowHistory = device[manufIndex]
cells = []
colIndex = 0
for column in columns:
cellContent = []
for field in column["fields"]:
fieldIndex = dataFields.index(field)
fieldContent = device[fieldIndex]
cellContent.append(html_escape(fieldContent))
cellContent = "<br />".join(cellContent)
try:
cH = cellHistory[colIndex]
except:
cH = False
if cH and cH.get("text") == cellContent:
cH["rowspan"] = cH.get("rowspan", 1) + 1
else:
cell = { "text": cellContent, "rowspan": 1 }
if column["name"] == "driver":
cell["class"] = supportLevelClasses[device[dataFields.index("support-level")]]
else:
cell["class"] = classes[currentClass]
if column["name"] == "support-level":
cell["class"] = hiddenClass
cells.append(cell)
try:
cellHistory[colIndex] = cell
except:
cellHistory.append(cell)
colIndex += 1
rows.append(cells)
for row in rows:
r = E.tr()
for cell in row:
attr = ""
innerHTML = ""
for key, value in cell.iteritems():
val = unicode(str(value), "utf-8")
if key != "text":
attr += " %s='%s'" % (key, val)
else:
innerHTML = val
r.append(html.fromstring("<td%s>%s</td>" % (attr, innerHTML)))
tbody.append(r)
table.append(tbody)
return etree.tostring(table, pretty_print=True)
deviceData = buildData(rawHCL)
# Dump device data as JSON
jsonData = "var UPSData = %s" % json.dumps(deviceData, encoding="utf-8")
try:
file = open(webJsonHCL, "w")
file.write(jsonData)
file.close()
print "JSON HCL written"
except IOError:
print "Unable to write JSON device data to %s" % webJsonHCL
exit(1)
# Create HTML table from device data
table = buildHTMLTable(deviceData)
try:
file = open(webStaticHCL, "w")
file.write("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
file.write(table)
file.write("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
print "HTML HCL written"
except IOError:
print "Unable to write HTML device table to %s" % webStaticHCL
exit(1)

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
#!/usr/bin/env perl
# Current Version : 1.0
# Copyright (C) 2008
# Copyright (C) 2008 - 2010
# Arnaud Quette <arnaud.quette@gmail.com>
# dloic (loic.dardant AT gmail DOT com)
#
@ -36,12 +36,12 @@ my $outputHotplug="../scripts/hotplug/libhid.usermap";
# udev output file
my $outputUdev="../scripts/udev/nut-usbups.rules.in";
# DeviceKit-power output file
my $outputDKp="../scripts/dkp/95-devkit-power-hid.rules";
# tmp output, to allow generating the ENV{DKP_VENDOR} header list
my $tmpOutputDKp;
# UPower output file
my $outputUPower="../scripts/upower/95-upower-hid.rules";
# tmp output, to allow generating the ENV{UPOWER_VENDOR} header list
my $tmpOutputUPower;
# mfr header flag
my $dkpMfrHeaderDone = 0;
my $upowerMfrHeaderDone = 0;
# array of products indexed by vendorID
my %vendor;
@ -79,20 +79,20 @@ sub gen_usb_files
# Udev file header
open my $outUdev, ">$outputUdev" || die "error $outputUdev : $!";
print $outUdev '# This file is generated and installed by the Network UPS Tools package.'."\n\n";
print $outUdev 'ACTION!="add", GOTO="nut-usbups_rules_end"'."\n";
print $outUdev 'ACTION!="add|change", GOTO="nut-usbups_rules_end"'."\n";
print $outUdev 'SUBSYSTEM=="usb_device", GOTO="nut-usbups_rules_real"'."\n";
print $outUdev 'SUBSYSTEM=="usb", GOTO="nut-usbups_rules_real"'."\n";
print $outUdev 'BUS!="usb", GOTO="nut-usbups_rules_end"'."\n\n";
print $outUdev 'SUBSYSTEM!="usb", GOTO="nut-usbups_rules_end"'."\n\n";
print $outUdev 'LABEL="nut-usbups_rules_real"'."\n";
# DeviceKit-power file header
open my $outputDKp, ">$outputDKp" || die "error $outputDKp : $!";
print $outputDKp '##############################################################################################################'."\n";
print $outputDKp '# Uninterruptible Power Supplies with USB HID interfaces'."\n#\n";
print $outputDKp '# to keep up to date, monitor: http://svn.debian.org/wsvn/nut/trunk/scripts/dkp/95-devkit-power-hid.rules'."\n\n";
print $outputDKp '# only support USB, else ignore'."\n".'SUBSYSTEM!="usb", GOTO="dkp_hid_end"'."\n\n";
print $outputDKp '# if usbraw device, ignore'."\n".'KERNEL!="hiddev*", GOTO="dkp_hid_end"'."\n\n";
print $outputDKp '# if an interface, ignore'."\n".'ENV{DEVTYPE}=="usb_interface", GOTO="dkp_hid_end"'."\n\n";
# UPower file header
open my $outputUPower, ">$outputUPower" || die "error $outputUPower : $!";
print $outputUPower '##############################################################################################################'."\n";
print $outputUPower '# Uninterruptible Power Supplies with USB HID interfaces'."\n#\n";
print $outputUPower '# to keep up to date, monitor: http://svn.debian.org/wsvn/nut/trunk/scripts/upower/95-upower-hid.rules'."\n\n";
print $outputUPower '# only support USB, else ignore'."\n".'SUBSYSTEM!="usb", GOTO="up_hid_end"'."\n\n";
print $outputUPower '# if usbraw device, ignore'."\n".'KERNEL!="hiddev*", GOTO="up_hid_end"'."\n\n";
print $outputUPower '# if an interface, ignore'."\n".'ENV{DEVTYPE}=="usb_interface", GOTO="up_hid_end"'."\n\n";
# generate the file in alphabetical order (first for VendorID, then for ProductID)
foreach my $vendorId (sort { lc $a cmp lc $b } keys %vendorName)
@ -113,8 +113,8 @@ sub gen_usb_files
print $outUdev "\n# ".$vendorName{$vendorId}."\n";
}
# DeviceKit-power vendor header flag
$dkpMfrHeaderDone = 0;
# UPower vendor header flag
$upowerMfrHeaderDone = 0;
foreach my $productId (sort { lc $a cmp lc $b } keys %{$vendor{$vendorId}})
{
@ -138,21 +138,21 @@ sub gen_usb_files
print $outUdev "\", ATTR{idProduct}==\"".removeHexPrefix($productId)."\",";
print $outUdev ' MODE="664", GROUP="@RUN_AS_GROUP@"'."\n";
# DeviceKit-power device entry (only for USB/HID devices!)
# UPower device entry (only for USB/HID devices!)
if ($vendor{$vendorId}{$productId}{"driver"} eq "usbhid-ups")
{
if ($dkpMfrHeaderDone == 0)
if ($upowerMfrHeaderDone == 0)
{
# DeviceKit-power vendor header
# UPower vendor header
if ($vendorName{$vendorId}) {
$tmpOutputDKp = $tmpOutputDKp."\n# ".$vendorName{$vendorId}."\n";
$tmpOutputUPower = $tmpOutputUPower."\n# ".$vendorName{$vendorId}."\n";
}
print $outputDKp "ATTRS{idVendor}==\"".removeHexPrefix($vendorId)."\", ENV{DKP_VENDOR}=\"".$vendorName{$vendorId}."\"\n";
$dkpMfrHeaderDone = 1;
print $outputUPower "ATTRS{idVendor}==\"".removeHexPrefix($vendorId)."\", ENV{UPOWER_VENDOR}=\"".$vendorName{$vendorId}."\"\n";
$upowerMfrHeaderDone = 1;
}
$tmpOutputDKp = $tmpOutputDKp."ATTRS{idVendor}==\"".removeHexPrefix($vendorId);
$tmpOutputDKp = $tmpOutputDKp."\", ATTRS{idProduct}==\"".removeHexPrefix($productId)."\",";
$tmpOutputDKp = $tmpOutputDKp.' ENV{DKP_BATTERY_TYPE}="ups"'."\n";
$tmpOutputUPower = $tmpOutputUPower."ATTRS{idVendor}==\"".removeHexPrefix($vendorId);
$tmpOutputUPower = $tmpOutputUPower."\", ATTRS{idProduct}==\"".removeHexPrefix($productId)."\",";
$tmpOutputUPower = $tmpOutputUPower.' ENV{UPOWER_BATTERY_TYPE}="ups"'."\n";
}
}
# HAL vendor footer
@ -166,11 +166,11 @@ sub gen_usb_files
# Udev footer
print $outUdev "\n".'LABEL="nut-usbups_rules_end"'."\n";
# DeviceKit-power...
# UPower...
# ...flush device table
print $outputDKp $tmpOutputDKp;
print $outputUPower $tmpOutputUPower;
# ...and print footer
print $outputDKp "\n".'LABEL="dkp_hid_end"'."\n";
print $outputUPower "\n".'LABEL="up_hid_end"'."\n";
}
sub find_usbdevs
@ -244,9 +244,6 @@ sub find_usbdevs
elsif ($nameFile eq "tripplite_usb.c") {
$driver="tripplite_usb";
}
elsif ($nameFile eq "megatec_usb.c") {
$driver="megatec_usb";
}
elsif ($nameFile eq "blazer_usb.c") {
$driver="blazer_usb";
}

5
tools/svn2cl.authors Normal file
View file

@ -0,0 +1,5 @@
clepple-guest:Charles Lepple <clepple+nut@gmail.com>
adkorte-guest:Arjen de Korte <adkorte-guest@alioth.debian.org>
aquette:Arnaud Quette <arnaud.quette@free.fr>
lestat-guest:David Goncalves <david@lestat.st>
chetanagarwal-guest: Chetan Agarwal <chetanagarwal-guest@alioth.debian.org>