[debian-edu-commits] r78780 - in trunk/src/hw-support-handler: . debian

pere at alioth.debian.org pere at alioth.debian.org
Fri Jan 18 09:04:57 UTC 2013


Author: pere
Date: 2013-01-18 09:04:57 +0000 (Fri, 18 Jan 2013)
New Revision: 78780

Modified:
   trunk/src/hw-support-handler/debian/control
   trunk/src/hw-support-handler/hw-support-handlerd
Log:
Rewrite from using hal/dbus for events to fetching kernel events directly using python-gudev.  Drop obsolete discover based code.

Modified: trunk/src/hw-support-handler/debian/control
===================================================================
--- trunk/src/hw-support-handler/debian/control	2013-01-18 05:47:23 UTC (rev 78779)
+++ trunk/src/hw-support-handler/debian/control	2013-01-18 09:04:57 UTC (rev 78780)
@@ -4,10 +4,12 @@
 Maintainer: Petter Reinholdtsen <pere at debian.org>
 Build-Depends: debhelper (>= 8), po-debconf
 Build-Depends-Indep: dash (>= 0.5.4-12)
-  , hal
-  , python-dbus
+  , python-gudev
   , python-gobject
   , python-notify
+  , aptdaemon
+  , python-aptdaemon-gtk
+  , libgnome2-perl
 Standards-Version: 3.9.4
 Vcs-Browser: http://anonscm.debian.org/viewvc/debian-edu/trunk/src/hw-support-handler/
 Vcs-Svn: svn://svn.debian.org/debian-edu/trunk/src/hw-support-handler/
@@ -17,8 +19,7 @@
 Architecture: all
 Depends: ${misc:Depends}
   , ${python:Depends}
-  , hal
-  , python-dbus
+  , python-gudev
   , python-gobject
   , python-notify
   , aptdaemon

Modified: trunk/src/hw-support-handler/hw-support-handlerd
===================================================================
--- trunk/src/hw-support-handler/hw-support-handlerd	2013-01-18 05:47:23 UTC (rev 78779)
+++ trunk/src/hw-support-handler/hw-support-handlerd	2013-01-18 09:04:57 UTC (rev 78780)
@@ -26,11 +26,10 @@
 __author__ = "Petter Reinholdtsen <pere at hungry.com>"
 
 import string
-import dbus
-from dbus.mainloop.glib import DBusGMainLoop
 #import pygtk
 import gtk
 import gobject
+import gudev
 import pynotify
 import subprocess
 import glob
@@ -171,31 +170,6 @@
             break
     return retval
 
-# While get_pkg_suggestions always return all suggestions, start by
-# igoring those plugged in when we start.
-def ignore_initial_suggestions():
-    pkgs = get_pkg_suggestions("", 0, 0);
-    for pkg in pkgs:
-        pkg_suggested[pkg] = True
-
-# 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_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)
-    while True:
-        retcode = p.poll()
-        pkgline = p.stdout.readline()
-        if pkgline != "":
-            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
@@ -209,49 +183,36 @@
         f.close()
     return modalias
 
-def get_pkg_suggestions_aptmodaliases(bus, vendor, device):
+def get_pkg_suggestions_aptmodaliases(modalias):
     print "info: checking apt modaliases info"
-    modalias = devid2modalias(bus, vendor, device)
-
-    if modalias is None:
-        return []
     return hwsupport.lookup.pkgs_handling_apt_modaliases([modalias])
 
-def get_pkg_suggestions_mymodaliases(bus, vendor, device):
+def get_pkg_suggestions_mymodaliases(modalias):
     print "info: checking my modaliases file (from svn)"
-    modalias = devid2modalias(bus, vendor, device)
-
-    if modalias is None:
-        return []
     return hwsupport.lookup.pkgs_handling_extra_modaliases([modalias])
 
-def get_pkg_suggestions(bus, vendor, device):
+def get_pkg_suggestions(modalias):
     pkgs = []
 #    discoverpkgs = get_pkg_suggestions_discover(bus, vendor, device)
 #    pkgs.extend(discoverpkgs)
-    aptpkgs = get_pkg_suggestions_aptmodaliases(bus, vendor, device)
+    aptpkgs = get_pkg_suggestions_aptmodaliases(modalias)
     pkgs.extend(aptpkgs)
-    mypkgs = get_pkg_suggestions_mymodaliases(bus, vendor, device)
+    mypkgs = get_pkg_suggestions_mymodaliases(modalias)
     pkgs.extend(mypkgs)
     return pkgs
 
-def catchall_signal_handler(*args, **kwargs):
-# Trigger on
-#   dbus_interface="org.freedesktop.Hal.Manager"
-#   member="DeviceAdded"
-#   args[0]="/org/freedesktop/Hal/devices/usb_device_781_5530_200531467118B5A19655"
-    if "org.freedesktop.Hal.Manager" == kwargs['dbus_interface'] and \
-            "DeviceAdded" == kwargs['member']:
-        devinfo = args[0].split('/')[5]
-#        print devinfo
-        if "usb_device" == devinfo[0:len("usb_device")]:
-            bus = "usb"
-            f = devinfo.split('_')
-            vendor = int(f[2], 16)
-            device = int(f[3], 16)
-            print "info: discovered USB device %04x:%04x" % (vendor, device)
-            if (vendor, device) not in hw_seen:
-                pkgs = get_pkg_suggestions(bus, vendor, device)
+def uevent_callback(client, action, device, user_data):
+    modalias = device.get_property("MODALIAS")
+    if ("add" == action and modalias is not None):
+        device_vendor = device.get_property("ID_VENDOR_ENC")
+        device_model = device.get_property("ID_MODEL_ENC")
+        print "uevent %s %s %s" % (device_vendor, device_model, modalias)
+        bus = device.get_subsystem()
+        if "usb" == bus:
+            print "info: discovered USB device %s %s" % (device_vendor,
+                                                         device_model)
+            if modalias not in hw_seen:
+                pkgs = get_pkg_suggestions(modalias)
 #                print "Suggestions: ", pkgs
                 newpkg = []
                 for pkg in pkgs:
@@ -259,16 +220,15 @@
                         newpkg.append(pkg)
                         pkg_suggested[pkg] = True
                 if 0 < len(newpkg):
-                    notify(bus, vendor, device, newpkg)
-                hw_seen[(vendor, device)] = True
+                    vendorid, deviceid, bcdevice = \
+                        device.get_property("PRODUCT").split("/")
+                    notify(bus, int(vendorid, 16), int(deviceid, 16), newpkg)
+                hw_seen[modalias] = True
 
 def main():
-    ignore_initial_suggestions()
-    DBusGMainLoop(set_as_default=True)
-    system_bus = dbus.SystemBus()
-    system_bus.add_signal_receiver(catchall_signal_handler,
-                                   interface_keyword='dbus_interface',
-                                   member_keyword='member')
+    client = gudev.Client([])
+    client.connect("uevent", uevent_callback, None)
+
     loop = gobject.MainLoop()
     print "info: ready to accept hardware events"
     loop.run()




More information about the debian-edu-commits mailing list