Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu User (http://www.linux-archive.org/ubuntu-user/)
-   -   Use HAL to probe for disks. Add a removableDriveDict for use by the exception dialog. (http://www.linux-archive.org/ubuntu-user/13346-use-hal-probe-disks-add-removabledrivedict-use-exception-dialog.html)

Bill Nottingham 12-05-2007 10:24 PM

Use HAL to probe for disks. Add a removableDriveDict for use by the exception dialog.
 
---
isys/isys.py | 68 +++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/isys/isys.py b/isys/isys.py
index 663bc1b..0d04443 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -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,42 @@ 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)
+ import dbus
+
+ bus = dbus.SystemBus()
+
+ halobj = bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager")
+ hal = dbus.Interface(halobj, "org.freedesktop.Hal.Manager")
+
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:
+ for udi in halobj.FindDeviceByCapability("storage"):
+ haldev = dbus.Interface(bus.get_object("org.freedesktop.Hal ", udi), 'org.freedesktop.Hal.Device')
+ try:
+ device = haldev.GetProperty('block.device')
+ device = device.replace('/dev/',')
+ except:
+ try:
+ device = haldev.GetProperty('linux.device_file')
+ device = device.replace('/dev/',')
+ except:
continue

+ dev = {}
+ dev['device'] = device
+ dev['class'] = haldev.GetProperty('storage.drive_type')
+ dev['removable'] = haldev.GetProperty('storage.removable')
+ dev['desc'] = '%s %s' % (haldev.GetProperty('storage.vendor'), haldev.GetProperty('storage.model'))
+
# 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"]:
+ if dev['class'] != "disk":
new[device] = dev
continue
try:
devName = "/dev/%s" % (device,)
- makeDevInode(device, devName)

if not mediaPresent (device):
new[device] = dev
@@ -477,8 +482,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['class'] == klassArg:
+ ret[key] = dev
return ret

## Get all the hard drives attached to the system.
@@ -490,18 +495,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]['desc']
+ 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]['removable'] != 0:
+ ret[item] = dict[item]['desc']
+ 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
--
1.5.3.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


All times are GMT. The time now is 01:29 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.