File virtman-dbus-query.diff of Package virt-manager

diff -Nuar virt-manager-0.5.3.orig/src/virtManager/connection.py virt-manager-0.5.3/src/virtManager/connection.py
--- virt-manager-0.5.3.orig/src/virtManager/connection.py	2008-03-31 14:32:40.000000000 -0600
+++ virt-manager-0.5.3/src/virtManager/connection.py	2008-03-31 15:23:14.000000000 -0600
@@ -136,6 +136,19 @@
 
         self.detect_network_devices()
 
+    # A bug in hal/dbus prevents us from calling QueryCapability on devices
+    # this is a temporary workaround that can be removed when we get
+    # a newer hald/hald_dbus.c
+    def _query_capability(self, device_interface, str_capability):
+        if device_interface == None:
+            return False
+        if not device_interface.PropertyExists('info.capabilities'):
+            return False
+        cap_set = set(device_interface.GetProperty('info.capabilities'))
+        if str_capability in cap_set:
+            return True
+        return False
+
     def detect_network_devices(self):
         try:
             # Get a connection to the SYSTEM bus
@@ -165,9 +178,11 @@
 
     def _device_added(self, path):
         obj = self.bus.get_object("org.freedesktop.Hal", path)
-        if obj.QueryCapability("net"):
-            name = obj.GetPropertyString("net.interface")
-            mac = obj.GetPropertyString("net.address")
+        iface = dbus.Interface(obj,"org.freedesktop.Hal.Device")
+        iface.PropertyExists('info.capabilities')
+        if self._query_capability(iface,"net"):
+            name = iface.GetPropertyString("net.interface")
+            mac = iface.GetPropertyString("net.address")
 
             # Now magic to determine if the device is part of a bridge
             shared = False
@@ -175,7 +190,7 @@
             try:
                 # XXX Linux specific - needs porting for other OS - patches
                 # welcomed...
-                sysfspath = obj.GetPropertyString("linux.sysfs_path")
+                sysfspath = iface.GetPropertyString("linux.sysfs_path")
 
                 # If running a device in bridged mode, there's a reasonable
                 # chance that the actual ethernet device has been renamed to
diff -Nuar virt-manager-0.5.3.orig/src/virtManager/opticalhelper.py virt-manager-0.5.3/src/virtManager/opticalhelper.py
--- virt-manager-0.5.3.orig/src/virtManager/opticalhelper.py	2008-01-10 18:17:51.000000000 -0700
+++ virt-manager-0.5.3/src/virtManager/opticalhelper.py	2008-03-31 15:24:16.000000000 -0600
@@ -41,6 +41,19 @@
             self.hal_iface = None
             raise
 
+    # A bug in hal prevents us from calling QueryCapability on devices
+    # this is a temporary workaround that can be removed when we get
+    # a newer hald/hald_dbus.c
+    def _query_capability(self, device_interface, str_capability):
+        if device_interface == None:
+            return False
+        if not device_interface.PropertyExists('info.capabilities'):
+            return False
+        cap_set = set(device_interface.GetProperty('info.capabilities'))
+        if str_capability in cap_set:
+            return True
+        return False
+
     def populate_opt_media(self):
         # get a list of optical devices with data discs in, for FV installs
         vollabel = {}
@@ -52,10 +65,11 @@
         # Find info about all current present media
         for d in self.hal_iface.FindDeviceByCapability("volume"):
             vol = self.bus.get_object("org.freedesktop.Hal", d)
-            if vol.GetPropertyBoolean("volume.is_disc") and \
-                   vol.GetPropertyBoolean("volume.disc.has_data"):
-                devnode = vol.GetProperty("block.device")
-                label = vol.GetProperty("volume.label")
+            iface = dbus.Interface(vol,"org.freedesktop.Hal.Device")
+            if iface.GetPropertyBoolean("volume.is_disc") and \
+                   iface.GetPropertyBoolean("volume.disc.has_data"):
+                devnode = iface.GetProperty("block.device")
+                label = iface.GetProperty("volume.label")
                 if label == None or len(label) == 0:
                     label = devnode
                 vollabel[devnode] = label
@@ -63,7 +77,9 @@
 
         for d in self.hal_iface.FindDeviceByCapability("storage.cdrom"):
             dev = self.bus.get_object("org.freedesktop.Hal", d)
-            devnode = dev.GetProperty("block.device")
+            iface = dbus.Interface(dev,"org.freedesktop.Hal.Device")
+            iface.PropertyExists('info.capabilities')
+            devnode = iface.GetProperty("block.device")
             if vollabel.has_key(devnode):
                 self.model.append([devnode, vollabel[devnode], True, volpath[devnode]])
             else:
@@ -71,11 +87,13 @@
 
     def _device_added(self, path):
         vol = self.bus.get_object("org.freedesktop.Hal", path)
-        if vol.QueryCapability("volume"):
-            if vol.GetPropertyBoolean("volume.is_disc") and \
-                   vol.GetPropertyBoolean("volume.disc.has_data"):
-                devnode = vol.GetProperty("block.device")
-                label = vol.GetProperty("volume.label")
+        iface = dbus.Interface(vol,"org.freedesktop.Hal.Device")
+        iface.PropertyExists('info.capabilities')
+        if self._query_capability(iface,"volume"):
+            if iface.GetPropertyBoolean("volume.is_disc") and \
+                   iface.GetPropertyBoolean("volume.disc.has_data"):
+                devnode = iface.GetProperty("block.device")
+                label = iface.GetProperty("volume.label")
                 if label == None or len(label) == 0:
                     label = devnode
 
openSUSE Build Service is sponsored by