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. --- anaconda | 2 +- booty/bootloaderInfo.py | 2 +- installmethod.py | 6 +++--- isys/isys.py | 33 --------------------------------- kickstart.py | 2 +- storage/devices.py | 30 ++++++++++++++++++++++++++++++ yuminstall.py | 3 ++- 7 files changed, 38 insertions(+), 40 deletions(-) diff --git a/anaconda b/anaconda index dc50999..a4ed591 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 2fdf16a..d114734 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 f2c3d71..c412c94 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 fb2fa5d..07c69a0 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 1000f8e..f24d617 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 13d85b8..61aa1b9 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -361,6 +361,10 @@ class Device(object): return packages + @property + def mediaPresent(self): + return True + class NetworkDevice(Device): """ A network device """ @@ -2479,6 +2483,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. @@ -2487,12 +2492,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 af6963d..dc541b5 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: -- 1.6.1.3 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list