summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2009-03-13 13:34:13 -0400
committerChris Lumens <clumens@redhat.com>2009-03-13 14:26:57 -0400
commit12c4fb21429e61fc0dedbd8e3fd2a2f0d3e3eeac (patch)
tree49266004e7465b89547982458ed990675cb95cba
parent4f7ad077b523a0dbb1ace6339720f875dec6574f (diff)
downloadanaconda-12c4fb21429e61fc0dedbd8e3fd2a2f0d3e3eeac.tar.gz
anaconda-12c4fb21429e61fc0dedbd8e3fd2a2f0d3e3eeac.tar.xz
anaconda-12c4fb21429e61fc0dedbd8e3fd2a2f0d3e3eeac.zip
Add mediaPresent and eject to the OpticalDevice class.
These no longer belong in isys.py as putting them in the classes is much more correct. I also put a mediaPresent method on Device in general. This will come in handy when we start dealing with USB CF readers and similar devices that can be present without having media.
-rwxr-xr-xanaconda2
-rw-r--r--booty/bootloaderInfo.py2
-rw-r--r--installmethod.py6
-rwxr-xr-xisys/isys.py33
-rw-r--r--kickstart.py2
-rw-r--r--storage/devices.py30
-rw-r--r--yuminstall.py3
7 files changed, 38 insertions, 40 deletions
diff --git a/anaconda b/anaconda
index dc50999f6..a4ed591e0 100755
--- a/anaconda
+++ b/anaconda
@@ -1026,7 +1026,7 @@ if __name__ == "__main__":
continue
log.info("attempting to eject %s" % drive.path)
- isys.ejectCdrom(drive.path)
+ drive.eject()
del anaconda.intf
diff --git a/booty/bootloaderInfo.py b/booty/bootloaderInfo.py
index 2fdf16ab7..d1147348c 100644
--- a/booty/bootloaderInfo.py
+++ b/booty/bootloaderInfo.py
@@ -453,7 +453,7 @@ class bootloaderInfo:
f.write("\n")
def updateDriveList(self, sortedList=[]):
- self._drivelist = map(lambda x: x.name, filter(lambda x: isys.mediaPresent(x.name), self.storage.disks))
+ self._drivelist = map(lambda x: x.name, filter(lambda dev: dev.mediaPresent, self.storage.disks))
self._drivelist.sort(isys.compareDrives)
# If we're given a sort order, make sure the drives listed in it
diff --git a/installmethod.py b/installmethod.py
index f2c3d7191..c412c944a 100644
--- a/installmethod.py
+++ b/installmethod.py
@@ -34,17 +34,17 @@ def doMethodComplete(anaconda):
return None
if anaconda.mediaDevice:
- return anaconda.mediaDevice
+ return anaconda.id.storage.devicetree.getDeviceByName(anaconda.mediaDevice)
# If we booted off the boot.iso instead of disc 1, eject that as well.
if anaconda.stage2 and anaconda.stage2.startswith("cdrom://"):
dev = anaconda.stage2[8:].split(':')[0]
- return dev
+ return anaconda.id.storage.devicetree.getDeviceByName(dev)
anaconda.backend.complete(anaconda)
dev = _ejectDevice()
if dev:
- isys.ejectCdrom(dev)
+ dev.eject()
mtab = "/dev/root / ext3 ro 0 0\n"
rootDevice = anaconda.id.storage.fsset.rootDevice
diff --git a/isys/isys.py b/isys/isys.py
index fb2fa5d57..07c69a0a1 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -437,22 +437,6 @@ def ext2HasJournal(device):
hasjournal = _isys.e2hasjournal(device);
return hasjournal
-def ejectCdrom(device):
- # XXX this should go into storage.devices.OpticalDevice
- if not os.path.exists(device):
- device = "/dev/%s" % device
-
- fd = os.open(device, os.O_RDONLY|os.O_NONBLOCK)
-
- # this is a best effort
- try:
- _isys.ejectcdrom(fd)
- except SystemError, e:
- log.warning("error ejecting cdrom (%s): %s" %(device, e))
- pass
-
- os.close(fd)
-
def driveUsesModule(device, modules):
"""Returns true if a drive is using a prticular module. Only works
for SCSI devices right now."""
@@ -481,23 +465,6 @@ def driveUsesModule(device, modules):
pass
return rc
-## Check if a removable media drive (CD, USB key, etc.) has media present.
-# @param device The basename of the device node.
-# @return True if media is present in device, False otherwise.
-def mediaPresent(device):
- # XXX this should go into storage.devices.RemovableDevice or similar
- try:
- fd = os.open("/dev/%s" % device, os.O_RDONLY)
- except OSError, (errno, strerror):
- # error 123 = No medium found
- if errno == 123:
- return False
- else:
- return True
- else:
- os.close(fd)
- return True
-
def driveIsIscsi(device):
# ewww. just ewww.
if not os.path.islink("/sys/block/%s/device" %(device,)):
diff --git a/kickstart.py b/kickstart.py
index 1000f8e0b..f24d6178a 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -238,7 +238,7 @@ class ClearPart(commands.clearpart.FC3_ClearPart):
if self.type is None:
self.type = CLEARPART_TYPE_NONE
- hds = map(lambda x: x.name, filter(lambda x: isys.mediaPresent(x.name), self.handler.id.storage.disks))
+ hds = map(lambda x: x.name, filter(lambda dev: dev.mediaPresent, self.handler.id.storage.disks))
for disk in self.drives:
if disk not in hds:
raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified nonexistent disk %s in clearpart command" % disk)
diff --git a/storage/devices.py b/storage/devices.py
index 39578c01b..283eb055c 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -381,6 +381,10 @@ class Device(object):
return packages
+ @property
+ def mediaPresent(self):
+ return True
+
class NetworkDevice(Device):
""" A network device """
@@ -2500,6 +2504,7 @@ class OpticalDevice(StorageDevice):
major=major, minor=minor, exists=True,
parents=parents, sysfsPath=sysfsPath)
+ @property
def mediaPresent(self):
""" Return a boolean indicating whether or not the device contains
media.
@@ -2508,12 +2513,37 @@ class OpticalDevice(StorageDevice):
if not self.exists:
raise DeviceError("device has not been created")
+ try:
+ fd = os.open(self.path, os.O_RDONLY)
+ except OSError as e:
+ # errno 123 = No medium found
+ if e.errno == 123:
+ return False
+ else:
+ return True
+ else:
+ os.close(fd)
+ return True
+
def eject(self):
""" Eject the drawer. """
+ import _isys
+
log_method_call(self, self.name, status=self.status)
if not self.exists:
raise DeviceError("device has not been created")
+ # Make a best effort attempt to do the eject. If it fails, it's not
+ # critical.
+ fd = os.open(self.path, os.O_RDONLY | os.O_NONBLOCK)
+
+ try:
+ _isys.ejectcdrom(fd)
+ except SystemError as e:
+ log.warning("error ejecting cdrom %s: %s" % (device, e))
+
+ os.close(fd)
+
class ZFCPDiskDevice(DiskDevice):
""" A mainframe ZFCP disk. """
diff --git a/yuminstall.py b/yuminstall.py
index af6963de0..dc541b571 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -342,7 +342,8 @@ class AnacondaYum(YumSorter):
unmountCD(self.tree, self.anaconda.intf.messageWindow)
self.currentMedia = None
- isys.ejectCdrom(self.anaconda.mediaDevice)
+ dev = self.anaconda.id.storage.devicetree.getDeviceByName(self.anaconda.mediaDevice)
+ dev.eject()
while True:
if self.anaconda.intf: