예제 #1
0
    def __init__(self):
        super(PartitionSetup, self).__init__(str,  # path
                                             str,  # type (fs)
                                             str,  # description (OS)
                                             str,  # format to
                                             str,  # mount point
                                             str,  # size
                                             str,  # free space
                                             object,  # partition object
                                             str)  # disk device path
        installer.setup.partitions = []
        installer.setup.partition_setup = self
        self.html_chunks = {}, defaultdict(list)

        os.popen('mkdir -p ' + TMP_MOUNTPOINT)
        installer.setup.gptonefi = is_efi_supported()
        self.disks = get_disks()
        print('Disks: ', self.disks)
        already_done_full_disk_format = False
        for disk_path, disk_description in self.disks:
            print("    Analyzing path='%s' description='%s'" % (disk_path, disk_description))
            disk_device = parted.getDevice(disk_path)
            print("      - Found the device...")
            try:
                disk = parted.Disk(disk_device)
                print("      - Found the disk...")
            except Exception as detail:
                print("      - Found an issue while looking for the disk: %s" % detail)
                from frontend.gtk_interface import QuestionDialog
                dialog = QuestionDialog(_("Installation Tool"),
                                        _("No partition table was found on the hard drive: %s. Do you want the installer to create a set of partitions for you? Note: This will ERASE ALL DATA present on this disk.") % disk_description,
                                        None, installer.window)
                if not dialog: continue  # the user said No, skip this disk
                try:
                    installer.window.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
                    print("Performing a full disk format")
                    if not already_done_full_disk_format:
                        assign_mount_format = full_disk_format(disk_device)
                        already_done_full_disk_format = True
                    else:
                        full_disk_format(disk_device) # Format but don't assign mount points
                    installer.window.get_window().set_cursor(None)
                    print("Done full disk format")
                    disk = parted.Disk(disk_device)
                    print("Got disk!")
                except Exception as second_exception:
                    installer.window.get_window().set_cursor(None)
                    print("      - Found another issue while looking for the disk: %s" % detail)
                    continue # Something is wrong with this disk, skip it

            disk_iter = self.append(None, (disk_description, '', '', '', '', '', '', None, disk_path))
            print("      - Looking at partitions...")
            free_space_partition = disk.getFreeSpacePartitions()
            print("           -> %d free space partitions" % len(free_space_partition))
            primary_partitions = disk.getPrimaryPartitions()
            print("           -> %d primary partitions" % len(primary_partitions))
            logical_partitions = disk.getLogicalPartitions()
            print("           -> %d logical partitions" % len(logical_partitions))
            raid_partitions = disk.getRaidPartitions()
            print("           -> %d raid partitions" % len(raid_partitions))
            lvm_partitions = disk.getLVMPartitions()
            print("           -> %d LVM partitions" % len(lvm_partitions))

            partition_set = tuple(free_space_partition + primary_partitions + logical_partitions + raid_partitions + lvm_partitions)
            print("           -> set of %d partitions" % len(partition_set))

            partitions = []
            for partition in partition_set:
                part = Partition(partition)
                print((partition.path, part.size, part.raw_size))
                # skip ranges <5MB
                if part.raw_size > 5242880:
                    partitions.append(part)
                else:
                    print(("skipping ", partition.path, part.raw_size))
            partitions = sorted(partitions, key=lambda part: part.partition.geometry.start)

            print("      - Found partitions...")
            try: # assign mount_as and format_as if disk was just auto-formatted
                for partition, (mount_as, format_as) in zip(partitions, assign_mount_format):
                    partition.mount_as = mount_as
                    partition.format_as = format_as
                del assign_mount_format
            except NameError: pass
            print("      - Iterating partitions...")
            # Needed to fix the 1% minimum Partition.size_percent
            sum_size_percent = sum(p.size_percent for p in partitions) + .5  # .5 for good measure
            for partition in partitions:
                print("        . Appending partition %s..." % partition.name)
                partition.size_percent = round(partition.size_percent / sum_size_percent * 100, 1)
                installer.setup.partitions.append(partition)
                self.append(disk_iter, (partition.name,
                                        '<span foreground="{}">{}</span>'.format(partition.color, partition.type),
                                        partition.description,
                                        partition.format_as,
                                        partition.mount_as,
                                        partition.size,
                                        partition.free_space,
                                        partition,
                                        disk_path))
예제 #2
0
    def __init__(self):
        super(PartitionSetup, self).__init__(
            str,  # path
            str,  # type (fs)
            str,  # description (OS)
            str,  # format to
            str,  # mount point
            str,  # size
            str,  # free space
            object,  # partition object
            str)  # disk device path
        installer.setup.partitions = []
        installer.setup.partition_setup = self

        os.popen('mkdir -p ' + TMP_MOUNTPOINT)
        self.disks = get_disks()
        log('Disks: ', self.disks)
        already_done_full_disk_format = False
        for disk_path, disk_description in self.disks:
            log("    Analyzing path='%s' description='%s'" %
                (disk_path, disk_description))
            disk_device = parted.getDevice(disk_path)
            try:
                disk = parted.Disk(disk_device)
            except Exception as detail:
                log("Found an issue while looking for the disk: %s" % detail)
                from frontend.gtk_interface import QuestionDialog
                dialog = QuestionDialog(
                    _("Installation Tool"),
                    _("No partition table was found on the hard drive: %s. Do you want the installer to create a set of partitions for you? Note: This will ERASE ALL DATA present on this disk."
                      ) % disk_description, None, installer.window)
                if not dialog:
                    continue  # the user said No, skip this disk
                try:
                    installer.window.get_window().set_cursor(
                        Gdk.Cursor.new(Gdk.CursorType.WATCH))
                    if not already_done_full_disk_format:
                        assign_mount_format = full_disk_format(disk_device)
                        already_done_full_disk_format = True
                    else:
                        # Format but don't assign mount points
                        full_disk_format(disk_device)
                    installer.window.get_window().set_cursor(None)
                    disk = parted.Disk(disk_device)
                except Exception:
                    installer.window.get_window().set_cursor(None)
                    continue  # Something is wrong with this disk, skip it

            disk_iter = self.append(
                None,
                (disk_description, '', '', '', '', '', '', None, disk_path))
            free_space_partition = disk.getFreeSpacePartitions()
            primary_partitions = disk.getPrimaryPartitions()
            logical_partitions = disk.getLogicalPartitions()
            raid_partitions = disk.getRaidPartitions()
            lvm_partitions = disk.getLVMPartitions()
            partition_set = tuple(free_space_partition + primary_partitions +
                                  logical_partitions + raid_partitions +
                                  lvm_partitions)
            partitions = []
            for partition in partition_set:
                part = Partition(partition)
                log("{} {}".format(partition.path.replace("-", ""), part.size))
                # skip ranges <5MB
                if part.raw_size > 5242880:
                    partitions.append(part)
            partitions = sorted(partitions,
                                key=lambda part: part.partition.geometry.start)

            try:  # assign mount_as and format_as if disk was just auto-formatted
                for partition, (mount_as,
                                format_as) in zip(partitions,
                                                  assign_mount_format):
                    partition.mount_as = mount_as
                    partition.format_as = format_as
                del assign_mount_format
            except NameError:
                pass
            # Needed to fix the 1% minimum Partition.size_percent
            # .5 for good measure
            sum_size_percent = sum(p.size_percent for p in partitions) + .5
            for partition in partitions:
                partition.size_percent = round(
                    partition.size_percent / sum_size_percent * 100, 1)
                installer.setup.partitions.append(partition)
                self.append(
                    disk_iter,
                    (partition.name, '<span>{}</span>'.format(
                        partition.type), partition.description,
                     partition.format_as, partition.mount_as, partition.size,
                     partition.free_space, partition, disk_path))
예제 #3
0
class PartitionSetup(Gtk.TreeStore):
    def __init__(self):
        super(PartitionSetup, self).__init__(
            str,  # path
            str,  # type (fs)
            str,  # description (OS)
            str,  # format to
            str,  # mount point
            str,  # size
            str,  # free space
            object,  # partition object
            str)  # disk device path
        installer.setup.partitions = []
        installer.setup.partition_setup = self
        self.html_disks, self.html_chunks = {}, defaultdict(list)

        def _get_attached_disks():
            disks = []
            exclude_devices = [
                '/dev/sr0', '/dev/sr1', '/dev/cdrom', '/dev/dvd', '/dev/fd0'
            ]
            live_device = commands.getoutput(
                "findmnt -n -o source /lib/live/mount/medium").split('\n')[0]
            live_device = re.sub(
                '[0-9]+$', '', live_device)  # remove partition numbers if any
            if live_device is not None and live_device.startswith('/dev/'):
                exclude_devices.append(live_device)
                print "Excluding %s (detected as the live device)" % live_device
            lsblk = shell_exec(
                'LC_ALL=en_US.UTF-8 lsblk -rindo TYPE,NAME,RM,SIZE,MODEL | sort -k3,2'
            )
            for line in lsblk.stdout:
                try:
                    elements = line.strip().split(" ", 4)
                    if len(elements) < 4:
                        print "Can't parse blkid output: %s" % elements
                        continue
                    elif len(elements) < 5:
                        print "Can't find model in blkid output: %s" % elements
                        type, device, removable, size, model = elements[
                            0], elements[1], elements[2], elements[
                                3], elements[1]
                    else:
                        type, device, removable, size, model = elements
                    device = "/dev/" + device
                    if type == "disk" and device not in exclude_devices:
                        # convert size to manufacturer's size for show, e.g. in GB, not GiB!
                        unit_index = 'BKMGTPEZY'.index(size.upper()[-1])
                        l10n_unit = [
                            _('B'),
                            _('kB'),
                            _('MB'),
                            _('GB'),
                            _('TB'), 'PB', 'EB', 'ZB', 'YB'
                        ][unit_index]
                        size = "%s %s" % (str(
                            int(float(size[:-1]) *
                                (1024 / 1000)**unit_index)), l10n_unit)
                        model = model.replace("\\x20", " ")
                        description = '{} ({})'.format(model.strip(), size)
                        if int(removable):
                            description = _('Removable:') + ' ' + description
                        disks.append((device, description))
                except Exception, detail:
                    print "Could not parse blkid output: %s (%s)" % (line,
                                                                     detail)
            return disks

        os.popen('mkdir -p ' + TMP_MOUNTPOINT)
        installer.setup.gptonefi = is_efi_supported()
        self.disks = _get_attached_disks()
        print 'Disks: ', self.disks
        already_done_full_disk_format = False
        for disk_path, disk_description in self.disks:
            print "    Analyzing path='%s' description='%s'" % (
                disk_path, disk_description)
            disk_device = parted.getDevice(disk_path)
            print "      - Found the device..."
            try:
                disk = parted.Disk(disk_device)
                print "      - Found the disk..."
            except Exception, detail:
                print "      - Found an issue while looking for the disk: %s" % detail
                from frontend.gtk_interface import QuestionDialog
                dialog = QuestionDialog(
                    _("Installation Tool"),
                    _("No partition table was found on the hard drive: %s. Do you want the installer to create a set of partitions for you? Note: This will ERASE ALL DATA present on this disk."
                      ) % disk_description, None, installer.window)
                if not dialog: continue  # the user said No, skip this disk
                try:
                    installer.window.get_window().set_cursor(
                        Gdk.Cursor.new(Gdk.CursorType.WATCH))
                    print "Performing a full disk format"
                    if not already_done_full_disk_format:
                        assign_mount_format = self.full_disk_format(
                            disk_device)
                        already_done_full_disk_format = True
                    else:
                        self.full_disk_format(
                            disk_device
                        )  # Format but don't assign mount points
                    installer.window.get_window().set_cursor(None)
                    print "Done full disk format"
                    disk = parted.Disk(disk_device)
                    print "Got disk!"
                except Exception as second_exception:
                    installer.window.get_window().set_cursor(None)
                    print "      - Found another issue while looking for the disk: %s" % detail
                    continue  # Something is wrong with this disk, skip it

            disk_iter = self.append(
                None,
                (disk_description, '', '', '', '', '', '', None, disk_path))
            print "      - Looking at partitions..."
            free_space_partition = disk.getFreeSpacePartitions()
            print "           -> %d free space partitions" % len(
                free_space_partition)
            primary_partitions = disk.getPrimaryPartitions()
            print "           -> %d primary partitions" % len(
                primary_partitions)
            logical_partitions = disk.getLogicalPartitions()
            print "           -> %d logical partitions" % len(
                logical_partitions)
            raid_partitions = disk.getRaidPartitions()
            print "           -> %d raid partitions" % len(raid_partitions)
            lvm_partitions = disk.getLVMPartitions()
            print "           -> %d LVM partitions" % len(lvm_partitions)

            partition_set = set(free_space_partition + primary_partitions +
                                logical_partitions + raid_partitions +
                                lvm_partitions)
            print "           -> set of %d partitions" % len(partition_set)

            partitions = []
            for partition in partition_set:
                part = Partition(partition)
                print(partition.path, part.size, part.raw_size)
                # skip ranges <5MB
                if part.raw_size > 5242880:
                    partitions.append(part)
                else:
                    print("skipping ", partition.path, part.raw_size)
            partitions = sorted(partitions,
                                key=lambda part: part.partition.geometry.start)

            print "      - Found partitions..."
            try:  # assign mount_as and format_as if disk was just auto-formatted
                for partition, (mount_as,
                                format_as) in zip(partitions,
                                                  assign_mount_format):
                    partition.mount_as = mount_as
                    partition.format_as = format_as
                del assign_mount_format
            except NameError:
                pass
            print "      - Iterating partitions..."
            # Needed to fix the 1% minimum Partition.size_percent
            sum_size_percent = sum(
                p.size_percent for p in partitions) + .5  # .5 for good measure
            for partition in partitions:
                print "        . Appending partition %s..." % partition.name
                partition.size_percent = round(
                    partition.size_percent / sum_size_percent * 100, 1)
                installer.setup.partitions.append(partition)
                self.append(
                    disk_iter,
                    (partition.name, '<span foreground="{}">{}</span>'.format(
                        partition.color,
                        partition.type), partition.description,
                     partition.format_as, partition.mount_as, partition.size,
                     partition.free_space, partition, disk_path))

            print "      - Loading HTML view..."
            self.html_disks[disk_path] = DISK_TEMPLATE.format(
                PARTITIONS_HTML=''.join(
                    PARTITION_TEMPLATE.format(p) for p in partitions))
예제 #4
0
    def __init__(self):
        super(PartitionSetup, self).__init__(str,  # path
                                             str,  # type (fs)
                                             str,  # description (OS)
                                             str,  # format to
                                             str,  # mount point
                                             str,  # size
                                             str,  # free space
                                             object,  # partition object
                                             str)  # disk device path
        installer.setup.partitions = []
        installer.setup.partition_setup = self
        self.html_disks, self.html_chunks = {}, defaultdict(list)

        def _get_attached_disks():
            disks = []
            exclude_devices = '/dev/sr0 /dev/sr1 /dev/cdrom /dev/dvd'.split()
            lsblk = shell_exec('lsblk -rindo TYPE,NAME,RM,SIZE,MODEL | sort -k3,2')
            for line in lsblk.stdout:
                type, device, removable, size, model = line.split(" ", 4)
                if type == "disk" and device not in exclude_devices:
                    device = "/dev/" + device
                    # convert size to manufacturer's size for show, e.g. in GB, not GiB!
                    size = str(int(float(size[:-1]) * (1024/1000)**'BkMGTPEZY'.index(size[-1]))) + size[-1]
                    description = '{} ({}B)'.format(model.strip(), size)
                    if int(removable):
                        description = _('Removable:') + ' ' + description
                    disks.append((device, description))
            return disks

        os.popen('mkdir -p ' + TMP_MOUNTPOINT)
        installer.setup.gptonefi = is_efi_supported()
        self.disks = _get_attached_disks()
        print 'Disks: ', self.disks
        for disk_path, disk_description in self.disks:
            disk_device = parted.getDevice(disk_path)
            try: disk = parted.Disk(disk_device)
            except Exception:
                from frontend.gtk_interface import QuestionDialog
                dialog = QuestionDialog(_("Installation Tool"),
                                        _("No partition table was found on the hard drive: {disk_description}. Do you want the installer to create a set of partitions for you? Note: This will ERASE ALL DATA present on this disk.").format(**locals()),
                                        installer.window)
                if not dialog.show(): continue  # the user said No, skip this disk
                installer.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
                assign_mount_format = self.full_disk_format(disk_device)
                installer.window.window.set_cursor(None)
                disk = parted.Disk(disk_device)
            disk_iter = self.append(None, (disk_description, '', '', '', '', '', '', None, disk_path))
            partitions = map(Partition,
                             sorted(filter(lambda part: part.getLength('MB') > 5,  # skip ranges <5MB
                                    set(disk.getFreeSpacePartitions() +
                                        disk.getPrimaryPartitions() +
                                        disk.getLogicalPartitions() +
                                        disk.getRaidPartitions() +
                                        disk.getLVMPartitions())),
                                    key=lambda part: part.geometry.start))
            try: # assign mount_as and format_as if disk was just auto-formatted
                for partition, (mount_as, format_as) in zip(partitions, assign_mount_format):
                    partition.mount_as = mount_as
                    partition.format_as = format_as
                del assign_mount_format
            except NameError: pass
            # Needed to fix the 1% minimum Partition.size_percent
            sum_size_percent = sum(p.size_percent for p in partitions) + .5  # .5 for good measure
            for partition in partitions:
                partition.size_percent = round(partition.size_percent / sum_size_percent * 100, 1)
                installer.setup.partitions.append(partition)
                self.append(disk_iter, (partition.name,
                                        '<span foreground="{}">{}</span>'.format(partition.color, partition.type),
                                        partition.description,
                                        partition.format_as,
                                        partition.mount_as,
                                        partition.size,
                                        partition.free_space,
                                        partition,
                                        disk_path))
            self.html_disks[disk_path] = DISK_TEMPLATE.format(PARTITIONS_HTML=''.join(PARTITION_TEMPLATE.format(p) for p in partitions))