Esempio n. 1
0
    def on_partition_list_new_activate(self, button):
        # print("on_partition_list_new_activate : add a new partition")

        selection = self.partition_list.get_selection()

        if not selection:
            return

        model, tree_iter = selection.get_selected()

        if tree_iter == None:
            return

        print("You selected %s" % model[tree_iter][0])

        if model[tree_iter][0] == _("free space"):

            parent_iter = model.iter_parent(tree_iter)

            disk_path = model[parent_iter][0]

            row = model[tree_iter]

            size_available = row[6]
            partition_path = row[8]

            if self.disks == None:
                self.disks = pm.get_devices()

            disk = self.disks[disk_path]
            dev = disk.device

            partitions = pm.get_partitions(disk)
            p = partitions[partition_path]

            # Get the objects from the dialog
            size_spin = self.ui.get_object("partition_size_spinbutton")
            primary_radio = self.ui.get_object("partition_create_type_primary")
            logical_radio = self.ui.get_object("partition_create_type_logical")
            beginning_radio = self.ui.get_object("partition_create_place_beginning")
            end_radio = self.ui.get_object("partition_create_place_end")
            use_combo = self.ui.get_object("partition_use_combo")
            format_checkbutton = self.ui.get_object("partition_edit_format_checkbutton")
            mount_combo = self.ui.get_object("partition_mount_combo")

            # prepare size spin
            # aas# +1 as not to leave unusably small space behind
            max_size_mb = int((p.geometry.length * dev.sectorSize) / 1000000) + 1

            size_spin.set_digits(0)
            # value, lower, upper, step_incr, page_incr, page_size
            adjustment = Gtk.Adjustment(max_size_mb, 1, max_size_mb, 1, 10, 0)
            size_spin.set_adjustment(adjustment)

            # use_combo

            use_combo.remove_all()
            for fs_name in sorted(fs._names):
                use_combo.append_text(fs_name)

            use_combo.set_wrap_width(2)

            # mount points

            mount_combo.remove_all()
            for mp in sorted(fs._common_mount_points):
                mount_combo.append_text(mp)

            # finally, show the create partition dialog

            response = self.edit_partition_dialog.run()

            if response == Gtk.ResponseType.OK:

                size = int(size_spin.get_value())
                # aas# pm does this already.  Just pass it size
                # size_in_sectors = int((size * 1000000) / dev.sectorSize)

                print("size : %d" % size)
                # print("size_in_sectors : %d" % size_in_sectors)
                # aas# pm does this already.  using variable instead
                if beginning_radio.get_active():
                    beg_var = True
                else:
                    beg_var = False
                start_sector = p.geometry.start
                end_sector = p.geometry.end
                print("start sector : %d" % start_sector)

                # part_type
                if primary_radio.get_active():
                    part_type = pm.PARTITION_PRIMARY
                else:
                    part_type = pm.PARTITION_LOGICAL

                # if the partition is of type LOGICAL, we must search if an
                # extended partition is already there. If it is, we must add
                # our logical partition to it, if it's not, we must create
                # an extended partition and then create our logical partition
                # inside.

                # Anaconda code follows. Must be adapted.
                #
                #        part_type = None
                #    extended = disk.getExtendedPartition()
                #    supports_extended = disk.supportsFeature(parted.DISK_TYPE_EXTENDED)
                #    logical_count = len(disk.getLogicalPartitions())
                #    max_logicals = disk.getMaxLogicalPartitions()
                #    primary_count = disk.primaryPartitionCount

                # if primary_count < disk.maxPrimaryPartitionCount:
                #        if primary_count == disk.maxPrimaryPartitionCount - 1:
                ## can we make an extended partition? now's our chance.
                # if not extended and supports_extended:
                #                part_type = parted.PARTITION_EXTENDED
                # elif not extended:
                ## extended partitions not supported. primary or nothing.
                # if not no_primary:
                # part_type = parted.PARTITION_NORMAL
                # else:
                ## there is an extended and a free primary
                # if not no_primary:
                # part_type = parted.PARTITION_NORMAL
                # elif logical_count < max_logicals:
                ## we have an extended with logical slots, so use one.
                # part_type = parted.PARTITION_LOGICAL
                # else:
                # there are two or more primary slots left. use one unless we're
                # not supposed to make primaries.
                #        if not no_primary:
                # part_type = parted.PARTITION_NORMAL
                # elif extended and logical_count < max_logicals:
                # part_type = parted.PARTITION_LOGICAL
                # elif extended and logical_count < max_logicals:
                # part_type = parted.PARTITION_LOGICAL
                # aas# pm does the below, no need to do here too
                # if part_type == pm.PARTITION_LOGICAL:
                # make room for logical partition's metadata
                #   start_sector += disklabel.alignment.grainSize
                #  print("start sector adjusted : %d" % start_sector)
                # aas# fixed this call
                geometry = pm.geom_builder(disk, start_sector, end_sector, size, beg_var)

                pm.create_partition(disk, part_type, geometry)

                # TODO: Don't forget these ones!
                # use_as
                # format
                # mount_point

                print("OK!")
                self.fill_partition_list()
            else:
                print("Cancel or closed!")

            self.edit_partition_dialog.hide()