summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2011-04-25 20:53:43 -0400
committerLuke Macken <lmacken@redhat.com>2011-04-25 21:03:58 -0400
commita0359a0a1f4656c31c394adfc55978dd9f9ca4ea (patch)
tree240fdd8e4cd7d5533414792a0512edea506acaa5
parentf7f9b27e72c527fc5ea4ea07dce63f080c0c549b (diff)
Port our mounting code to UDisks, and simplify it a bit
-rwxr-xr-xliveusb/creator.py73
-rwxr-xr-xliveusb/gui.py12
2 files changed, 32 insertions, 53 deletions
diff --git a/liveusb/creator.py b/liveusb/creator.py
index bbb1200..0c13c48 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -548,14 +548,13 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
'uuid' : str(dev.GetProperty('volume.uuid')),
'mount' : mount,
'udi' : dev,
- 'unmount' : False,
'free' : mount and self.get_free_bytes(mount) / 1024**2 or None,
'device' : device,
'parent' : parent
}
def mount_device(self):
- """ Mount our device with HAL if it is not already mounted """
+ """ Mount our device if it is not already mounted """
import dbus
if not self.fstype:
raise LiveUSBError(_("Unknown filesystem. Your device "
@@ -568,59 +567,42 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
try:
self.log.debug("Calling %s.Mount('', %s, [], ...)" % (
self.drive['udi'], self.fstype))
- self.drive['udi'].Mount('', self.fstype, [],
- dbus_interface='org.freedesktop.Hal.Device.Volume')
- self.drive['unmount'] = True
+ dev = self._get_device(self.drive['udi'])
+ dev.FilesystemMount('', [],
+ dbus_interface='org.freedesktop.UDisks.Device')
except dbus.exceptions.DBusException, e:
if e.get_dbus_name() == \
'org.freedesktop.Hal.Device.Volume.AlreadyMounted':
self.log.debug('Device already mounted')
+ else:
+ self.log.error('Unknown dbus exception:')
+ self.log.exception(e)
except Exception, e:
raise LiveUSBError(_("Unable to mount device: %s" % str(e)))
- device = self.hal.FindDeviceStringMatch('block.device',
- self.drive['device'])
- device = self._get_device(device[0])
- self.dest = device.GetProperty('volume.mount_point')
- self.log.debug("Mounted %s to %s " % (self.drive['device'],
- self.dest))
- self.drive['mount'] = self.dest
- self.drive['free'] = self.get_free_bytes(self.dest) / 1024**2
+
+ # Get the new mount point
+ udi = self.drive['udi']
+ dev_obj = self.bus.get_object("org.freedesktop.UDisks", udi)
+ dev = dbus.Interface(dev_obj, "org.freedesktop.DBus.Properties")
+ mounts = map(str, list(dev.Get(udi, 'DeviceMountPaths')))
+ if not mounts:
+ self.log.error(_('No mount points found after mounting attempt'))
+ else:
+ self.dest = self.drive['mount'] = mounts[0]
+ self.drive['free'] = self.get_free_bytes(self.dest) / 1024**2
+ self.log.debug("Mounted %s to %s " % (self.drive['device'],
+ self.dest))
else:
self.log.debug("Using existing mount: %s" % self.dest)
- def unmount_device(self, force=False):
+ def unmount_device(self):
""" Unmount our device """
- import dbus
- #try:
- # unmount = self.drive.get('unmount', None)
- #except KeyError, e:
- # self.log.exception(e)
- # return
- if self.dest or force or (self.drive and
- self.drive.get('unmount', False)):
- self.log.debug("Unmounting %s from %s" % (self.drive['device'],
- self.dest))
- try:
- self.drive['udi'].Unmount([],
- dbus_interface='org.freedesktop.Hal.Device.Volume')
- except dbus.exceptions.DBusException, e:
- if e.get_dbus_name() in (
- 'org.freedesktop.Hal.Device.Volume.NotMountedByHal',
- 'org.freedesktop.Hal.Device.Volume.UnknownFailure'):
- self.log.debug('Device not mounted by HAL; trying manually')
- self.popen('umount %s' % self.drive['device'], passive=True)
- else:
- import traceback
- self.log.warning("Unable to unmount device: %s" % str(e))
- self.log.debug(traceback.format_exc())
- return
- self.drive['unmount'] = False
- self.drive['mount'] = None
- if os.path.exists(self.dest):
- self.log.error("Mount %s exists after unmounting" % self.dest)
- self.dest = None
- else:
- self.log.warning("self.dest and unmount not set, skipping unmount")
+ self.log.info("Unmounting %s" % self.dest)
+ self.popen('umount %s' % self.drive['device'], passive=True)
+ self.drive['mount'] = None
+ if os.path.exists(self.dest):
+ self.log.error("Mount %s exists after unmounting" % self.dest)
+ self.dest = None
def verify_filesystem(self):
self.log.info(_("Verifying filesystem..."))
@@ -747,7 +729,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
self.log.debug("Killed process %d" % pid)
except OSError:
pass
- #self.unmount_device()
def verify_iso_md5(self):
""" Verify the ISO md5sum.
diff --git a/liveusb/gui.py b/liveusb/gui.py
index 50daace..ab80b31 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -216,11 +216,9 @@ class LiveUSBThread(QtCore.QThread):
if self.parent.opts.liveos_checksum:
self.live.calculate_liveos_checksum()
- # This sometimes causes segfaults in dbus.
- #self.live.unmount_device()
-
- # Flush all filesystem buffers
+ # Flush all filesystem buffers and unmount
self.live.flush_buffers()
+ self.live.unmount_device()
duration = str(datetime.now() - now).split('.')[0]
self.status(_("Complete! (%s)" % duration))
@@ -459,7 +457,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
return
if self.live.drive['mount']:
self.live.dest = self.live.drive['mount']
- self.live.unmount_device(force=True)
+ self.live.unmount_device()
self.live.reset_mbr()
elif not self.live.mbr_matches_syslinux_bin():
if self.opts.reset_mbr:
@@ -492,7 +490,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
self.status(_("Press 'Create Live USB' again if you wish to "
"continue."))
self.confirmed = True
- self.live.unmount_device()
+ #self.live.unmount_device()
self.enable_widgets(True)
return
else:
@@ -504,7 +502,7 @@ class LiveUSBDialog(QtGui.QDialog, LiveUSBInterface):
self.live.delete_liveos()
except LiveUSBError, e:
self.status(e.args[0])
- self.live.unmount_device()
+ #self.live.unmount_device()
self.enable_widgets(True)
return