def create_persistence(self):
logging.debug('create_persistence')
if self.persist != 0:
dd_cmd = ['dd', 'if=/dev/zero', 'bs=1M', 'of=%s' %
os.path.join(str(self.target), 'casper-rw'),
'count=%d' % self.persist]
if sys.platform == 'win32':
# XXX evand 2009-07-30: Do not read past the end of the device.
# See http://www.chrysocome.net/dd for details.
dd_cmd.append('--size')
if sys.platform != 'win32':
mkfs_cmd = ['mkfs.ext3', '-F', '%s/casper-rw' % str(self.target)]
else:
# FIXME evand 2009-07-23: Need a copy of mke2fs.exe.
mkfs_cmd = []
self.progress_message(_('Creating a persistence file...'))
popen(dd_cmd)
self.check()
self.progress_message(_('Creating an ext2 filesystem in the '
'persistence file...'))
if sys.platform != 'win32':
popen(mkfs_cmd)
self.check()
def sync(self):
logging.debug('sync')
# FIXME evand 2009-07-27: Use FlushFileBuffers on the volume (\\.\e:)
# http://msdn.microsoft.com/en-us/library/aa364439(VS.85).aspx
if sys.platform != 'win32':
self.progress_pulse()
self.progress_message(_('Finishing...'))
# I would try to unmount the device using umount here to get the
# pretty GTK+ message, but umount now returns 1 when you do that.
# We could call udisk's umount method over dbus, but I now think
# that this would look a lot cleaner if done in the usb-creator UI.
import dbus
try:
bus = dbus.SystemBus()
obj = bus.get_object('com.ubuntu.USBCreator',
'/com/ubuntu/USBCreator')
obj.UnmountFile(self.device,
dbus_interface='com.ubuntu.USBCreator',
timeout=MAX_DBUS_TIMEOUT)
except dbus.DBusException:
# TODO: Notify the user.
logging.exception('Unable to unmount:')