[debian-edu-commits] r78714 - in trunk/src/hw-support-handler: . debian
pere at alioth.debian.org
pere at alioth.debian.org
Fri Jan 11 23:23:53 UTC 2013
Author: pere
Date: 2013-01-11 23:23:53 +0000 (Fri, 11 Jan 2013)
New Revision: 78714
Modified:
trunk/src/hw-support-handler/debian/control
trunk/src/hw-support-handler/debian/hw-support-handler.install
trunk/src/hw-support-handler/hw-support-handlerd
Log:
Stop using discover and use the local modaliases file generated from discover-data instead.
Modified: trunk/src/hw-support-handler/debian/control
===================================================================
--- trunk/src/hw-support-handler/debian/control 2013-01-11 22:37:09 UTC (rev 78713)
+++ trunk/src/hw-support-handler/debian/control 2013-01-11 23:23:53 UTC (rev 78714)
@@ -4,7 +4,6 @@
Maintainer: Petter Reinholdtsen <pere at debian.org>
Build-Depends: debhelper (>= 8), po-debconf
Build-Depends-Indep: dash (>= 0.5.4-12)
- , discover (>= 2.1.2-6)
, hal
, python-dbus
, python-gobject
@@ -18,7 +17,6 @@
Architecture: all
Depends: ${misc:Depends}
, ${python:Depends}
- , discover (>= 2.1.2-6)
, hal
, python-dbus
, python-gobject
Modified: trunk/src/hw-support-handler/debian/hw-support-handler.install
===================================================================
--- trunk/src/hw-support-handler/debian/hw-support-handler.install 2013-01-11 22:37:09 UTC (rev 78713)
+++ trunk/src/hw-support-handler/debian/hw-support-handler.install 2013-01-11 23:23:53 UTC (rev 78714)
@@ -1,2 +1,3 @@
hw-support-handlerd usr/bin
hw-support-handlerd.desktop usr/share/autostart
+modaliases usr/share/hw-support-handler
Modified: trunk/src/hw-support-handler/hw-support-handlerd
===================================================================
--- trunk/src/hw-support-handler/hw-support-handlerd 2013-01-11 22:37:09 UTC (rev 78713)
+++ trunk/src/hw-support-handler/hw-support-handlerd 2013-01-11 23:23:53 UTC (rev 78714)
@@ -21,9 +21,10 @@
print "info: buttonclicked: %s" % string.join(pkgs, " ")
def notify(bus, vendor, device, pkgs):
+ pkgstr = string.join(pkgs, " ")
info = "New %s device [%04x:%04x] supported by package(s) %s." \
- % (bus, vendor, device, string.join(pkgs, " "))
- instructions = "To install, run /sbin/discover-pkginstall as user root."
+ % (bus, vendor, device, pkgstr)
+ instructions = "To install, run \"apt-get install %s\" as user root." % pkgstr
title = "New %s device" % bus
text = info + " " + instructions
@@ -64,7 +65,8 @@
# Currently just ask discover for the set of suggested packages.
# FIXME Should only return the suggested packages for the provided
# bus+vendor+device.
-def get_pkg_suggestions(bus, vendor, device):
+def get_pkg_suggestions_discover(bus, vendor, device):
+ print "info: quering discover-pkginstall"
pkgs = []
cmd = ["/sbin/discover-pkginstall", "-l"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@@ -88,9 +90,26 @@
if fnmatch.fnmatch(line, target):
modalias = line
# print filename
+ f.close()
return modalias
-def get_pkg_suggestions_modaliases(bus, vendor, device):
+def modalias_match(alias, candidates):
+ for part in candidates.split(')'):
+ part = part.strip(', ')
+ if not part:
+ continue
+ module, lst = part.split('(')
+ for candidate in lst.split(','):
+ candidate = candidate.strip()
+ bus = candidate.split(':', 1)[0]
+# print bus, alias, modalias, pkg.name
+ if fnmatch.fnmatch(alias, candidate):
+# print "Match for %s" % pkg.name
+ return True
+ return False
+
+def get_pkg_suggestions_aptmodaliases(bus, vendor, device):
+ print "info: checking apt modaliases info"
modalias = devid2modalias(bus, vendor, device)
if modalias is None:
@@ -110,20 +129,47 @@
continue
entries = record['Modaliases']
# print pkg.name
- for part in entries.split(')'):
- part = part.strip(', ')
- if not part:
- continue
- module, lst = part.split('(')
- for alias in lst.split(','):
- alias = alias.strip()
- bus = alias.split(':', 1)[0]
-# print bus, alias, modalias, pkg.name
- if fnmatch.fnmatch(modalias, alias):
-# print "Match for %s" % pkg.name
- thepkgs.append(pkg.name)
+ if modalias_match(modalias, entries):
+ thepkgs.append(pkg.name)
return thepkgs
+def get_pkg_suggestions_mymodaliases(bus, vendor, device):
+ print "info: checking my modaliases file"
+ modalias = devid2modalias(bus, vendor, device)
+
+ if modalias is None:
+ return []
+
+ thepkgs = []
+ filename = "/usr/share/hw-support-handler/modaliases"
+ try:
+ f = open(filename)
+ except IOError: # No global file, try the local one
+ # FIXME remove this code in production, only for testing
+ filename = "modaliases"
+ f = open(filename)
+ line = f.readline()
+ while line:
+ header, sep, packagename = line.strip().partition(": ")
+ header, sep, modaliases = f.readline().strip().partition(": ")
+ blank = f.readline()
+# print packagename, modaliases
+ if modalias_match(modalias, modaliases):
+ thepkgs.append(packagename)
+ line = f.readline()
+ f.close()
+ return thepkgs
+
+def get_pkg_suggestions(bus, vendor, device):
+ pkgs = []
+# discoverpkgs = get_pkg_suggestions_discover(bus, vendor, device)
+# pkgs.extend(discoverpkgs)
+ aptpkgs = get_pkg_suggestions_aptmodaliases(bus, vendor, device)
+ pkgs.extend(aptpkgs)
+ mypkgs = get_pkg_suggestions_mymodaliases(bus, vendor, device)
+ pkgs.extend(mypkgs)
+ return pkgs
+
def catchall_signal_handler(*args, **kwargs):
# Trigger on
# dbus_interface="org.freedesktop.Hal.Manager"
@@ -141,8 +187,6 @@
print "info: discovered USB device %04x:%04x" % (vendor, device)
if (vendor, device) not in hw_seen:
pkgs = get_pkg_suggestions(bus, vendor, device)
- aptpkgs = get_pkg_suggestions_modaliases(bus, vendor, device)
- pkgs.extend(aptpkgs)
# print pkgs
newpkg = []
for pkg in pkgs:
More information about the debian-edu-commits
mailing list