Exemple #1
0
 def create_partition(self, widget):
     self.create_bt.set_sensitive(False)
     self.delete_bt.set_sensitive(False)
     self.modify_bt.set_sensitive(False)
     self.auto_bt.set_sensitive(False)
     self.revert_bt.set_sensitive(False)
     if len(self.path) == 2 and how_partition(
             self.path) == 1 and self.slice == 'freespace':
         self.schemeEditor(False)
     elif len(self.path) == 3:
         if self.slice == 'freespace':
             self.labelEditor(self.path, self.slice, self.size, 'MBR',
                              False)
     elif len(self.path) == 2 and self.slice == 'freespace':
         if scheme_query(self.path) == "MBR" and self.path[1] < 4:
             self.sliceEditor()
         elif scheme_query(self.path) == "GPT":
             self.labelEditor(self.path, self.slice, self.size, 'GPT',
                              False)
     else:
         if how_partition(self.path) == 1:
             self.schemeEditor(True)
         elif how_partition(self.path) == 0:
             self.schemeEditor(True)
         else:
             pass
Exemple #2
0
 def create_partition(self, widget):
     if len(self.path) == 3:
         if self.slice == 'freespace':
             self.labelEditor(self.path, self.slice, self.size, 0, 1)
     elif len(self.path) == 2 and self.slice == 'freespace':
         if scheme_query(self.path) == "MBR" and self.path[1] < 4:
             self.sliceEditor()
         elif scheme_query(self.path) == "GPT":
             self.labelEditor(self.path, self.slice, self.size, 1, 1)
     else:
         if how_partition(self.path) == 1:
             self.schemeEditor(True)
         elif how_partition(self.path) == 0:
             self.schemeEditor(True)
         else:
             pass
Exemple #3
0
 def create_partition(self, widget):
     if len(self.path) == 3:
         if self.slice == "freespace":
             self.labelEditor(self.path, self.slice, self.size, 0, 1)
     elif len(self.path) == 2 and self.slice == "freespace":
         if scheme_query(self.path) == "MBR" and self.path[1] < 4:
             self.sliceEditor()
         elif scheme_query(self.path) == "GPT":
             self.labelEditor(self.path, self.slice, self.size, 1, 1)
     else:
         if how_partition(self.path) == 1:
             self.schemeEditor(True)
         elif how_partition(self.path) == 0:
             self.schemeEditor(True)
         else:
             pass
Exemple #4
0
    def partition_selection(self, tree_selection):
        (model, pathlist) = tree_selection.get_selected_rows()
        for path in pathlist:
            tree_iter = model.get_iter(path)
            self.slice = model.get_value(tree_iter, 0)
            self.size = model.get_value(tree_iter, 1)
            #value2 = model.get_value(tree_iter, 2)
            self.scheme = model.get_value(tree_iter, 3)
            self.path = path

            if 'freespace' in self.slice:
                if path[1] >= 4 and "s" in self.slice:
                    self.create_bt.set_sensitive(False)
                else:
                    self.create_bt.set_sensitive(True)
                self.delete_bt.set_sensitive(False)
                self.modifi_bt.set_sensitive(False)
                self.auto_bt.set_sensitive(True)
            elif 's' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                #self.modifi_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            elif 'p' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                #self.modifi_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            else:
                self.delete_bt.set_sensitive(False)
                self.modifi_bt.set_sensitive(False)
                self.auto_bt.set_sensitive(True)
                if how_partition(self.path) == 1:
                    self.create_bt.set_sensitive(True)
                elif how_partition(self.path) == 0:
                    self.create_bt.set_sensitive(True)
                else:
                    self.create_bt.set_sensitive(False)
Exemple #5
0
    def partition_selection(self, tree_selection):
        (model, pathlist) = tree_selection.get_selected_rows()
        for path in pathlist:
            tree_iter = model.get_iter(path)
            self.slice = model.get_value(tree_iter, 0)
            self.size = model.get_value(tree_iter, 1)
            #value2 = model.get_value(tree_iter, 2)
            self.scheme = model.get_value(tree_iter, 3)
            self.path = path

            if 'freespace' in self.slice:
                if path[1] >= 4 and "s" in self.slice:
                    self.create_bt.set_sensitive(False)
                else:
                    self.create_bt.set_sensitive(True)
                self.delete_bt.set_sensitive(False)
                self.modifi_bt.set_sensitive(False)
                self.auto_bt.set_sensitive(True)
            elif 's' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                #self.modifi_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            elif 'p' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                #self.modifi_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            else:
                self.delete_bt.set_sensitive(False)
                self.modifi_bt.set_sensitive(False)
                self.auto_bt.set_sensitive(True)
                if how_partition(self.path) == 1:
                    self.create_bt.set_sensitive(True)
                elif how_partition(self.path) == 0:
                    self.create_bt.set_sensitive(True)
                else:
                    self.create_bt.set_sensitive(False)
Exemple #6
0
 def partition_selection(self, widget):
     model, self.iter, = widget.get_selected()
     if self.iter is not None:
         self.path = model.get_path(self.iter)
         tree_iter3 = model.get_iter(self.path[0])
         self.scheme = model.get_value(tree_iter3, 3)
         self.disk = model.get_value(tree_iter3, 0)
         tree_iter = model.get_iter(self.path)
         self.slice = model.get_value(tree_iter, 0)
         self.size = model.get_value(tree_iter, 1)
         if len(self.path) == 2 and self.path[1] > 0 and self.scheme == "MBR":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             sl = int(self.path[1]) + 1
             if 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('s')[2])
         elif len(self.path) == 2 and self.path[1] > 0 and self.scheme == "GPT":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             self.lablebehind = model.get_value(tree_iter2, 2)
             sl = int(self.path[1]) + 1
             if 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('p')[2])
         elif len(self.path) == 3 and self.path[2] > 0 and self.scheme == "MBR":
             if self.path[1] > 0:
                 pathbehind1 = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
                 tree_iter2 = model.get_iter(pathbehind1)
                 self.slicebehind = model.get_value(tree_iter2, 0)
             else:
                 self.slicebehind = None
             pathbehind2 = str(self.path[0]) + ":" + str(self.path[1]) + ":" + str(int(self.path[2] - 1))
             tree_iter3 = model.get_iter(pathbehind2)
             self.lablebehind = model.get_value(tree_iter3, 2)
             sl = int(self.path[1]) + 1
             if self.slicebehind is None:
                 slbehind = self.path[1]
             elif 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('s')[2])
         else:
             self.slicebehind = None
             self.lablebehind = None
             sl = 1
             slbehind = 0
         if 'freespace' in self.slice:
             if self.path[1] > 3 and self.scheme == "MBR":
                 self.create_bt.set_sensitive(False)
             elif self.slicebehind is None:
                 self.create_bt.set_sensitive(True)
             elif sl == slbehind:
                 self.create_bt.set_sensitive(False)
             elif slbehind > 4:
                 self.create_bt.set_sensitive(False)
             else:
                 self.create_bt.set_sensitive(True)
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
         elif 's' in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         elif 'p' in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         else:
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(False)
             how_many_prt = how_partition(self.path)
             firstisfree = first_is_free(self.path)
             if how_many_prt == 1 and firstisfree == 'freespace':
                 self.create_bt.set_sensitive(False)
             elif how_partition(self.path) == 0:
                 self.create_bt.set_sensitive(True)
             else:
                 self.create_bt.set_sensitive(False)
     if os.path.exists(Part_label):
         rd = open(Part_label, 'r')
         self.prttn = rd.readlines()
         rtbt = False
         for line in self.prttn:
             if "/boot\n" in line:
                 rtbt = True
                 break
         # If Find GPT scheme.
         if os.path.exists(disk_schem):
             rschm = open(disk_schem, 'r')
             schm = rschm.readlines()[0]
             efi = efi_exist(self.disk)
             if 'GPT' in schm:
                 if len(self.prttn) >= 2:
                     if 'BOOT' in self.prttn[0]:
                         if rtbt is True and "/boot\n" not in self.prttn[1]:
                             self.button3.set_sensitive(False)
                         elif "/boot\n" in self.prttn[1]:
                             if len(self.prttn) >= 3:
                                 if '/\n' in self.prttn[2]:
                                     self.button3.set_sensitive(True)
                                 else:
                                     self.button3.set_sensitive(False)
                             else:
                                 self.button3.set_sensitive(False)
                         elif '/\n' in self.prttn[1]:
                             self.button3.set_sensitive(True)
                         else:
                             self.button3.set_sensitive(False)
                     elif 'UEFI' in self.prttn[0] and efi is False:
                         if rtbt is True and "/boot\n" not in self.prttn[1]:
                             self.button3.set_sensitive(False)
                         elif "/boot\n" in self.prttn[1]:
                             if len(self.prttn) >= 3:
                                 if '/\n' in self.prttn[2]:
                                     self.button3.set_sensitive(True)
                                 else:
                                     self.button3.set_sensitive(False)
                             else:
                                 self.button3.set_sensitive(False)
                         elif '/\n' in self.prttn[1]:
                             self.button3.set_sensitive(True)
                         else:
                             self.button3.set_sensitive(False)
                     elif rtbt is True and "/boot\n" not in self.prttn[1]:
                         self.button3.set_sensitive(False)
                     elif "/boot\n" in self.prttn[0] and efi is True:
                         if len(self.prttn) >= 2:
                             if '/\n' in self.prttn[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif '/\n' in self.prttn[0] and efi is True:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
             else:
                 if len(self.prttn) >= 1:
                     if "/boot\n" in self.prttn[0]:
                         if len(self.prttn) >= 2:
                             if '/\n' in self.prttn[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif '/\n' in self.prttn[0]:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
         else:
             self.button3.set_sensitive(False)
     else:
             self.button3.set_sensitive(False)
Exemple #7
0
 def partition_selection(self, widget):
     model, self.iter, = widget.get_selected()
     if self.iter != None:
         self.path = model.get_path(self.iter)
         tree_iter3 = model.get_iter(self.path[0])
         self.scheme = model.get_value(tree_iter3, 3)
         tree_iter = model.get_iter(self.path)
         self.slice = model.get_value(tree_iter, 0)
         self.size = model.get_value(tree_iter, 1)
         if len(self.path) == 2 and self.path[1] > 0 and self.scheme == "MBR":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             sl = int(self.path[1]) + 1
             if 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('s')[2])
         elif len(self.path) == 2 and  self.path[1] > 0 and self.scheme == "GPT":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             self.lablebehind = model.get_value(tree_iter2, 2)
             sl = int(self.path[1]) + 1
             if 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('p')[2])
         elif len(self.path) == 3 and  self.path[2] > 0 and self.scheme == "MBR":
             if self.path[1] > 0:
                 pathbehind1 = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
                 tree_iter2 = model.get_iter(pathbehind1)
                 self.slicebehind = model.get_value(tree_iter2, 0)
             else:
                 self.slicebehind = None
             pathbehind2 = str(self.path[0]) + ":" + str(self.path[1]) + ":" + str(int(self.path[2] - 1))
             tree_iter3 = model.get_iter(pathbehind2)
             self.lablebehind = model.get_value(tree_iter3, 2)
             sl = int(self.path[1]) + 1
             if self.slicebehind is None:
                 slbehind = self.path[1]
             elif 'freespace' in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition('s')[2])
         else:
             self.slicebehind = None
             self.lablebehind = None
             sl = 1
             slbehind = 0
         if 'freespace' in self.slice:
             if self.path[1] > 3 and self.scheme == "MBR":
                 self.create_bt.set_sensitive(False)
             elif self.slicebehind == None:
                 self.create_bt.set_sensitive(True)
             elif sl == slbehind:
                 self.create_bt.set_sensitive(False)
             elif slbehind > 4:
                 self.create_bt.set_sensitive(False)
             else:
                 self.create_bt.set_sensitive(True)
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
         elif 's' in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             #self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         elif 'p' in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             #self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         else:
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
             if how_partition(self.path) == 1 and first_is_free(self.path) == 'freespace':
                 self.create_bt.set_sensitive(True)
             elif how_partition(self.path) == 0:
                 self.create_bt.set_sensitive(True)
             else:
                 self.create_bt.set_sensitive(False)
     if os.path.exists(Part_label):
         rd = open(Part_label, 'r')
         self.partfile = rd.readlines()
         # If Find GPT scheme.
         if os.path.exists(disk_schem):
             rschm = open(disk_schem, 'r')
             schm = rschm.readlines()[0]
             if 'GPT' in schm:
                 if len(self.partfile) >= 2:
                     if 'BOOT' in self.partfile[0] or 'BIOS' in self.partfile[0] or 'UEFI' in self.partfile[0]:
                             if "/boot\n" in self.partfile[1]:
                                 if len(self.partfile) >= 3:
                                     if '/\n' in self.partfile[1]:
                                         self.button3.set_sensitive(True)
                                     else:
                                         self.button3.set_sensitive(False)
                                 else:
                                     self.button3.set_sensitive(False)
                             elif '/\n' in self.partfile[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
             else:
                 if len(self.partfile) >= 1:
                     if "/boot\n" in self.partfile[0]:
                         if len(self.partfile) >= 2:
                             if '/\n' in self.partfile[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif '/\n' in self.partfile[0]:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
         else:
             self.button3.set_sensitive(False)
     else:
             self.button3.set_sensitive(False)
Exemple #8
0
    def partition_selection(self, widget):
        model, self.iter, = widget.get_selected()
        if self.iter is not None:
            self.path = model.get_path(self.iter)
            tree_iter3 = model.get_iter(self.path[0])
            self.scheme = model.get_value(tree_iter3, 3)
            self.disk = model.get_value(tree_iter3, 0)
            tree_iter = model.get_iter(self.path)
            self.slice = model.get_value(tree_iter, 0)
            self.size = model.get_value(tree_iter, 1)
            if len(self.path
                   ) == 2 and self.path[1] > 0 and self.scheme == "MBR":
                pathbehind = str(self.path[0]) + ":" + str(
                    int(self.path[1] - 1))
                tree_iter2 = model.get_iter(pathbehind)
                self.slicebehind = model.get_value(tree_iter2, 0)
                sl = int(self.path[1]) + 1
                if 'freespace' in self.slicebehind:
                    slbehind = self.path[1]
                else:
                    slbehind = int(self.slicebehind.partition('s')[2])
            elif len(self.path
                     ) == 2 and self.path[1] > 0 and self.scheme == "GPT":
                pathbehind = str(self.path[0]) + ":" + str(
                    int(self.path[1] - 1))
                tree_iter2 = model.get_iter(pathbehind)
                self.slicebehind = model.get_value(tree_iter2, 0)
                self.lablebehind = model.get_value(tree_iter2, 2)
                self.fsbehind = model.get_value(tree_iter2, 3)

                sl = int(self.path[1]) + 1
                if 'freespace' in self.slicebehind:
                    slbehind = self.path[1]
                else:
                    slbehind = int(self.slicebehind.partition('p')[2])
            elif len(self.path
                     ) == 3 and self.path[2] > 0 and self.scheme == "MBR":
                if self.path[2] > 0:
                    pathbehind1 = str(self.path[0]) + ":" + str(
                        self.path[1]) + ":" + str(int(self.path[2] - 1))
                    tree_iter2 = model.get_iter(pathbehind1)
                    self.slicebehind = model.get_value(tree_iter2, 0)
                else:
                    self.slicebehind = None
                pathbehind2 = str(self.path[0]) + ":" + str(
                    self.path[1]) + ":" + str(int(self.path[2] - 1))
                tree_iter3 = model.get_iter(pathbehind2)
                self.lablebehind = model.get_value(tree_iter3, 2)
                self.fsbehind = model.get_value(tree_iter3, 3)
                sl = int(self.path[1]) + 1
                if self.slicebehind is None:
                    slbehind = self.path[1]
                elif 'freespace' in self.slicebehind:
                    slbehind = self.path[1]
                else:
                    slbehind = int(self.slicebehind.partition('s')[2])
            else:
                self.slicebehind = None
                self.lablebehind = None
                self.fsbehind = None
                sl = 1
                slbehind = 0
            if 'freespace' in self.slice:
                if self.path[1] > 3 and self.scheme == "MBR":
                    self.create_bt.set_sensitive(False)
                elif self.slicebehind is None:
                    self.create_bt.set_sensitive(True)
                elif sl == slbehind:
                    self.create_bt.set_sensitive(False)
                # elif slbehind > 4:
                #     self.create_bt.set_sensitive(False)
                else:
                    self.create_bt.set_sensitive(True)
                self.delete_bt.set_sensitive(False)
                self.modify_bt.set_sensitive(False)
                # scan for efi partition
                for num in range(self.path[1]):
                    partition_path = f"{self.path[0]}:{num}"
                    first_tree_iter = model.get_iter(partition_path)
                    first_fs = model.get_value(first_tree_iter, 3)
                    if first_fs == "UEFI" or 'efi' in first_fs:
                        self.efi_exist = True
                        break
                else:
                    self.efi_exist = False
                self.auto_bt.set_sensitive(True)
            elif 's' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                # self.modify_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            elif 'p' in self.slice:
                self.create_bt.set_sensitive(False)
                self.delete_bt.set_sensitive(True)
                # self.modify_bt.set_sensitive(True)
                self.auto_bt.set_sensitive(False)
            else:
                self.delete_bt.set_sensitive(False)
                self.modify_bt.set_sensitive(False)
                self.auto_bt.set_sensitive(False)
                how_many_prt = how_partition(self.path)
                firstisfree = first_is_free(self.path)
                if how_many_prt == 1 and firstisfree == 'freespace':
                    self.create_bt.set_sensitive(False)
                elif how_partition(self.path) == 0:
                    self.create_bt.set_sensitive(True)
                else:
                    self.create_bt.set_sensitive(False)
        if os.path.exists(Part_label):
            rd = open(Part_label, 'r')
            self.prttn = rd.readlines()
            print(self.prttn)
            # Find if GPT scheme.
            if os.path.exists(disk_schem):
                rschm = open(disk_schem, 'r')
                schm = rschm.readlines()[0]
                if 'GPT' in schm:
                    if os.path.exists(disk_file):
                        diskfile = open(disk_file, 'r')
                        disk = diskfile.readlines()[0].strip()
                        diskfile.close()
                        disk_num = re.sub("[^0-9]", "", disk)
                        num = 0
                        while True:
                            partition_path = f"{disk_num}:{num}"
                            try:
                                first_tree_iter = model.get_iter(
                                    partition_path)
                                first_fs = model.get_value(first_tree_iter, 3)
                                if first_fs == "UEFI" or 'efi' in first_fs:
                                    self.efi_exist = True
                                    break
                            except ValueError:
                                self.efi_exist = False
                                break
                            num += 1
                    if 'BOOT' in self.prttn[0] and bios_type == 'BIOS':
                        if "/boot\n" in self.prttn[1]:
                            if len(self.prttn) >= 3:
                                if '/\n' in self.prttn[2]:
                                    self.button3.set_sensitive(True)
                                elif 'ZFS' in self.prttn[0]:
                                    self.button3.set_sensitive(True)
                                else:
                                    self.button3.set_sensitive(False)
                            else:
                                self.button3.set_sensitive(False)
                        elif '/\n' in self.prttn[1]:
                            self.button3.set_sensitive(True)
                        elif 'ZFS' in self.prttn[0]:
                            self.button3.set_sensitive(True)
                        else:
                            self.button3.set_sensitive(False)
                    elif self.efi_exist is True and bios_type == 'UEFI':
                        if '/\n' in self.prttn[0]:
                            self.button3.set_sensitive(True)
                        elif 'ZFS' in self.prttn[0]:
                            self.button3.set_sensitive(True)
                        elif "/boot\n" in self.prttn[0]:
                            if len(self.prttn) >= 2:
                                if '/\n' in self.prttn[1]:
                                    self.button3.set_sensitive(True)
                                elif 'ZFS' in self.prttn[0]:
                                    self.button3.set_sensitive(True)
                                else:
                                    self.button3.set_sensitive(False)
                            else:
                                self.button3.set_sensitive(False)
                        elif 'UEFI' in self.prttn[0] and '/\n' in self.prttn[1]:
                            self.button3.set_sensitive(True)
                        elif 'UEFI' in self.prttn[0] and 'ZFS' in self.prttn[1]:
                            self.button3.set_sensitive(True)
                        elif 'UEFI' in self.prttn[
                                0] and "/boot\n" in self.prttn[0]:
                            if len(self.prttn) >= 3:
                                if '/\n' in self.prttn[2]:
                                    self.button3.set_sensitive(True)
                                elif 'ZFS' in self.prttn[0]:
                                    self.button3.set_sensitive(True)
                                else:
                                    self.button3.set_sensitive(False)
                            else:
                                self.button3.set_sensitive(False)
                        else:
                            self.button3.set_sensitive(False)
                    else:
                        self.button3.set_sensitive(False)
                else:
                    # to be changed when MBR UEFI will be supported in the backend.
                    self.efi_exist = False
                    if len(self.prttn) >= 1:
                        if "/boot\n" in self.prttn[0]:
                            if len(self.prttn) >= 2:
                                if '/\n' in self.prttn[1]:
                                    self.button3.set_sensitive(True)
                                elif 'ZFS' in self.prttn[0]:
                                    self.button3.set_sensitive(True)
                                else:
                                    self.button3.set_sensitive(False)
                            else:
                                self.button3.set_sensitive(False)
                        elif '/\n' in self.prttn[0]:
                            self.button3.set_sensitive(True)
                        elif 'ZFS' in self.prttn[0]:
                            self.button3.set_sensitive(True)
                        else:
                            self.button3.set_sensitive(False)
                    else:
                        self.button3.set_sensitive(False)
            else:
                self.button3.set_sensitive(False)
        else:
            self.button3.set_sensitive(False)
        path_exist = [
            os.path.exists(Part_label),
            os.path.exists(disk_schem),
            os.path.exists(disk_file),
            os.path.exists(psize),
            os.path.exists(part_schem)
        ]
        if any(path_exist):
            self.revert_bt.set_sensitive(True)
        else:
            self.revert_bt.set_sensitive(False)
Exemple #9
0
 def partition_selection(self, widget):
     model, self.iter, = widget.get_selected()
     if self.iter is not None:
         self.path = model.get_path(self.iter)
         main_tree_iter = model.get_iter(self.path)
         self.size = model.get_value(main_tree_iter, 1)
         tree_iter1 = model.get_iter(self.path[0])
         self.scheme = model.get_value(tree_iter1, 3)
         self.disk = model.get_value(tree_iter1, 0)
         if len(self.path) >= 2:
             tree_iter2 = model.get_iter(self.path[:2])
             self.slice = model.get_value(tree_iter2, 0)
             self.change_schemes = False
         else:
             if len(self.path) == 1:
                 if how_partition(self.disk) == 1:
                     slice_path = f'{self.path[0]}:0'
                     tree_iter2 = model.get_iter(slice_path)
                     if 'freespace' in model.get_value(tree_iter2, 0):
                         self.change_schemes = True
                     else:
                         self.change_schemes = False
                 else:
                     self.change_schemes = False
                 self.slice = 'Not selected'
             else:
                 self.slice = 'Not selected'
                 self.change_schemes = False
         if len(self.path) == 3:
             tree_iter3 = model.get_iter(self.path[:3])
             self.label = model.get_value(tree_iter3, 0)
         else:
             self.label = 'Not selected'
         if len(self.path) == 2 and self.path[1] > 0 and self.scheme == "GPT":
             pathbehind = f'{self.path[0]}:{str(int(self.path[1] - 1))}'
             tree_iter4 = model.get_iter(pathbehind)
             self.mountpoint_behind = model.get_value(tree_iter4, 2)
             self.fs_behind = model.get_value(tree_iter4, 3)
         elif len(self.path) == 3 and self.path[2] > 0 and self.scheme == "MBR":
             pathbehind2 = f'{self.path[0]}:{str(self.path[1])}:{str(int(self.path[2] - 1))}'
             tree_iter1 = model.get_iter(pathbehind2)
             self.mountpoint_behind = model.get_value(tree_iter1, 2)
             self.fs_behind = model.get_value(tree_iter1, 3)
         else:
             self.mountpoint_behind = None
             self.fs_behind = None
         if 'freespace' in self.slice:
             self.create_bt.set_sensitive(True)
             self.delete_bt.set_sensitive(False)
             self.modify_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
             # scan for efi partition
             for num in range(self.path[1]):
                 partition_path = f"{self.path[0]}:{num}"
                 first_tree_iter = model.get_iter(partition_path)
                 first_fs = model.get_value(first_tree_iter, 3)
                 if first_fs == "UEFI" or 'efi' in first_fs:
                     self.efi_exist = True
                     break
             else:
                 self.efi_exist = False
         elif 'freespace' in self.label:
             if self.path[1] > 3:
                 self.create_bt.set_sensitive(False)
             else:
                 self.create_bt.set_sensitive(True)
                 self.auto_bt.set_sensitive(True)
             self.delete_bt.set_sensitive(False)
             self.modify_bt.set_sensitive(False)
         elif 's' in self.slice and len(self.path) > 1:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modify_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         elif 'p' in self.slice and len(self.path) > 1:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modify_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         else:
             self.delete_bt.set_sensitive(False)
             self.modify_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(False)
             if how_partition(self.disk) == 0:
                 self.create_bt.set_sensitive(True)
             elif self.change_schemes is True:
                 self.create_bt.set_sensitive(True)
             else:
                 self.create_bt.set_sensitive(False)
     if os.path.exists(partition_label_file):
         rd = open(partition_label_file, 'r')
         self.partitions = rd.readlines()
         # Find if GPT scheme.
         if os.path.exists(disk_scheme):
             rschm = open(disk_scheme, 'r')
             schm = rschm.read()
             if 'GPT' in schm:
                 if os.path.exists(disk_file):
                     diskfile = open(disk_file, 'r')
                     disk = diskfile.readlines()[0].strip()
                     diskfile.close()
                     disk_num = re.sub("[^0-9]", "", disk)
                     num = 0
                     while True:
                         partition_path = f"{disk_num}:{num}"
                         try:
                             first_tree_iter = model.get_iter(partition_path)
                             first_fs = model.get_value(first_tree_iter, 3)
                             if first_fs == "UEFI" or 'efi' in first_fs:
                                 self.efi_exist = True
                                 break
                         except ValueError:
                             self.efi_exist = False
                             break
                         num += 1
                 if 'BOOT' in self.partitions[0] and bios_type == 'BIOS':
                     if "/boot\n" in self.partitions[1]:
                         if len(self.partitions) >= 3:
                             if '/\n' in self.partitions[2]:
                                 self.button3.set_sensitive(True)
                             elif 'ZFS' in self.partitions[2]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif '/\n' in self.partitions[1]:
                         self.button3.set_sensitive(True)
                     elif 'ZFS' in self.partitions[1]:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 elif self.efi_exist is True and bios_type == 'UEFI':
                     if '/\n' in self.partitions[0]:
                         self.button3.set_sensitive(True)
                     elif 'ZFS' in self.partitions[0]:
                         self.button3.set_sensitive(True)
                     elif "/boot\n" in self.partitions[0]:
                         if len(self.partitions) >= 2:
                             if '/\n' in self.partitions[1]:
                                 self.button3.set_sensitive(True)
                             elif 'ZFS' in self.partitions[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                 elif 'UEFI' in self.partitions[0] and '/\n' in self.partitions[1]:
                     self.button3.set_sensitive(True)
                 elif 'UEFI' in self.partitions[0] and 'ZFS' in self.partitions[1]:
                     self.button3.set_sensitive(True)
                 elif 'UEFI' in self.partitions[0] and "/boot\n" in self.partitions[1]:
                     if len(self.partitions) >= 3:
                         if '/\n' in self.partitions[2]:
                             self.button3.set_sensitive(True)
                         elif 'ZFS' in self.partitions[2]:
                             self.button3.set_sensitive(True)
                         else:
                             self.button3.set_sensitive(False)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
             else:
                 # to be changed when MBR UEFI will be supported by pc-sysinstall.
                 self.efi_exist = False
                 if len(self.partitions) >= 1:
                     if "/boot\n" in self.partitions[0]:
                         if len(self.partitions) >= 2:
                             if '/\n' in self.partitions[1]:
                                 self.button3.set_sensitive(True)
                             elif 'ZFS' in self.partitions[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif '/\n' in self.partitions[0]:
                         self.button3.set_sensitive(True)
                     elif 'ZFS' in self.partitions[0]:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
         else:
             self.button3.set_sensitive(False)
     else:
         self.button3.set_sensitive(False)
     path_exist = [
         os.path.exists(f'{tmp}/create'),
         os.path.exists(disk_scheme),
         os.path.exists(disk_file),
         os.path.exists(slice_file),
         os.path.exists(f'{tmp}/delete'),
         os.path.exists(f'{tmp}/destroy'),
         os.path.exists(partition_label_file)
     ]
     if any(path_exist):
         self.revert_bt.set_sensitive(True)
     else:
         self.revert_bt.set_sensitive(False)
Exemple #10
0
 def partition_selection(self, widget):
     model, self.iter, = widget.get_selected()
     if self.iter != None:
         self.path = model.get_path(self.iter)
         tree_iter3 = model.get_iter(self.path[0])
         self.scheme = model.get_value(tree_iter3, 3)
         tree_iter = model.get_iter(self.path)
         self.slice = model.get_value(tree_iter, 0)
         self.size = model.get_value(tree_iter, 1)
         if len(self.path) == 2 and self.path[1] > 0 and self.scheme == "MBR":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             sl = int(self.path[1]) + 1
             if "freespace" in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition("s")[2])
         elif len(self.path) == 2 and self.path[1] > 0 and self.scheme == "GPT":
             pathbehind = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
             tree_iter2 = model.get_iter(pathbehind)
             self.slicebehind = model.get_value(tree_iter2, 0)
             self.lablebehind = model.get_value(tree_iter2, 2)
             sl = int(self.path[1]) + 1
             if "freespace" in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition("p")[2])
         elif len(self.path) == 3 and self.path[2] > 0 and self.scheme == "MBR":
             if self.path[1] > 0:
                 pathbehind1 = str(self.path[0]) + ":" + str(int(self.path[1] - 1))
                 tree_iter2 = model.get_iter(pathbehind1)
                 self.slicebehind = model.get_value(tree_iter2, 0)
             else:
                 self.slicebehind = None
             pathbehind2 = str(self.path[0]) + ":" + str(self.path[1]) + ":" + str(int(self.path[2] - 1))
             tree_iter3 = model.get_iter(pathbehind2)
             self.lablebehind = model.get_value(tree_iter3, 2)
             sl = int(self.path[1]) + 1
             if self.slicebehind is None:
                 slbehind = self.path[1]
             elif "freespace" in self.slicebehind:
                 slbehind = self.path[1]
             else:
                 slbehind = int(self.slicebehind.partition("s")[2])
         else:
             self.slicebehind = None
             self.lablebehind = None
             sl = 1
             slbehind = 0
         if "freespace" in self.slice:
             if self.path[1] > 3 and self.scheme == "MBR":
                 self.create_bt.set_sensitive(False)
             elif self.slicebehind == None:
                 self.create_bt.set_sensitive(True)
             elif sl == slbehind:
                 self.create_bt.set_sensitive(False)
             elif slbehind > 4:
                 self.create_bt.set_sensitive(False)
             else:
                 self.create_bt.set_sensitive(True)
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
         elif "s" in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         elif "p" in self.slice:
             self.create_bt.set_sensitive(False)
             self.delete_bt.set_sensitive(True)
             # self.modifi_bt.set_sensitive(True)
             self.auto_bt.set_sensitive(False)
         else:
             self.delete_bt.set_sensitive(False)
             self.modifi_bt.set_sensitive(False)
             self.auto_bt.set_sensitive(True)
             if how_partition(self.path) == 1 and first_is_free(self.path) == "freespace":
                 self.create_bt.set_sensitive(True)
             elif how_partition(self.path) == 0:
                 self.create_bt.set_sensitive(True)
             else:
                 self.create_bt.set_sensitive(False)
     if os.path.exists(Part_label):
         rd = open(Part_label, "r")
         self.partfile = rd.readlines()
         # If Find GPT scheme.
         if os.path.exists(disk_schem):
             rschm = open(disk_schem, "r")
             schm = rschm.readlines()[0]
             if "GPT" in schm:
                 if len(self.partfile) >= 2:
                     if "BOOT" in self.partfile[0] or "BIOS" in self.partfile[0] or "UEFI" in self.partfile[0]:
                         if "/boot\n" in self.partfile[1]:
                             if len(self.partfile) >= 3:
                                 if "/\n" in self.partfile[1]:
                                     self.button3.set_sensitive(True)
                                 else:
                                     self.button3.set_sensitive(False)
                             else:
                                 self.button3.set_sensitive(False)
                         elif "/\n" in self.partfile[1]:
                             self.button3.set_sensitive(True)
                         else:
                             self.button3.set_sensitive(False)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
             else:
                 if len(self.partfile) >= 1:
                     if "/boot\n" in self.partfile[0]:
                         if len(self.partfile) >= 2:
                             if "/\n" in self.partfile[1]:
                                 self.button3.set_sensitive(True)
                             else:
                                 self.button3.set_sensitive(False)
                         else:
                             self.button3.set_sensitive(False)
                     elif "/\n" in self.partfile[0]:
                         self.button3.set_sensitive(True)
                     else:
                         self.button3.set_sensitive(False)
                 else:
                     self.button3.set_sensitive(False)
         else:
             self.button3.set_sensitive(False)
     else:
         self.button3.set_sensitive(False)