[debian-edu-commits] r78697 - trunk/src/hw-support-handler

pere at alioth.debian.org pere at alioth.debian.org
Thu Jan 10 17:27:11 UTC 2013


Author: pere
Date: 2013-01-10 17:27:10 +0000 (Thu, 10 Jan 2013)
New Revision: 78697

Modified:
   trunk/src/hw-support-handler/hw-support-handlerd
Log:
Implement support for Modaliases in the Packages file.  Minor cleanups in output.

Modified: trunk/src/hw-support-handler/hw-support-handlerd
===================================================================
--- trunk/src/hw-support-handler/hw-support-handlerd	2013-01-10 14:26:43 UTC (rev 78696)
+++ trunk/src/hw-support-handler/hw-support-handlerd	2013-01-10 17:27:10 UTC (rev 78697)
@@ -8,13 +8,17 @@
 import gobject
 import pynotify
 import subprocess
+import glob
+import fnmatch
+import sys
+import apt
 
 hw_seen = {}
 pkg_suggested = {}
 
 def notify_pleaseinstall(notification=None, action=None, data=None):
     pkgs = data
-    print "Buttonclicked: %s" % string.join(pkgs, " ")
+    print "info: buttonclicked: %s" % string.join(pkgs, " ")
 
 def notify(bus, vendor, device, pkgs):
     info = "New %s device [%04x:%04x] supported by package(s) %s." \
@@ -23,7 +27,7 @@
     title = "New %s device" % bus
     text = info + "  " + instructions
 
-    print info
+    print "info: " + info
 
     # Initializite pynotify
     if not pynotify.init("test"):
@@ -68,12 +72,62 @@
         retcode = p.poll()
         pkgline = p.stdout.readline()
         if pkgline != "":
-            for pkg in pkgline.rstrip().split(" "):
+            for pkg in pkgline.strip().split(" "):
                 pkgs.append(pkg)
         if(retcode is not None):
             break
     return pkgs
 
+def devid2modalias(bus, vendor, device):
+    target = "%s:v%04xp%04xd*" % (bus, vendor, device)
+    modalias = None
+    for filename in glob.iglob("/sys/bus/%s/devices/*/modalias" % bus):
+        f = open(filename)
+        line = f.readline().strip()
+#        print line, target
+        if fnmatch.fnmatch(line, target):
+            modalias = line
+#            print filename
+    return modalias
+
+def get_pkg_suggestions_modaliases(bus, vendor, device):
+    modalias = devid2modalias(bus, vendor, device)
+
+    if modalias is None:
+        return []
+
+    cache = apt.Cache()
+    cache.open(None)
+    thepkgs = []
+    for pkg in cache:
+        version = pkg.candidate
+        if version is None:
+            version = pkg.installed
+        if version is None:
+            continue
+        record = version.record
+        if not record.has_key('Modaliases'):
+            continue
+        entries = record['Modaliases']
+        entries = "foo(usb:v0781p5530d*)"
+#        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)
+    return thepkgs
+
+#print get_pkg_suggestions_apt("usb", int('0x0781', 16), int('0x5530', 16))
+#exit(0)
+
 def catchall_signal_handler(*args, **kwargs):
 # Trigger on
 #   dbus_interface="org.freedesktop.Hal.Manager"
@@ -88,9 +142,11 @@
             f = devinfo.split('_')
             vendor = int(f[2], 16)
             device = int(f[3], 16)
-            print "Discovered USB device %04x:%04x" % (vendor, device)
+            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:
@@ -109,7 +165,7 @@
                                    interface_keyword='dbus_interface',
                                    member_keyword='member')
     loop = gobject.MainLoop()
-    print "ready to accept hardware events"
+    print "info: ready to accept hardware events"
     loop.run()
 
 if __name__ == '__main__':




More information about the debian-edu-commits mailing list