Пример #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()
Пример #2
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()