Exemplo n.º 1
0
    def on_partition_list_delete_activate(self, button):
        selection = self.partition_list.get_selection()

        if not selection:
            return

        model, tree_iter = selection.get_selected()

        if tree_iter == None:
            return

        # No es pot crear una taula de particions nova quan hi ha
        # particions actives.  Les particions actives són aquelles
        # que s'estan utilitzant, com ara un sistema de fitxers muntat
        # o un espai d'intercanvi habilitat.
        # Utilitzeu les opcions del menú Partició, com ara «Desmunta»
        # o «Partició d'intercanvi inactiva», per desactivar totes
        # les particions d'aquest dispositiu abans de crear una taula
        # de particions nova.

        parent_iter = model.iter_parent(tree_iter)

        part_type = model[tree_iter][10]

        if part_type == pm.PARTITION_LOGICAL:
            parent_iter = model.iter_parent(parent_iter)

        disk_path = model[parent_iter][0]

        logical_partition = False

        row = model[tree_iter]

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

        print("You will delete from disk [%s] partition [%s]" % (disk_path, partition_path))

        if self.disks == None:
            # just call get_devices once
            self.disks = pm.get_devices()

        disk = self.disks[disk_path]

        partitions = pm.get_partitions(disk)

        part = partitions[partition_path]

        if pm.check_mounted(part):
            # Should we ask first?
            subp = subprocess.Popen(["umount", part.path], stdout=subprocess.PIPE)

        # Is it worth to show some warning message here?
        pm.delete_partition(disk, part)

        # Update treeview
        self.fill_partition_list()
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def fill_partition_list(self):
        # create tree store 'partition_list_store' for our model

        if self.partition_list_store != None:
            self.partition_list_store.clear()

        # Treeview columns:
        # disc path or partition path or "free space",
        # fs_type
        # label
        # part_name
        # formatable_active
        # formatable_visible
        # size
        # used
        # partition_path
        # flags

        self.partition_list_store = Gtk.TreeStore(str, str, str, str, bool, bool, str, str, str, str, int)

        if self.disks == None:
            # just call get_devices once
            self.disks = pm.get_devices()

        for disk_path in sorted(self.disks):
            disk = self.disks[disk_path]

            if disk is None:
                # maybe disk without a partition table?
                print(disk_path)
                row = [disk_path, "", "", "", False, False, "", "", "", "", 0]
                self.partition_list_store.append(None, row)
            else:
                dev = disk.device

                size_txt = self.get_size(dev.length, dev.sectorSize)

                row = [dev.path, "", "", "", False, False, size_txt, "", "", "", 0]
                disk_parent = self.partition_list_store.append(None, row)

                parent = disk_parent

                # create list of partitions for this device (/dev/sda for example)
                partitions = pm.get_partitions(disk)
                partition_list = pm.order_partitions(partitions)

                for partition_path in partition_list:
                    p = partitions[partition_path]

                    size_txt = self.get_size(p.geometry.length, dev.sectorSize)

                    label = ""

                    if p.type == pm.PARTITION_EXTENDED:
                        path = p.path
                        mount_point = ""
                        fs_type = _("extended")
                        formatable = False
                        used = ""
                        flags = pm.get_flags(p)
                        # aas# cannot get label from staged partition
                        try:
                            info = fs.get_info(partition_path)
                        except:
                            info = []
                        if "LABEL" in info:
                            label = info["LABEL"]
                    elif p.type == pm.PARTITION_PRIMARY or p.type == pm.PARTITION_LOGICAL:
                        path = p.path
                        # aas# fix crash if no fs on partition
                        if p.fileSystem:
                            fs_type = p.fileSystem.type
                        else:
                            fs_type = "none"
                        formatable = True
                        used = str(pm.get_used_space(p))
                        flags = pm.get_flags(p)

                        if pm.check_mounted(p):
                            if "swap" in fs_type:
                                mount_point = "(swap)"
                            else:
                                mount_point = self.get_mount_point(p.path)
                        else:
                            mount_point = ""
                        # aas# we cannot get label of staged partition
                        try:
                            info = fs.get_info(partition_path)
                        except:
                            info = []
                        if "LABEL" in info:
                            label = info["LABEL"]

                    elif p.type == pm.PARTITION_FREESPACE:
                        path = _("free space")
                        mount_point = ""
                        fs_type = _("not used")
                        formatable = True
                        used = ""
                        flags = ""

                    row = [
                        path,
                        fs_type,
                        mount_point,
                        label,
                        False,
                        formatable,
                        size_txt,
                        used,
                        partition_path,
                        "",
                        p.type,
                    ]
                    tree_iter = self.partition_list_store.append(parent, row)

                    if p.type == pm.PARTITION_EXTENDED:
                        parent = tree_iter
                    elif p.type == pm.PARTITION_PRIMARY:
                        parent = disk_parent

        # assign our new model to our treeview
        self.partition_list.set_model(self.partition_list_store)
        self.partition_list.expand_all()