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

Re: [PATCH 11/15] Use HAL to probe for disks. Add a removableDriveDict for use by the exception dialog.



Jeremy Katz (katzj redhat com) said: 
> Some of these can and do raise exceptions.  Also, it'd probably be a
> little cleaner if we had an abstraction around the hal stuff so that we
> could avoid littering the world with dbus calls.  That would also make
> it a little easier to adapt in the future when hal is rewritten.  

Here ya go.

commit e01e37c61b84ac3bf3d53ab342c8abb9ea38a885
Author: Bill Nottingham <notting redhat com>
Date:   Thu Dec 6 18:30:56 2007 -0500

    Add some utility functions that wrap HAL operations we need.

diff --git a/minihal.py b/minihal.py
new file mode 100644
index 0000000..d7f2bf4
--- /dev/null
+++ b/minihal.py
@@ -0,0 +1,70 @@
+#
+# minihal.py: Simple wrapper around HAL
+#
+# Bill Nottingham <notting redhat com>
+#
+# Copyright 2007 Red Hat, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# library public license.
+#
+# You should have received a copy of the GNU Library Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+"""Simple wrapper around HAL"""
+
+import dbus
+
+try:
+    bus = dbus.SystemBus()
+    hal = dbus.Interface(bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager")
+except:
+    bus = None
+    hal = None  
+
+def get_device(udi):
+    """Retrieve all properties of a particular device (by UDI)"""
+    try:
+        bus = dbus.SystemBus()
+        haldev = dbus.Interface(bus.get_object("org.freedesktop.Hal", udi), "org.freedesktop.Hal.Device")
+        props = haldev.GetAllProperties()
+    except dbus.exceptions.DBusException:
+        return None
+
+    if props.has_key('block.device'):
+        props['device'] = props['block.device']
+    elif props.has_key('linux.device_file'):
+        props['device'] = props['linux.device_file']
+    elif props.has_key('net.interface'):
+        props['device'] = props['net.interface']
+    else:
+        props['device'] = None
+
+    if props.has_key('info.product'):
+        if props.has_key('info.vendor'):
+            props['description'] = '%s %s' % (props['info.vendor'],props['info.product'])
+        else:
+            props['description'] = props['info.product']
+    else:
+        props['description'] = props['info.udi']
+    if props.has_key('net.physical_device'):
+        pdev = get_device(props['net.physical_device'])
+        props['description'] = pdev['description']
+
+    return props
+
+def get_devices_by_type(type):
+    """Retrieve all devices of a particular type"""
+    ret = []
+    try:
+        bus = dbus.SystemBus()
+        hal = dbus.Interface(bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager")
+    except:
+        return ret
+    for udi in hal.FindDeviceByCapability(type):
+        dev = get_device(udi)
+        if dev:
+            ret.append(dev)
+    return ret
+            
+    
\ No newline at end of file

commit 8c348d5ce98a4ccc5dbe5398b862304827ad6d51
Author: Bill Nottingham <notting redhat com>
Date:   Thu Dec 6 18:51:56 2007 -0500

    Use HAL to probe for available network devices.

diff --git a/network.py b/network.py
index 3e16214..c8b8fa9 100644
--- a/network.py
+++ b/network.py
@@ -21,7 +21,7 @@ import isys
 import iutil
 import socket
 import os
-import kudzu
+import minihal
 import rhpl
 from flags import flags
 
@@ -256,66 +256,27 @@ class Network:
 	    if not oneactive:
 		self.netdevices[self.firstnetdevice].set(("onboot", "yes"))
 
-	    # assign description to each device based on kudzu information
-	    probedevs = kudzu.probe(kudzu.CLASS_NETWORK, kudzu.BUS_UNSPEC, kudzu.PROBE_LOADED)
-	    for netdev in probedevs:
-		device = netdev.device
-		if device in self.netdevices.keys():
-		    desc = netdev.desc
-		    if desc is not None and len(desc) > 0:
-			self.netdevices[device].set(("desc", desc))
-
-                    # hwaddr for qeth doesn't make sense (#135023)
-                    if netdev.driver == "qeth":
-                        continue
-                    # add hwaddr
-                    hwaddr = isys.getMacAddress(device)
-                    if hwaddr and hwaddr != "00:00:00:00:00:00" and hwaddr != "ff:ff:ff:ff:ff:ff":
-                        self.netdevices[device].set(("hwaddr", hwaddr))
-
     def getDevice(self, device):
 	return self.netdevices[device]
 
     def getFirstDeviceName(self):
 	return self.firstnetdevice
 
-    def _sysfsDeviceIsUsable(self, dev):
-        if os.path.exists("/sys/class/net/%s/bridge" % dev):
-            return False
-        try:
-            f = open("/sys/class/net/%s/type" % dev)
-            lines = f.readlines()
-            f.close()
-
-            return lines[0].startswith("1")
-        except:
-            return False
-
     def available(self):
+        for device in minihal.get_devices_by_type("net"):
+            if device.has_key('net.arp_proto_hw_id'):
+                if device['net.arp_proto_hw_id'] == 1:
+                    dev = device['device']
+                    self.netdevices[dev] = NetworkDevice(dev);
+                    if self.firstnetdevice is None:
+                        self.firstnetdevice = dev
+                    self.netdevices[dev].set(('hwaddr',device['net.address']))
+                    self.netdevices[dev].set(('desc',device['description']))
+
         ksdevice = None
         if flags.cmdline.has_key("ksdevice"):
             ksdevice = flags.cmdline["ksdevice"]
 
-        f = open("/proc/net/dev")
-        lines = f.readlines()
-        f.close()
-        # skip first two lines, they are header
-        lines = lines[2:]
-        for line in lines:
-            dev = string.strip(line[0:6])
-            if dev != "lo" and dev[0:3] != "sit" and not self.netdevices.has_key(dev) and self._sysfsDeviceIsUsable(dev):
-		if self.firstnetdevice is None:
-		    self.firstnetdevice = dev
-
-                self.netdevices[dev] = NetworkDevice(dev)
-
-                try:
-                    hwaddr = isys.getMacAddress(dev)
-                    if rhpl.getArch() != "s390" and hwaddr and hwaddr != "00:00:00:00:00:00" and hwaddr != "ff:ff:ff:ff:ff:ff":
-                        self.netdevices[dev].set(("hwaddr", hwaddr))
-                except Exception, e:
-                    log.error("exception getting mac addr: %s" %(e,))
-
         if ksdevice and self.netdevices.has_key(ksdevice):
             self.firstnetdevice = ksdevice
 

commit 2f39302d49a550a5d579a30946964cf90d73e942
Author: Bill Nottingham <notting redhat com>
Date:   Thu Dec 6 18:46:41 2007 -0500

    Use HAL to probe for disks. Add a removableDriveDict for use by the exception dialog.

diff --git a/isys/isys.py b/isys/isys.py
index 9c53e0e..ce34413 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -23,7 +23,6 @@ import socket
 import stat
 import posix
 import sys
-import kudzu
 import iutil
 import warnings
 import resource
@@ -31,6 +30,7 @@ import re
 import rhpl
 import struct
 import block
+import minihal
 
 import logging
 log = logging.getLogger("anaconda")
@@ -367,11 +367,6 @@ def swapon (path):
 def loadKeymap(keymap):
     return _isys.loadKeymap (keymap)
 
-classMap = { "disk": kudzu.CLASS_HD,
-             "cdrom": kudzu.CLASS_CDROM,
-             "floppy": kudzu.CLASS_FLOPPY,
-             "tape": kudzu.CLASS_TAPE }
-
 cachedDrives = None
 
 ## Clear the drive dict cache.
@@ -388,32 +383,26 @@ def driveDict(klassArg):
     import parted
     global cachedDrives
     if cachedDrives is None:
-        # FIXME: need to add dasd probing to kudzu
-        devs = kudzu.probe(kudzu.CLASS_HD | kudzu.CLASS_CDROM | \
-                           kudzu.CLASS_FLOPPY | kudzu.CLASS_TAPE,
-                           kudzu.BUS_UNSPEC, kudzu.PROBE_SAFE)
         new = {}
-        for dev in devs:
-            device = dev.device
-            if device is None: # none devices make no sense
-                # kudzu is unable to determine the device for tape drives w/ 2.6
-                if dev.deviceclass == classMap["tape"]:
-                    tapedevs = filter(lambda d: d.startswith("st"), new.keys())
-                    device = "st%d" % (len(tapedevs),)
-                else:
-                    continue
+        for dev in minihal.get_devices_by_type("storage"):
+            if dev['device'] is None: # none devices make no sense
+                continue
 
+            device = dev['device'].replace('/dev/','')
             # we can't actually use the sg devices, so ignore them
             if device.startswith("sg"):
                 log.info("ignoring sg device %s" %(device,))
                 continue
 
-            if dev.deviceclass != classMap["disk"]:
+            # we can't actually use the st devices, so ignore them
+            if device.startswith("st"):
+                log.info("ignoring st device %s" %(device,))
+                continue
+
+            if dev['storage.drive_type'] != 'disk':
                 new[device] = dev
                 continue
             try:
-                devName = "/dev/%s" % (device,)
-
                 if not mediaPresent (device):
                     new[device] = dev
                     continue
@@ -424,12 +413,12 @@ def driveDict(klassArg):
                 if os.path.exists("/dev/live") and \
                        stat.S_ISBLK(os.stat("/dev/live")[stat.ST_MODE]):
                     livetarget = os.path.realpath("/dev/live")
-                    if livetarget.startswith(devName):
+                    if livetarget.startswith(dev['device']):
                         log.info("%s looks to be the live device; ignoring" % (device,))
                         continue
 
                 if device.startswith("sd"):
-                    peddev = parted.PedDevice.get(devName)
+                    peddev = parted.PedDevice.get(dev['device'])
                     model = peddev.model
 
                     # blacklist *STMF on power5 iSeries boxes
@@ -476,8 +465,8 @@ def driveDict(klassArg):
         if isinstance(dev, block.MultiPath) or isinstance(dev, block.RaidSet):
             if klassArg == "disk":
                 ret[key] = dev
-        elif dev.deviceclass == classMap[klassArg]:
-            ret[key] = dev.desc
+        elif dev['storage.drive_type'] == klassArg:
+            ret[key] = dev
     return ret
 
 ## Get all the hard drives attached to the system.
@@ -489,18 +478,27 @@ def driveDict(klassArg):
 # @see driveDict
 # @return A dict of all the hard drive descriptions, keyed on device name.
 def hardDriveDict():
-    return driveDict("disk")
+    ret = {}
+    dict = driveDict("disk")
+    for item in dict.keys():
+        ret[item] = dict[item]['description']
+    return ret
 
-## Get all the floppy drives attached to the system.
-# This method queries the drive dict cache for all floppy drives.  If the cache
+## Get all the removable drives attached to the system.
+# This method queries the drive dict cache for all removable drives.  If the cache
 # is empty, this will cause all disk devices to be probed.  If the status of
 # the devices has changed, flushDriveDict must be run called first.
 #
 # @see flushDriveDict
 # @see driveDict
-# @return A dict of all the floppy drive descriptions, keyed on device name.
-def floppyDriveDict():
-    return driveDict("floppy")
+# @return A dict of all the removable drive descriptions, keyed on device name.
+def removableDriveDict():
+    ret = {}
+    dict = driveDict("disk")
+    for item in dict.keys():
+        if dict[item]['storage.removable'] != 0:
+            ret[item] = dict[item]['description']
+    return ret
 
 ## Get all CD/DVD drives attached to the system.
 # This method queries the drive dict cache for all hard drives.  If the cache


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