[conduit/udev: 2/2] more udev work



commit 536607e5cfd3a7d5e0b633c36ce5a3020286e15f
Author: John Stowers <john stowers gmail com>
Date:   Mon Mar 29 08:33:39 2010 +0200

    more udev work

 conduit/dataproviders/DataProvider.py    |   11 ++++
 conduit/dataproviders/HalFactory.py      |   83 ++++++++++++++++--------------
 conduit/dataproviders/VolumeFactory.py   |   58 ---------------------
 conduit/modules/iPodModule/iPodModule.py |    2 +-
 4 files changed, 57 insertions(+), 97 deletions(-)
---
diff --git a/conduit/dataproviders/DataProvider.py b/conduit/dataproviders/DataProvider.py
index 839b6e4..bc27682 100644
--- a/conduit/dataproviders/DataProvider.py
+++ b/conduit/dataproviders/DataProvider.py
@@ -568,6 +568,10 @@ class DataProviderFactory(gobject.GObject):
         gobject.GObject.__init__(self)
 
     def emit_added(self, klass, initargs, category, customKey=None):
+        """
+        Emits the dataprovider-added signal for the given class with the
+        given conctruction arguments
+        """
         dpw = ModuleWrapper.ModuleWrapper(   
                     klass=klass,
                     initargs=initargs,
@@ -580,10 +584,17 @@ class DataProviderFactory(gobject.GObject):
         return key
 
     def emit_removed(self, key):
+        """
+        Emits the dataprovider-removed signal
+        """
         log.debug("DataProviderFactory %s: Emitting dataprovider-removed for %s" % (self, key))
         self.emit("dataprovider-removed", key)
 
     def probe(self):
+        """
+        Search for appropriate connected devices, calling emit_added or
+        emit_removed for each device
+        """
         pass
 
     def quit(self):
diff --git a/conduit/dataproviders/HalFactory.py b/conduit/dataproviders/HalFactory.py
index fb339cd..0f2fd41 100644
--- a/conduit/dataproviders/HalFactory.py
+++ b/conduit/dataproviders/HalFactory.py
@@ -12,54 +12,61 @@ log.info("Module Information: %s" % Utils.get_module_information(gudev, "__versi
 
 class HalFactory(SimpleFactory.SimpleFactory):
 
+    SUBSYSTEMS = ("usb", "block")
+
     def __init__(self, **kwargs):
         SimpleFactory.SimpleFactory.__init__(self, **kwargs)
 
-        # Connect to system HAL
-        self.bus = dbus.SystemBus()
-        self.hal_obj = self.bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
-        self.hal = dbus.Interface(self.hal_obj, "org.freedesktop.Hal.Manager")
+        assert hasattr(self.SUBSYSTEMS, "__iter__")
 
-        # Hookup signals
-        self.hal.connect_to_signal("DeviceAdded", self._device_added)
-        self.hal.connect_to_signal("DeviceRemoved", self._device_removed)
-        self.hal.connect_to_signal("NewCapability", self._new_capability)
+        self.gudev = gudev.Client(self.SUBSYSTEMS)
+        self.gudev.connect("uevent", self._on_uevent)
 
-    def _maybe_new(self, device_udi):
-        props = self._get_properties(device_udi)
-        if self.is_interesting(device_udi, props):
-            self.item_added(device_udi, **props)
+    def _print_device(self, device):
+        print "subsystem", device.get_subsystem()
+        print "devtype", device.get_devtype()
+        print "name", device.get_name()
+        print "number", device.get_number()
+        print "sysfs_path:", device.get_sysfs_path()
+        print "driver:", device.get_driver()
+        print "action:", device.get_action()
+        print "seqnum:", device.get_seqnum()
+        print "device type:", device.get_device_type()
+        print "device number:", device.get_device_number()
+        print "device file:", device.get_device_file()
+        print "device file symlinks:", ", ".join(device.get_device_file_symlinks())
+        print "device keys:", ", ".join(device.get_property_keys())
+        for device_key in device.get_property_keys():
+            print "   device property %s: %s"  % (device_key, device.get_property(device_key))
 
-    def _device_added(self, device_udi, *args):
-        self._maybe_new(device_udi)
+    def _on_uevent(self, client, action, device):
+        self._print_device(device)
+#        self._maybe_new
 
-    def _new_capability(self, device_udi, *args):
-        if not device_udi in self.items.keys():
-            self._maybe_new(device_udi)
+    def get_udev_device_for_sysfs_path(self, sysfs_path):
+        return self.gudev.query_by_sysfs_path(sysfs_path)
 
-    def _device_removed(self, device_udi):
-        self.item_removed(device_udi)
+    def _maybe_new(self, device):
+        props = self._get_properties(sysfs_path)
+        if self.is_interesting(sysfs_path, props):
+            self.item_added(sysfs_path, **props)
 
+#    def _device_added(self, sysfs_path, *args):
+#        self._maybe_new(sysfs_path)
+#
+#    def _new_capability(self, sysfs_path, *args):
+#        if not sysfs_path in self.items.keys():
+#            self._maybe_new(sysfs_path)
+#
+#    def _device_removed(self, sysfs_path):
+#        self.item_removed(sysfs_path)
+#
     def _get_properties(self, device):
-        buf = {}
-        try:
-            device_dbus_obj = self.bus.get_object("org.freedesktop.Hal" ,device)
-            for x, y in device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device").items():
-                #DBus *still* does not marshal dbus.String to str correctly,
-                #so we force it to
-                buf[str(x)] = y
-        except:
-            log.warn("Could not get HAL properties for %s" % device_udi)
-        return buf
+        log.critical("NOT IMPLEMENTED")
+        return {}
 
     def probe(self):
-        """
-        Enumerate HAL for any entries of interest
-        """
-        devices = self.hal.GetAllDevices()
-        for device in self.hal.GetAllDevices():
-            self._maybe_new(str(device))
-
-    def get_args(self, udi, **kwargs):
-        return (udi,)
+        for s in self.SUBSYSTEMS:
+            for d in self.gudev.query_by_subsystem(s):
+                self._maybe_new(d)
 
diff --git a/conduit/modules/iPodModule/iPodModule.py b/conduit/modules/iPodModule/iPodModule.py
index 6b72885..291eb45 100644
--- a/conduit/modules/iPodModule/iPodModule.py
+++ b/conduit/modules/iPodModule/iPodModule.py
@@ -24,7 +24,7 @@ log = logging.getLogger("modules.iPod")
 import conduit
 import conduit.dataproviders.DataProvider as DataProvider
 import conduit.dataproviders.DataProviderCategory as DataProviderCategory
-import conduit.dataproviders.VolumeFactory as VolumeFactory
+import conduit.dataproviders.HalFactory as HalFactory
 import conduit.utils as Utils
 import conduit.datatypes.Note as Note
 import conduit.datatypes.Contact as Contact



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]