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

pere at alioth.debian.org pere at alioth.debian.org
Wed Jan 9 20:57:43 UTC 2013


Author: pere
Date: 2013-01-09 20:57:42 +0000 (Wed, 09 Jan 2013)
New Revision: 78689

Modified:
   trunk/src/hw-support-handler/hw-support-handlerd
Log:
Do not suggest packages that are already installed.

Modified: trunk/src/hw-support-handler/hw-support-handlerd
===================================================================
--- trunk/src/hw-support-handler/hw-support-handlerd	2013-01-09 20:57:18 UTC (rev 78688)
+++ trunk/src/hw-support-handler/hw-support-handlerd	2013-01-09 20:57:42 UTC (rev 78689)
@@ -7,6 +7,7 @@
 import gtk
 import gobject
 import pynotify
+import subprocess
 
 hw_seen = {}
 pkg_suggested = {}
@@ -31,6 +32,19 @@
     n.show()
     return True
 
+def is_pkg_installed(packagename):
+    cmd = ["dpkg", "-l", packagename]
+    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    while True:
+        retcode = p.poll()
+        line = p.stdout.readline()
+        if(retcode is not None):
+            line = None
+            return 0 == retcode
+    line = None
+    return False
+
+
 # While get_pkg_suggestions always return all suggestions, start by
 # igoring those plugged in when we start.
 def ignore_initial_suggestions():
@@ -44,7 +58,6 @@
 def get_pkg_suggestions(bus, vendor, device):
     pkgs = []
     cmd = ["/sbin/discover-pkginstall", "-l"]
-    import subprocess
     p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     while True:
         retcode = p.poll()
@@ -69,16 +82,17 @@
             f = devinfo.split('_')
             vendor = int(f[2], 16)
             device = int(f[3], 16)
+            print "Discovered USB device %04x:%04x" % (vendor, device)
             if (vendor, device) not in hw_seen:
                 pkgs = get_pkg_suggestions(bus, vendor, device)
-                hw_seen[(vendor, device)] = True
                 newpkg = []
                 for pkg in pkgs:
-                    if pkg not in pkg_suggested:
+                    if pkg not in pkg_suggested and not is_pkg_installed(pkg):
                         newpkg.append(pkg)
                         pkg_suggested[pkg] = True
                 if 0 < len(newpkg):
                     notify(bus, vendor, device, newpkg)
+                hw_seen[(vendor, device)] = True
 
 def main():
     ignore_initial_suggestions()
@@ -86,6 +100,7 @@
     system_bus = dbus.SystemBus()
     system_bus.add_signal_receiver(catchall_signal_handler, interface_keyword='dbus_interface', member_keyword='member')
     loop = gobject.MainLoop()
+    print "ready to accept hardware events"
     loop.run()
 
 if __name__ == '__main__':




More information about the debian-edu-commits mailing list