[Pkg-privacy-commits] [tails-installer] 01/27: Remove the copy option
Intrigeri
intrigeri at moszumanska.debian.org
Wed May 24 15:26:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to tag 3.91.0
in repository tails-installer.
commit 5fa95231e995d236226f061969577b8f0858b67d
Author: Martin Briza <mbriza at redhat.com>
Date: Mon Jan 25 16:31:23 2016 +0100
Remove the copy option
Still works alright in Linux
Probably broken in Windows, will test
---
liveusb/creator.py | 582 +----------------------------------------------------
liveusb/gui.py | 107 ++--------
2 files changed, 16 insertions(+), 673 deletions(-)
diff --git a/liveusb/creator.py b/liveusb/creator.py
index cc30ec7..3b6eaac 100755
--- a/liveusb/creator.py
+++ b/liveusb/creator.py
@@ -97,73 +97,10 @@ class LiveUSBCreator(object):
""" This method should populate self.drives with removable devices """
raise NotImplementedError
- def verify_filesystem(self):
- """
- Verify the filesystem of our device, setting the volume label
- if necessary. If something is not right, this method throws a
- LiveUSBError.
- """
- raise NotImplementedError
-
- def get_free_bytes(self, drive=None):
- """ Return the number of free bytes on a given drive.
-
- If drive is None, then use the currently selected device.
- """
- raise NotImplementedError
-
- def extract_iso(self):
- """ Extract the LiveCD ISO to the USB drive """
- raise NotImplementedError
-
def verify_iso_md5(self):
""" Verify the MD5 checksum of the ISO """
raise NotImplementedError
- def install_bootloader(self):
- """ Install the bootloader to our device.
-
- Platform-specific classes inheriting from the LiveUSBCreator are
- expected to implement this method to install the bootloader to the
- specified device using syslinux. This specific implemention is
- platform independent and performs sanity checking along with adding
- OLPC support.
- """
- if not os.path.exists(os.path.join(self.dest, 'isolinux')):
- raise LiveUSBError('extract_iso must be run before '
- 'install_bootloader')
- if self.opts.xo:
- self.setup_olpc()
-
- def setup_olpc(self):
- """ Install the Open Firmware configuration for the OLPC.
-
- This method will make the selected device bootable on the OLPC. It
- does this by installing a /boot/olpc.fth open firmware configuration
- file that enables booting off of USB and SD cards on the XO.
- """
- from liveusb.olpc import ofw_config
- self.log.info(_('Setting up OLPC boot file...'))
- args = self.get_kernel_args()
- if not os.path.exists(os.path.join(self.dest, 'boot')):
- os.mkdir(os.path.join(self.dest, 'boot'))
- olpc_cfg = file(os.path.join(self.dest, 'boot', 'olpc.fth'), 'w')
- olpc_cfg.write(ofw_config % ' '.join(args))
- olpc_cfg.close()
- self.log.debug('Wrote %s' % olpc_cfg.name)
-
- def get_kernel_args(self):
- """ Grab the kernel arguments from our syslinux configuration """
- args = []
- cfg = file(os.path.join(self.dest, 'isolinux', 'syslinux.cfg'))
- for line in cfg.readlines():
- if 'append' in line:
- args.extend([arg for arg in line.split()[1:]
- if not arg.startswith('initrd')])
- break
- cfg.close()
- return args
-
def terminate(self):
""" Terminate any subprocesses that we have spawned """
raise NotImplementedError
@@ -249,118 +186,6 @@ class LiveUSBCreator(object):
else:
self.log.debug(_('Unknown ISO, skipping checksum verification'))
- def check_free_space(self):
- """ Make sure there is enough space for the LiveOS and overlay """
- freebytes = self.get_free_bytes()
- self.log.debug('freebytes = %d' % freebytes)
- self.log.debug('isosize = %d' % self.isosize)
- overlaysize = self.overlay * 1024**2
- self.log.debug('overlaysize = %d' % overlaysize)
- self.totalsize = overlaysize + self.isosize
- if self.totalsize > freebytes:
- raise LiveUSBError(_("There is not enough free space on the selected device.\nRequired: %s. Free: %s." %
- (str(self.isosize/1024**2 + self.overlay) + "MB",
- str(freebytes/1024**2) + "MB")))
-
- def create_persistent_overlay(self):
- if self.overlay:
- self.log.info(_("Creating") + " %sMB " % self.overlay +
- _("persistent overlay"))
- if self.fstype == 'vfat':
- # vfat apparently can't handle sparse files
- self.popen('dd if=/dev/zero of="%s" count=%d bs=1M'
- % (self.get_overlay(), self.overlay))
- else:
- self.popen('dd if=/dev/zero of="%s" count=1 bs=1M seek=%d'
- % (self.get_overlay(), self.overlay))
-
- def _update_configs(self, infile, outfile):
- infile = file(infile, 'r')
- outfile= file(outfile, 'w')
- usblabel = 'LABEL=' + self.label
- for line in infile.readlines():
- if "LABEL" in line:
- line = re.sub("LABEL=[^ :]*", usblabel, line)
- line = re.sub("rootfstype=[^ ]*",
- "rootfstype=%s" % self.fstype,
- line)
- if "isolinux" in line:
- line = re.sub("isolinux", "syslinux", line)
- if "liveimg" in line:
- if self.overlay:
- line = line.replace("liveimg", "liveimg overlay=" + usblabel)
- line = line.replace(" ro ", " rw ")
- if self.opts.kernel_args:
- line = line.replace("liveimg", "liveimg %s" %
- ' '.join(self.opts.kernel_args.split(',')))
- elif "rd.live.image" in line:
- if self.overlay:
- line = line.replace("rd.live.image", "rd.live.image " +
- "rd.live.overlay=" + usblabel)
- line = line.replace(" ro ", " rw ")
- if self.opts.kernel_args:
- line = line.replace("rd.live.image", "rd.live.image %s" %
- ' '.join(self.opts.kernel_args.split(',')))
- outfile.write(line)
- infile.close()
- outfile.close()
-
- def update_configs(self):
- """ Generate our syslinux.cfg and grub.conf files """
- grubconf = os.path.join(self.dest, "EFI", "BOOT", "grub.cfg")
- bootconf = os.path.join(self.dest, "EFI", "BOOT", "boot.conf")
- bootx64conf = os.path.join(self.dest, "EFI", "BOOT", "bootx64.conf")
- bootia32conf = os.path.join(self.dest, "EFI", "BOOT", "bootia32.conf")
- updates = [(os.path.join(self.dest, "isolinux", "isolinux.cfg"),
- os.path.join(self.dest, "isolinux", "syslinux.cfg")),
- (grubconf, bootconf)]
- copies = [(bootconf, grubconf),
- (bootconf, bootx64conf),
- (bootconf, bootia32conf)]
-
- for (infile, outfile) in updates:
- if os.path.exists(infile):
- self._update_configs(infile, outfile)
- # only copy/overwrite files we had originally started with
- for (infile, outfile) in copies:
- if os.path.exists(outfile):
- try:
- shutil.copyfile(infile, outfile)
- except Exception, e:
- self.log.warning(_("Unable to copy %r to %r: %r") % (infile, outfile, e))
-
- def delete_ldlinux(self):
- # Don't prompt about overwriting files from mtools (#491234)
- for ldlinux in [os.path.join(self.dest, p, 'ldlinux.sys')
- for p in ('syslinux', '')]:
- self.log.debug('Looking for %s' % ldlinux)
- if os.path.isfile(ldlinux):
- self.log.debug(_("Removing") + " %s" % ldlinux)
- self.popen('chattr -i "%s"' % ldlinux, passive=True)
- os.unlink(ldlinux)
-
- def delete_liveos(self):
- """ Delete the existing LiveOS """
- self.log.info(_('Removing existing Live OS'))
- self.delete_ldlinux()
- for path in [self.get_liveos(),
- os.path.join(self.dest + os.path.sep, 'syslinux'),
- os.path.join(self.dest + os.path.sep, 'isolinux')]:
- if os.path.exists(path):
- self.log.debug(_("Deleting ") + path)
- # Python for Windows is unable to delete read-only files,
- if os.path.isdir(path):
- for f in os.listdir(path):
- try:
- os.chmod(os.path.join(path, f), 0777)
- except OSError, e:
- self.log.debug(_("Unable to delete %r: %r") % (f, e))
- try:
- shutil.rmtree(path)
- except OSError, e:
- raise LiveUSBError(_("Unable to remove previous LiveOS: "
- "%r" % e))
-
def write_log(self):
""" Write out our subprocess stdout/stderr to a log file """
tmpdir = os.getenv('TEMP', '/tmp')
@@ -417,10 +242,6 @@ class LiveUSBCreator(object):
""" Return a dictionary of proxy settings """
return None
- def bootable_partition(self):
- """ Ensure that the selected partition is flagged as bootable """
- pass
-
def set_iso(self, iso):
""" Select the given ISO """
self.iso = os.path.abspath(self._to_unicode(iso))
@@ -434,22 +255,6 @@ class LiveUSBCreator(object):
obj = unicode(obj, encoding, 'replace')
return obj
- def get_mbr(self):
- pass
-
- def blank_mbr(self):
- pass
-
- def mbr_matches_syslinux_bin(self):
- """
- Return whether or not the MBR on the drive matches the system's
- syslinux mbr.bin
- """
- return True
-
- def reset_mbr(self):
- pass
-
def flush_buffers(self):
""" Flush filesystem buffers """
pass
@@ -510,13 +315,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
def __init__(self, *args, **kw):
super(LinuxLiveUSBCreator, self).__init__(*args, **kw)
- extlinux = self.get_extlinux_version()
- if extlinux is None:
- self.valid_fstypes -= self.ext_fstypes
- elif extlinux < 4:
- self.log.debug(_('You are using an old version of syslinux-extlinux '
- 'that does not support the ext4 filesystem'))
- self.valid_fstypes -= set(['ext4'])
def strify(self, s):
return bytearray(s).replace(b'\x00', b'').decode('utf-8')
@@ -666,8 +464,7 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
else:
mount = data['mount'] = None
- data['free'] = mount and \
- self.get_free_bytes(mount) / 1024**2 or None
+ data['free'] = data['size']
parent_obj = self.bus.get_object("org.freedesktop.UDisks2", partition[u'Table'])
@@ -734,59 +531,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
'parent' : parent
}
- def mount_device(self):
- """ Mount our device if it is not already mounted """
- import dbus
- if not self.fstype:
- raise LiveUSBError(_("Unknown filesystem. Your device "
- "may need to be reformatted."))
- if self.fstype not in self.valid_fstypes:
- raise LiveUSBError(_("Unsupported filesystem: %s") %
- self.fstype)
- self.dest = self.drive['mount']
- mnt = None
- if not self.dest:
- dev=None
- bd=None
- try:
- dev = self._get_device_fs(self.drive['udi'])
- bd = self.bus.get_object('org.freedesktop.UDisks2',
- '/org/freedesktop/UDisks2/block_devices%s' %
- self.drive['device'][4:])
- except dbus.exceptions.DBusException, e:
- self.log.error(_('Unknown dbus exception while trying to '
- 'mount device: %s') % str(e))
-
- if dev and bd:
- try:
- mntpnts = dbus.Interface(bd, 'org.freedesktop.DBus.Properties').Get('org.freedesktop.UDisks2.Filesystem', 'MountPoints')
- if len(mntpnts) > 0:
- self.log.debug("%s is already mounted at %s" % (self.drive['device'], self.strify(mntpnts[0])))
- mnt = self.strify(mntpnts[0])
- except dbus.exceptions.DBusException, e:
- pass
-
- if dev and bd and not mnt:
- try:
- self.log.debug("Mounting %s" % self.drive['device'])
- mnt = str(bd.Mount({}, dbus_interface='org.freedesktop.UDisks2.Filesystem'))
- except dbus.exceptions.DBusException, e:
- self.log.error(_('Unknown dbus exception while trying to '
- 'mount device: %s') % str(e))
- except Exception, e:
- raise LiveUSBError(_("Unable to mount device: %r" % e))
-
- if mnt and not os.path.exists(mnt):
- self.log.error(_('No mount points found after mounting attempt'))
- self.log.error("%s doesn't exist" % mnt)
- else:
- self.dest = self.drive['mount'] = mnt
- 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):
""" Unmount our device """
self.log.info("Unmounting %s" % self.dest)
@@ -796,133 +540,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
self.log.error("Mount %s exists after unmounting" % self.dest)
self.dest = None
- def verify_filesystem(self):
- self.log.info(_("Verifying filesystem..."))
- if self.fstype not in self.valid_fstypes:
- if not self.fstype:
- raise LiveUSBError(_("Unknown filesystem. Your device "
- "may need to be reformatted."))
- else:
- raise LiveUSBError(_("Unsupported filesystem: %s" %
- self.fstype))
- if self.drive['label'] != self.label:
- self.log.info(_("Setting %s label to %s") % (self.drive['device'],
- self.label))
- try:
- if self.fstype in ('vfat', 'msdos'):
- try:
- self.popen('/sbin/dosfslabel %s %s' % (
- self.drive['device'], self.label))
- except LiveUSBError:
- # dosfslabel returns an error code even upon success
- pass
- else:
- self.popen('/sbin/e2label %s %s' % (self.drive['device'],
- self.label))
- except LiveUSBError, e:
- self.log.error(_("Unable to change volume label: %r") % e)
-
- def extract_iso(self):
- """ Extract self.iso to self.dest """
- self.log.info(_("Extracting live image to USB device..."))
- tmpdir = tempfile.mkdtemp()
- self.popen('mount -o loop,ro "%s" %s' % (self.iso, tmpdir))
- tmpliveos = os.path.join(tmpdir, 'LiveOS')
- try:
- if not os.path.isdir(tmpliveos):
- raise LiveUSBError(_("Unable to find LiveOS on ISO"))
- liveos = os.path.join(self.dest, 'LiveOS')
- if not os.path.exists(liveos):
- os.mkdir(liveos)
-
- start = datetime.now()
- self.popen("cp %s '%s'" % (os.path.join(tmpliveos, 'squashfs.img'),
- os.path.join(liveos, 'squashfs.img')))
- delta = datetime.now() - start
- if delta.seconds:
- self.mb_per_sec = (self.isosize / delta.seconds) / 1024**2
- if self.mb_per_sec:
- self.log.info(_("Wrote to device at") + " %d MB/sec" %
- self.mb_per_sec)
-
- osmin = os.path.join(tmpliveos, 'osmin.img')
- if os.path.exists(osmin):
- self.popen("cp %s '%s'" % (osmin,
- os.path.join(liveos, 'osmin.img')))
- else:
- self.log.debug('No osmin.img found')
-
- isolinux = os.path.join(self.dest, 'isolinux')
- if not os.path.exists(isolinux):
- os.mkdir(isolinux)
- self.popen("cp %s/* '%s'" % (
- os.path.join(tmpdir, 'isolinux'), isolinux))
-
- if os.path.exists(os.path.join(tmpdir, 'EFI')):
- efi = os.path.join(self.dest, 'EFI')
- if not os.path.exists(efi):
- os.mkdir(efi)
- self.popen("cp -r %s/* '%s'" % (os.path.join(tmpdir, 'EFI'),
- efi))
- finally:
- self.popen('umount %s' % tmpdir)
-
- def install_bootloader(self):
- """ Run syslinux to install the bootloader on our devices """
- LiveUSBCreator.install_bootloader(self)
- self.log.info(_("Installing bootloader..."))
- syslinux_path = os.path.join(self.dest, "syslinux")
- try:
- shutil.rmtree(syslinux_path)
- except OSError, e:
- pass
- shutil.move(os.path.join(self.dest, "isolinux"), syslinux_path)
- try:
- os.unlink(os.path.join(syslinux_path, "isolinux.cfg"))
- except OSError, e:
- pass
-
- # Syslinux doesn't guarantee the API for its com32 modules (#492370)
- for com32mod in ('vesamenu.c32', 'menu.c32'):
- copied = False
- for path in ('/usr/share', '/usr/lib'):
- com32path = os.path.join(path, 'syslinux', com32mod)
- if os.path.isfile(com32path):
- self.log.debug('Copying %s on to stick' % com32path)
- shutil.copyfile(com32path, os.path.join(syslinux_path, com32mod))
- copied = True
- break
- if copied:
- break
-
- self.delete_ldlinux()
-
- if self.drive['fstype'] in self.ext_fstypes:
- shutil.move(os.path.join(syslinux_path, "syslinux.cfg"),
- os.path.join(syslinux_path, "extlinux.conf"))
- self.popen("extlinux -i '%s'" % syslinux_path)
- else: # FAT
- self.popen('syslinux%s -f -d %s %s' % (self.opts.safe and ' -s' or '',
- 'syslinux', self.drive['device']))
-
- def get_free_bytes(self, device=None):
- """ Return the number of available bytes on our device """
- import statvfs
- device = device and device or self.dest
- if not device:
- return 0
- device = device.encode('utf-8')
- if not os.path.exists(device):
- raise LiveUSBError(_('Cannot find device: %s') % device)
- stat = os.statvfs(device)
- return stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
-
- def _get_device_fs(self, udi):
- """ Return a dbus Interface to a specific UDisks device UDI """
- import dbus
- dev_obj = self.bus.get_object("org.freedesktop.UDisks2", udi)
- return dbus.Interface(dev_obj, "org.freedesktop.UDisks2.Filesystem")
-
def terminate(self):
for pid in self.pids:
try:
@@ -975,61 +592,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
proxies['ftp'] = ftpProxy
return proxies
- def bootable_partition(self):
- """ Ensure that the selected partition is flagged as bootable """
- if self.drive.get('parent') is None:
- self.log.debug('No partitions on device; not attempting to mark '
- 'any paritions as bootable')
- return
- import parted
- try:
- disk, partition = self.get_disk_partition()
- except LiveUSBError:
- self.log.exception(_('Unable to get disk partitions'))
- return
- if partition.isFlagAvailable(parted.PARTITION_BOOT):
- if partition.getFlag(parted.PARTITION_BOOT):
- self.log.debug(_('%s already bootable') % self.drive['device'])
- else:
- partition.setFlag(parted.PARTITION_BOOT)
- try:
- disk.commit()
- self.log.info('Marked %s as bootable' % self.drive['device'])
- except Exception, e:
- self.log.exception(e)
- else:
- self.log.warning('%s does not have boot flag' % self.drive['device'])
-
- def get_disk_partition(self):
- """ Return the PedDisk and partition of the selected device """
- import parted
- parent = self.drives[self._drive]['parent']
- dev = parted.Device(path = parent)
- disk = parted.Disk(device = dev)
- for part in disk.partitions:
- if self.drive['device'] == "/dev/%s" %(part.getDeviceNodeName(),):
- return disk, part
- raise LiveUSBError(_("Unable to find partition"))
-
- def initialize_zip_geometry(self):
- """ This method initializes the selected device in a zip-like fashion.
-
- :Note: This feature is currently experimental, and will DESTROY ALL DATA
- on your device!
-
- More details on this can be found here:
- http://syslinux.zytor.com/doc/usbkey.txt
- """
- #from parted import PedDevice
- self.log.info('Initializing %s in a zip-like fashon' % self.drive['device'])
- heads = 64
- cylinders = 32
- # Is this part even necessary?
- #device = PedDevice.get(self._drive[:-1])
- #cylinders = int(device.cylinders / (64 * 32))
- self.popen('/usr/lib/syslinux/mkdiskimage -4 %s 0 %d %d' % (
- self.drive['device'][:-1], heads, cylinders))
-
def format_device(self):
""" Format the selected partition as FAT32 """
self.log.info('Formatting %s as FAT32' % self.drive['device'])
@@ -1050,42 +612,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
self.log.debug('mbr = %r' % mbr)
return mbr
- def blank_mbr(self):
- """ Return whether the MBR is empty or not """
- return self.get_mbr() == '0000'
-
- def _get_mbr_bin(self):
- mbr = None
- for mbr_bin in ('/usr/lib/syslinux/mbr.bin',
- '/usr/share/syslinux/mbr.bin',
- '/usr/lib/syslinux/bios/mbr.bin',
- '/usr/lib/syslinux/mbr/mbr.bin'):
- if os.path.exists(mbr_bin):
- mbr = mbr_bin
- return mbr
-
- def mbr_matches_syslinux_bin(self):
- """
- Return whether or not the MBR on the drive matches the system's
- syslinux mbr.bin
- """
- mbr_bin = open(self._get_mbr_bin(), 'rb')
- mbr = ''.join(['%02X' % ord(x) for x in mbr_bin.read(2)])
- return mbr == self.get_mbr()
-
- def reset_mbr(self):
- parent = unicode(self.drive.get('parent', self.drive['device']))
- if '/dev/loop' not in self.drive:
- mbr = self._get_mbr_bin()
- if mbr:
- self.log.info(_('Resetting Master Boot Record') + ' of %s' % parent)
- self.popen('cat %s > %s' % (mbr, parent))
- else:
- self.log.info(_('Unable to reset MBR. You may not have the '
- '`syslinux` package installed'))
- else:
- self.log.info(_('Drive is a loopback, skipping MBR reset'))
-
def calculate_device_checksum(self, progress=None):
""" Calculate the SHA1 checksum of the device """
self.log.info(_("Calculating the SHA1 of %s" % self.drive['device']))
@@ -1117,23 +643,6 @@ class LinuxLiveUSBCreator(LiveUSBCreator):
def is_admin(self):
return os.getuid() == 0
- def get_extlinux_version(self):
- """ Return the version of extlinux. None if it isn't installed """
- import subprocess
- version = None
- p = subprocess.Popen('extlinux -v', shell=True,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- if p.returncode == 0:
- version = int(err.split()[1].split('.')[0])
- elif p.returncode == 127:
- self.log.warning('extlinux not found! Only FAT filesystems will be supported')
- else:
- self.log.debug('Unknown return code from extlinux: %s' % p.returncode)
- self.log.debug('stdout: %r\nstderr: %r' % (out, err))
- return version
-
-
class MacOsLiveUSBCreator(LiveUSBCreator):
@@ -1149,17 +658,6 @@ class MacOsLiveUSBCreator(LiveUSBCreator):
"""
pass
- def get_free_bytes(self, drive=None):
- """ Return the number of free bytes on a given drive.
-
- If drive is None, then use the currently selected device.
- """
- pass
-
- def extract_iso(self):
- """ Extract the LiveCD ISO to the USB drive """
- pass
-
def verify_iso_md5(self):
""" Verify the MD5 checksum of the ISO """
pass
@@ -1168,31 +666,10 @@ class MacOsLiveUSBCreator(LiveUSBCreator):
""" Terminate any subprocesses that we have spawned """
pass
- def mount_device(self):
- """ Mount self.drive, setting the mount point to self.mount """
- pass
-
- def unmount_device(self):
- """ Unmount the device mounted at self.mount """
- pass
-
def get_proxies(self):
""" Return a dictionary of proxy settings """
pass
- def bootable_partition(self):
- """ Ensure that the selected partition is flagged as bootable """
- pass
-
- def get_mbr(self):
- pass
-
- def blank_mbr(self):
- pass
-
- def reset_mbr(self):
- pass
-
def flush_buffers(self):
""" Flush filesystem buffers """
pass
@@ -1288,57 +765,6 @@ class WindowsLiveUSBCreator(LiveUSBCreator):
except pywintypes.error, e:
self.log.warning(_("Unable to SetVolumeLabel: %r") % e)
- def get_free_bytes(self, device=None):
- """ Return the number of free bytes on our selected drive """
- import win32file
- device = device and device or self.drive['device']
- try:
- (spc, bps, fc, tc) = win32file.GetDiskFreeSpace(device)
- except Exception, e:
- self.log.error(_("Problem determining free space: %r") % e)
- return 0
- return fc * (spc * bps) # free-clusters * bytes per-cluster
-
- def extract_iso(self):
- """ Extract our ISO with 7-zip directly to the USB key """
- self.log.info(_("Extracting live image to USB device..."))
- start = datetime.now()
- self.popen('7z x "%s" -x![BOOT] -y -o%s' % (self.iso, self.drive['device']))
- delta = datetime.now() - start
- if delta.seconds:
- self.mb_per_sec = (self.isosize / delta.seconds) / 1024**2
- if self.mb_per_sec:
- self.log.info(_("Wrote to device at") + " %d MB/sec" %
- self.mb_per_sec)
-
- def install_bootloader(self):
- """ Run syslinux to install the bootloader on our device """
- LiveUSBCreator.install_bootloader(self)
- self.log.info(_("Installing bootloader"))
- device = self.drive['device']
- syslinuxdir = os.path.join(device + os.path.sep, "syslinux")
- if os.path.isdir(syslinuxdir):
- # Python for Windows is unable to delete read-only files, and some
- # may exist here if the LiveUSB stick was created in Linux
- for f in os.listdir(syslinuxdir):
- os.chmod(os.path.join(syslinuxdir, f), 0777)
- shutil.rmtree(syslinuxdir)
- shutil.move(os.path.join(device + os.path.sep, "isolinux"), syslinuxdir)
- os.unlink(os.path.join(syslinuxdir, "isolinux.cfg"))
-
- # Don't prompt about overwriting files from mtools (#491234)
- for ldlinux in [os.path.join(device + os.path.sep, p, 'ldlinux.sys')
- for p in (syslinuxdir, '')]:
- if os.path.isfile(ldlinux):
- os.chmod(ldlinux, 0777)
- self.log.debug(_("Removing") + " %s" % ldlinux)
- os.unlink(ldlinux)
-
- self.popen('syslinux%s -f -m -a -d %s %s' % (self.opts.safe and ' -s' or '', 'syslinux', device))
-
- # Cache these, because they are fairly expensive
- _win32_logicaldisk = {}
-
def _get_win32_logicaldisk(self, drive):
""" Return the Win32_LogicalDisk object for the given drive """
import win32com.client
@@ -1427,12 +853,6 @@ class WindowsLiveUSBCreator(LiveUSBCreator):
except pywintypes.error:
pass
- def mount_device(self):
- self.dest = self.drive['mount']
-
- def unmount_device(self):
- pass
-
def get_proxies(self):
proxies = {}
try:
diff --git a/liveusb/gui.py b/liveusb/gui.py
index 4b58589..3013bb0 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -205,12 +205,18 @@ class ReleaseWriterProgressThread(QThread):
self.totalSize = size / 1024
self.drive = drive
self.get_free_bytes = freebytes
- self.orig_free = self.get_free_bytes()
+ if self.get_free_bytes:
+ self.orig_free = self.get_free_bytes()
+ else:
+ self.orig_free = 0
self.parent().maxProgress = self.totalSize
def run(self):
while self.alive:
- free = self.get_free_bytes()
+ if self.get_free_bytes:
+ free = self.get_free_bytes()
+ else:
+ free = 0
value = (self.orig_free - free) / 1024
self.parent().progress = value
if (value >= self.totalSize):
@@ -242,16 +248,14 @@ class ReleaseWriterThread(QThread):
#self.live.log.addHandler(handler)
now = datetime.now()
try:
- self.live.verify_filesystem()
if not self.live.drive['uuid'] and not self.live.label:
self.parent.release.addError(_('Error: Cannot set the label or obtain '
'the UUID of your device. Unable to continue.'))
self.parent.running = False
return
- if self.parent.release.liveUSBData.option('dd'):
- self.ddImage(now)
- else:
- self.copyImage(now)
+
+ self.ddImage(now)
+
except Exception, e:
self.parent.release.addError(e.args[0])
self.live.log.exception(e)
@@ -269,62 +273,6 @@ class ReleaseWriterThread(QThread):
self.progressThread.stop()
return
- def copyImage(self, now):
- # TODO move this to the backend
-
- self.parent.status = _('Checking the source image')
- self.live.check_free_space()
-
- if not self.live.opts.noverify:
- # Verify the MD5 checksum inside of the ISO image
- if not self.live.verify_iso_md5():
- #self.live.log.removeHandler(handler)
- return
-
- # If we know about this ISO, and it's SHA1 -- verify it
- release = self.live.get_release_from_iso()
- if release and ('sha1' in release or 'sha256' in release):
- if not self.live.verify_iso_sha1(self):
- #self.live.log.removeHandler(handler)
- return
-
- self.parent.status = _('Unpacking the image')
- # Setup the progress bar
- self.progressThread.set_data(size=self.live.totalsize,
- drive=self.live.drive['device'],
- freebytes=self.live.get_free_bytes)
- self.progressThread.start()
-
- self.live.extract_iso()
-
- if self.live.blank_mbr() or self.parent.release.liveUSBData.option('resetMBR'):
- self.live.reset_mbr()
-
- self.parent.status = _('Writing the data')
- self.live.create_persistent_overlay()
- self.live.update_configs()
- self.live.install_bootloader()
- self.live.bootable_partition()
-
- self.parent.status = _('Checking the written data')
- if self.live.opts.device_checksum:
- self.live.calculate_device_checksum(progressThread=self)
- if self.live.opts.liveos_checksum:
- self.live.calculate_liveos_checksum()
-
- self.progressThread.stop()
-
- # Flush all filesystem buffers and unmount
- self.live.flush_buffers()
- self.live.unmount_device()
- self.parent.status = _('Finished!')
- self.parent.finished = True
-
- duration = str(datetime.now() - now).split('.')[0]
- #self.parent.status = 'Complete! (%s)' % duration
-
- self.progressThread.stop()
-
def set_max_progress(self, maximum):
self.parent.maxProgress = maximum
@@ -502,24 +450,7 @@ class Release(QObject):
if not self.live.drive:
return
- if self.parent().option('dd'):
- self.addWarning(_('You are about to perform a destructive install. This will erase all data and partitions on your USB drive'))
- else:
- if self.live.blank_mbr():
- self.addInfo(_('The Master Boot Record on your device is blank. Writing the image will reset the MBR on this device'))
- elif not self.live.mbr_matches_syslinux_bin() and not self.parent().option('resetMBR'):
- self.addInfo(_('The Master Boot Record on your device does not match your system\'s syslinux MBR.\n'
- 'If you have trouble booting it, try setting the \"Reset the MBR\" advanced option.'))
-
- try:
- self.live.mount_device()
- except LiveUSBError, e:
- self.addInfo(e.args[0])
- except OSError, e:
- self.addInfo(_('Unable to mount device'))
-
- if self.live.existing_liveos() and not self.parent().option('dd'):
- self.addWarning(_('Your device already contains a live OS. If you continue, it will be overwritten.'))
+ self.addWarning(_('You are about to perform a destructive install. This will erase all data and partitions on your USB drive'))
@pyqtProperty(int, constant=True)
def index(self):
@@ -788,13 +719,10 @@ class LiveUSBData(QObject):
_currentDrive = 0
# man, this is just awkward... but it seems like the only way to do it in a predictable manner without creating a new class
- _optionKeys = ['dd', 'resetMBR'] if not sys.platform.startswith("win") \
- else ['resetMBR']
- _optionNames = {'dd': _('Use <b>dd</b> to write the image - this will erase everything on your portable drive'),
- 'resetMBR': _('Reset the MBR (Master Boot Record)'),
+ _optionKeys = []
+ _optionNames = {
}
- _optionValues = {'dd': False,
- 'resetMBR': True,
+ _optionValues = {
}
def __init__(self, opts):
@@ -932,11 +860,6 @@ class LiveUSBData(QObject):
def setOption(self, index, value):
key = self._optionKeys[index]
if self._optionValues[key] != value:
- # dd and resetMBR options are mutually exclusive
- if key == 'dd' and value:
- self._optionValues['resetMBR'] = False
- if key == 'resetMBR' and value:
- self._optionValues['dd'] = False
self._optionValues[key] = value
self.optionsChanged.emit()
self.currentImage.inspectDestination()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git
More information about the Pkg-privacy-commits
mailing list