updating partition.py and db_partiton from gbi

This commit is contained in:
ericbsd
2019-04-17 22:09:38 -03:00
parent a2e76e5a2b
commit cf27a52874
2 changed files with 185 additions and 133 deletions
+92 -82
View File
@@ -34,34 +34,26 @@ from subprocess import Popen, PIPE, STDOUT, call
import pickle import pickle
from time import sleep from time import sleep
tmp = "/tmp/.gbinstall/" tmp = "/tmp/.gbi/"
if not os.path.exists(tmp): if not os.path.exists(tmp):
os.makedirs(tmp) os.makedirs(tmp)
installer = "/usr/local/lib/gbinstall/" installer = "/usr/local/lib/gbi/"
pc_sysinstall = "/usr/local/sbin/pc-sysinstall" sysinstall = "/usr/local/sbin/pc-sysinstall"
partitiondb = f"{tmp}partitiondb/" partitiondb = "%spartitiondb/" % tmp
diskdb = f"{partitiondb}disk" query = "sh /usr/local/lib/gbi/backend-query/"
query_disk = '%sdisk-list.sh' % query
query = f'{installer}backend-query' detect_sheme = '%sdetect-sheme.sh' % query
diskdb = "%sdisk" % partitiondb
query_disk = f'sh {query}/disk-list.sh' query_partition = '%sdisk-part.sh' % query
detect_sheme = f'sh {query}/detect-sheme.sh' query_label = '%sdisk-label.sh' % query
query_partition = f'sh {query}/disk-part.sh' disk_info = '%sdisk-info.sh' % query
query_label = f'sh {query}/disk-label.sh' nl = "\n"
disk_info = f'sh {query}/disk-info.sh'
# query_disk = f'{pc_sysinstall} disk-list'
# detect_sheme = f'{pc_sysinstall} detect-sheme'
# query_partition = f'{pc_sysinstall} disk-part'
# query_label = f'{pc_sysinstall} disk-label'
# disk_info = f'{pc_sysinstall} disk-info'
memory = 'sysctl hw.physmem' memory = 'sysctl hw.physmem'
disk_file = f'{tmp}disk' disk_file = '%sdisk' % tmp
dslice = f'{tmp}slice' dslice = '%sslice' % tmp
Part_label = f'{tmp}partlabel' Part_label = '%spartlabel' % tmp
part_schem = f'{tmp}scheme' part_schem = '%sscheme' % tmp
boot_file = f'{tmp}boot' boot_file = '%sboot' % tmp
def disk_query(): def disk_query():
@@ -71,13 +63,13 @@ def disk_query():
def zfs_disk_query(): def zfs_disk_query():
disk_output = Popen(pc_sysinstall + " disk-list", shell=True, stdin=PIPE, disk_output = Popen(sysinstall + " disk-list", shell=True, stdin=PIPE,
stdout=PIPE, universal_newlines=True, close_fds=True) stdout=PIPE, universal_newlines=True, close_fds=True)
return disk_output.stdout.readlines() return disk_output.stdout.readlines()
def zfs_disk_size_query(disk): def zfs_disk_size_query(disk):
disk_info_output = Popen(pc_sysinstall + " disk-info " + disk, shell=True, disk_info_output = Popen(sysinstall + " disk-info " + disk, shell=True,
stdin=PIPE, stdout=PIPE, universal_newlines=True, stdin=PIPE, stdout=PIPE, universal_newlines=True,
close_fds=True) close_fds=True)
return disk_info_output.stdout.readlines()[3].partition('=')[2] return disk_info_output.stdout.readlines()[3].partition('=')[2]
@@ -87,7 +79,6 @@ def how_partition(path):
disk = disk_query()[path[0]][0] disk = disk_query()[path[0]][0]
if os.path.exists(partitiondb + disk): if os.path.exists(partitiondb + disk):
part = partition_query(disk) part = partition_query(disk)
print(part)
return len(part) return len(part)
else: else:
return 0 return 0
@@ -202,7 +193,7 @@ class partition_repos():
def disk_list(self): def disk_list(self):
disk_output = Popen(query_disk, shell=True, stdin=PIPE, stdout=PIPE, disk_output = Popen(query_disk, shell=True, stdin=PIPE, stdout=PIPE,
universal_newlines=True, close_fds=True) universal_newlines=True, close_fds=True)
dlist = [] dlist = []
for disk in disk_output.stdout: for disk in disk_output.stdout:
dlist.append(disk.split()) dlist.append(disk.split())
@@ -394,12 +385,16 @@ class Delete_partition():
sl[snum] = ['freespace', free, '', ''] sl[snum] = ['freespace', free, '', '']
else: else:
free = int_size(sl[snum][1]) free = int_size(sl[snum][1])
if sl[snum + 1][0] == 'freespace' and sl[snum - 1][0] == 'freespace': slice_after = sl[snum + 1][0]
free = free + int_size(sl[snum + 1][1]) + int_size(sl[snum - 1][1]) slice_before = sl[snum - 1][0]
size_after = sl[snum + 1]
size_before = sl[snum - 1]
if slice_after == 'freespace' and slice_before == 'freespace':
free = free + int_size(size_after) + int_size(size_before)
sl[snum] = ['freespace', free, '', ''] sl[snum] = ['freespace', free, '', '']
sl.remove(sl[snum + 1]) sl.remove(sl[snum + 1])
sl.remove(sl[snum - 1]) sl.remove(sl[snum - 1])
elif sl[snum + 1][0] == 'freespace': elif slice_after == 'freespace':
free = free + int_size(sl[snum + 1][1]) free = free + int_size(sl[snum + 1][1])
sl[snum] = ['freespace', free, '', ''] sl[snum] = ['freespace', free, '', '']
sl.remove(sl[snum + 1]) sl.remove(sl[snum + 1])
@@ -413,7 +408,7 @@ class Delete_partition():
dl = [] dl = []
mdl = [] mdl = []
data = True data = True
# if delete exist chek if slice is in delete. # if delete exist check if slice is in delete.
if os.path.exists(tmp + 'delete'): if os.path.exists(tmp + 'delete'):
df = open(tmp + 'delete', 'rb') df = open(tmp + 'delete', 'rb')
mdl = pickle.load(df) mdl = pickle.load(df)
@@ -436,8 +431,8 @@ class Delete_partition():
pfile = open(Part_label, 'w') pfile = open(Part_label, 'w')
for partlist in partition_query(drive): for partlist in partition_query(drive):
if partlist[2] != '': if partlist[2] != '':
pfile.writelines('%s %s %s\n' % (partlist[3], partlist[1], partition = f'{partlist[3]} {partlist[1]} {partlist[2]}\n'
partlist[2])) pfile.writelines(partition)
pfile.close() pfile.close()
@@ -511,7 +506,7 @@ class autoDiskPartition():
slice_file.writelines('%s\n' % number) slice_file.writelines('%s\n' % number)
slice_file.close() slice_file.close()
ram = Popen(memory, shell=True, stdin=PIPE, stdout=PIPE, ram = Popen(memory, shell=True, stdin=PIPE, stdout=PIPE,
universal_newlines=True, close_fds=True) universal_newlines=True, close_fds=True)
mem = ram.stdout.read() mem = ram.stdout.read()
swap = int(int(mem.partition(':')[2].strip()) / (1024 * 1024)) swap = int(int(mem.partition(':')[2].strip()) / (1024 * 1024))
if bios_or_uefi() == "UEFI": if bios_or_uefi() == "UEFI":
@@ -523,13 +518,8 @@ class autoDiskPartition():
plist = [] plist = []
mplist = [] mplist = []
plf = open(partitiondb + disk, 'wb') plf = open(partitiondb + disk, 'wb')
read = open(boot_file, 'r')
line = read.readlines()
boot = line[0].strip()
if bios_or_uefi() == "UEFI": if bios_or_uefi() == "UEFI":
plist.extend(([disk + 'p1', bnum, 'none', 'UEFI'])) plist.extend(([disk + 'p1', bnum, 'none', 'UEFI']))
elif boot == "grub":
plist.extend(([disk + 'p1', bnum, 'none', 'BIOS']))
else: else:
plist.extend(([disk + 'p1', bnum, 'none', 'BOOT'])) plist.extend(([disk + 'p1', bnum, 'none', 'BOOT']))
mplist.append(plist) mplist.append(plist)
@@ -544,8 +534,6 @@ class autoDiskPartition():
pfile = open(Part_label, 'w') pfile = open(Part_label, 'w')
if bios_or_uefi() == "UEFI": if bios_or_uefi() == "UEFI":
pfile.writelines('UEFI %s none\n' % bnum) pfile.writelines('UEFI %s none\n' % bnum)
elif boot == "grub":
pfile.writelines('BIOS %s none\n' % bnum)
else: else:
pfile.writelines('BOOT %s none\n' % bnum) pfile.writelines('BOOT %s none\n' % bnum)
pfile.writelines('UFS+SUJ %s /\n' % rnum) pfile.writelines('UFS+SUJ %s /\n' % rnum)
@@ -623,10 +611,6 @@ class autoFreeSpace():
sfile.close() sfile.close()
number = int(size.partition('M')[0]) number = int(size.partition('M')[0])
number = number - 512 number = number - 512
slice_file = open(dslice, 'w')
slice_file.writelines('p%s\n' % sl)
slice_file.writelines('%s\n' % number)
slice_file.close()
ram = Popen(memory, shell=True, stdin=PIPE, stdout=PIPE, ram = Popen(memory, shell=True, stdin=PIPE, stdout=PIPE,
universal_newlines=True, close_fds=True) universal_newlines=True, close_fds=True)
mem = ram.stdout.read() mem = ram.stdout.read()
@@ -640,29 +624,38 @@ class autoFreeSpace():
plist = [] plist = []
mplist = partition_query(disk) mplist = partition_query(disk)
plf = open(partitiondb + disk, 'wb') plf = open(partitiondb + disk, 'wb')
read = open(boot_file, 'r') done = False
line = read.readlines() if bios_or_uefi() == "UEFI" and efi_exist(disk) is False:
boot = line[0].strip()
if bios_or_uefi() == "UEFI":
plist.extend(([disk + 'p%s' % sl, bs, 'none', 'UEFI'])) plist.extend(([disk + 'p%s' % sl, bs, 'none', 'UEFI']))
elif boot == "grub": rsl = int(sl + 1)
plist.extend(([disk + 'p%s' % sl, bs, 'none', 'BIOS'])) swsl = int(rsl + 1)
elif bios_or_uefi() == "UEFI" and efi_exist(disk) is True:
rsl = int(sl)
swsl = int(rsl + 1)
else: else:
plist.extend(([disk + 'p%s' % sl, bs, 'none', 'BOOT'])) plist.extend(([disk + 'p%s' % sl, bs, 'none', 'BOOT']))
mplist[path] = plist rsl = int(sl + 1)
swsl = (rsl + 1)
if len(plist) != 0:
done = True
mplist[path] = plist
plist = []
plist.extend(([disk + 'p%s' % rsl, rootNum, '/', 'UFS+SUJ']))
if done is False:
mplist[path] = plist
else:
mplist.append(plist)
plist = [] plist = []
plist.extend(([disk + 'p%s' % int(sl + 1), rootNum, '/', 'UFS+SUJ'])) plist.extend(([disk + 'p%s' % swsl, swap, 'none', 'SWAP']))
mplist.append(plist)
plist = []
plist.extend(([disk + 'p%s' % int(sl + 2), swap, 'none', 'SWAP']))
mplist.append(plist) mplist.append(plist)
pickle.dump(mplist, plf) pickle.dump(mplist, plf)
plf.close() plf.close()
slice_file = open(dslice, 'w')
slice_file.writelines(f'p{rsl}')
slice_file.close()
pfile = open(Part_label, 'w') pfile = open(Part_label, 'w')
if bios_or_uefi() == "UEFI": if bios_or_uefi() == "UEFI" and efi_exist(disk) is False:
pfile.writelines('UEFI %s none\n' % bs) pfile.writelines('UEFI %s none\n' % bs)
elif boot == "grub":
pfile.writelines('BIOS %s none\n' % bs)
else: else:
pfile.writelines('BOOT %s none\n' % bs) pfile.writelines('BOOT %s none\n' % bs)
pfile.writelines('UFS+SUJ %s /\n' % rootNum) pfile.writelines('UFS+SUJ %s /\n' % rootNum)
@@ -670,17 +663,20 @@ class autoFreeSpace():
pfile.close() pfile.close()
pl = [] pl = []
mpl = [] mpl = []
if not os.path.exists(tmp + 'create'): if bios_or_uefi() == "UEFI" and efi_exist(disk) is True:
pl.extend(([disk + "p%s" % sl, size])) pass
mpl.append(pl) else:
cf = open(tmp + 'create', 'wb') if not os.path.exists(tmp + 'create'):
pickle.dump(mpl, cf) pl.extend(([disk + "p%s" % sl, size]))
cf.close() mpl.append(pl)
cf = open(tmp + 'create', 'wb')
pickle.dump(mpl, cf)
cf.close()
class createLabel(): class createLabel():
def __init__(self, path, lnumb, cnumb, lb, fs, data): def __init__(self, path, lnumb, cnumb, label, fs, data):
disk = disk_query()[path[0]][0] disk = disk_query()[path[0]][0]
if not os.path.exists(disk_file): if not os.path.exists(disk_file):
file_disk = open(disk_file, 'w') file_disk = open(disk_file, 'w')
@@ -702,7 +698,7 @@ class createLabel():
plf = open(partitiondb + disk + 's%s' % sl, 'wb') plf = open(partitiondb + disk + 's%s' % sl, 'wb')
if lnumb == 0: if lnumb == 0:
cnumb -= 1 cnumb -= 1
llist.extend(([disk + 's%s' % sl + letter, cnumb, lb, fs])) llist.extend(([disk + 's%s' % sl + letter, cnumb, label, fs]))
mllist[lv] = llist mllist[lv] = llist
llist = [] llist = []
if lnumb > 0: if lnumb > 0:
@@ -722,7 +718,7 @@ class createLabel():
class modifyLabel(): class modifyLabel():
def __init__(self, path, lnumb, cnumb, lb, fs, data): def __init__(self, path, lnumb, cnumb, label, fs, data):
disk = disk_query()[path[0]][0] disk = disk_query()[path[0]][0]
if not os.path.exists(disk_file): if not os.path.exists(disk_file):
file_disk = open(disk_file, 'w') file_disk = open(disk_file, 'w')
@@ -744,7 +740,7 @@ class modifyLabel():
plf = open(partitiondb + disk + 's%s' % sl, 'wb') plf = open(partitiondb + disk + 's%s' % sl, 'wb')
if lnumb == 0: if lnumb == 0:
cnumb -= 1 cnumb -= 1
llist.extend(([disk + 's%s' % sl + letter, cnumb, lb, fs])) llist.extend(([disk + 's%s' % sl + letter, cnumb, label, fs]))
mllist[lv] = llist mllist[lv] = llist
llist = [] llist = []
if lnumb > 0: if lnumb > 0:
@@ -813,7 +809,7 @@ class createSlice():
class createPartition(): class createPartition():
def __init__(self, path, lnumb, inumb, cnumb, lb, fs, data): def __init__(self, path, lnumb, inumb, cnumb, label, fs, create):
disk = disk_query()[path[0]][0] disk = disk_query()[path[0]][0]
if not os.path.exists(disk_file): if not os.path.exists(disk_file):
file_disk = open(disk_file, 'w') file_disk = open(disk_file, 'w')
@@ -829,7 +825,7 @@ class createPartition():
sfile = open(part_schem, 'w') sfile = open(part_schem, 'w')
sfile.writelines('partscheme=GPT') sfile.writelines('partscheme=GPT')
sfile.close() sfile.close()
if not os.path.exists(dslice): if label == '/':
slice_file = open(dslice, 'w') slice_file = open(dslice, 'w')
slice_file.writelines('p%s\n' % pl) slice_file.writelines('p%s\n' % pl)
# slice_file.writelines('%s\n' % number) # slice_file.writelines('%s\n' % number)
@@ -840,7 +836,7 @@ class createPartition():
if lnumb == 0 and cnumb > 1: if lnumb == 0 and cnumb > 1:
cnumb -= 1 cnumb -= 1
pf = open(partitiondb + disk, 'wb') pf = open(partitiondb + disk, 'wb')
plist.extend(([disk + 'p%s' % pl, cnumb, lb, fs])) plist.extend(([disk + 'p%s' % pl, cnumb, label, fs]))
mplist[lv] = plist mplist[lv] = plist
plist = [] plist = []
if lnumb > 0: if lnumb > 0:
@@ -854,7 +850,7 @@ class createPartition():
pfile.writelines('%s %s %s\n' % (partlist[3], partlist[1], pfile.writelines('%s %s %s\n' % (partlist[3], partlist[1],
partlist[2])) partlist[2]))
pfile.close() pfile.close()
if data is True: if create is True:
plst = [] plst = []
mplst = [] mplst = []
if not os.path.exists(tmp + 'create'): if not os.path.exists(tmp + 'create'):
@@ -867,7 +863,7 @@ class createPartition():
class modifyPartition(): class modifyPartition():
def __init__(self, path, lnumb, inumb, cnumb, lb, fs, data): def __init__(self, path, lnumb, inumb, cnumb, label, fs, data):
disk = disk_query()[path[0]][0] disk = disk_query()[path[0]][0]
if not os.path.exists(disk_file): if not os.path.exists(disk_file):
file_disk = open(disk_file, 'w') file_disk = open(disk_file, 'w')
@@ -883,10 +879,9 @@ class modifyPartition():
sfile = open(part_schem, 'w') sfile = open(part_schem, 'w')
sfile.writelines('partscheme=GPT') sfile.writelines('partscheme=GPT')
sfile.close() sfile.close()
if not os.path.exists(dslice): if label == '/':
slice_file = open(dslice, 'w') slice_file = open(dslice, 'w')
slice_file.writelines('p%s\n' % pl) slice_file.writelines('p%s\n' % pl)
# slice_file.writelines('%s\n' % number)
slice_file.close() slice_file.close()
plist = [] plist = []
pslice = '%sp%s' % (disk, pl) pslice = '%sp%s' % (disk, pl)
@@ -894,7 +889,7 @@ class modifyPartition():
if lnumb == 0: if lnumb == 0:
cnumb -= 1 cnumb -= 1
pf = open(partitiondb + disk, 'wb') pf = open(partitiondb + disk, 'wb')
plist.extend(([disk + 'p%s' % pl, cnumb, lb, fs])) plist.extend(([disk + 'p%s' % pl, cnumb, label, fs]))
mplist[lv] = plist mplist[lv] = plist
plist = [] plist = []
if lnumb > 0: if lnumb > 0:
@@ -976,7 +971,19 @@ def bios_or_uefi():
return "BIOS" return "BIOS"
def efi_exist(disk):
cmd = f"gpart show {disk} | grep efi"
process = Popen(cmd, shell=True, stdout=PIPE,
universal_newlines=True, close_fds=True)
output = process.stdout.readlines()
if len(output) == 0:
return False
else:
return True
class makingParttion(): class makingParttion():
def __init__(self): def __init__(self):
if os.path.exists(tmp + 'create'): if os.path.exists(tmp + 'create'):
pf = open(tmp + 'create', 'rb') pf = open(tmp + 'create', 'rb')
@@ -997,13 +1004,16 @@ class makingParttion():
call(cmd2, shell=True) call(cmd2, shell=True)
else: else:
if boot == "grub": if boot == "grub":
cmd = 'gpart add -a 4k -s 1M -t bios-boot -i %s %s' % (sl, drive) cmd = 'gpart add -a 4k -s 1M -t bios-boot -i' \
f' {sl} {drive}'
else: else:
cmd = 'gpart add -a 4k -s 512 -t freebsd-boot -i %s %s' % (sl, drive) cmd = 'gpart add -a 4k -s 512 -t freebsd-boot -i' \
f' {sl} {drive}'
call(cmd, shell=True) call(cmd, shell=True)
elif slicePartition(part) == 's': elif slicePartition(part) == 's':
size = int(line[1]) size = int(line[1])
block = int(size * 2048) block = int(size * 2048)
cmd = 'gpart add -a 4k -s %s -t freebsd -i %s %s' % (block, sl, drive) cmd = f'gpart add -a 4k -s {block} -t freebsd -i {sl} ' \
f'{drive}'
call(cmd, shell=True) call(cmd, shell=True)
sleep(2) sleep(2)
+93 -51
View File
@@ -41,6 +41,8 @@ from db_partition import partition_query, label_query, bios_or_uefi
from db_partition import autoDiskPartition, autoFreeSpace, first_is_free from db_partition import autoDiskPartition, autoFreeSpace, first_is_free
from db_partition import createLabel, scheme_query, how_partition from db_partition import createLabel, scheme_query, how_partition
from db_partition import diskSchemeChanger, createSlice, createPartition from db_partition import diskSchemeChanger, createSlice, createPartition
from partition_handler import efi_exist
# Folder use pr the installer. # Folder use pr the installer.
tmp = "/tmp/.gbinstall/" tmp = "/tmp/.gbinstall/"
@@ -93,7 +95,7 @@ class Partitions():
def save_selection(self): def save_selection(self):
pass pass
def on_add_label(self, widget, entry, inumb, path, data): def on_add_label(self, widget, entry, inumb, path, create):
if self.fs == '' or self.label == '': if self.fs == '' or self.label == '':
pass pass
else: else:
@@ -101,11 +103,11 @@ class Partitions():
lb = self.label lb = self.label
cnumb = entry.get_value_as_int() cnumb = entry.get_value_as_int()
lnumb = inumb - cnumb lnumb = inumb - cnumb
createLabel(path, lnumb, cnumb, lb, fs, data) createLabel(path, lnumb, cnumb, lb, fs, create)
self.window.hide() self.window.hide()
self.update() self.update()
def on_add_partition(self, widget, entry, inumb, path, data): def on_add_partition(self, widget, entry, inumb, path, create):
if self.fs == '' or self.label == '': if self.fs == '' or self.label == '':
pass pass
else: else:
@@ -113,14 +115,14 @@ class Partitions():
lb = self.label lb = self.label
cnumb = entry.get_value_as_int() cnumb = entry.get_value_as_int()
lnumb = inumb - cnumb lnumb = inumb - cnumb
createPartition(path, lnumb, inumb, cnumb, lb, fs, data) createPartition(path, lnumb, inumb, cnumb, lb, fs, create)
self.window.hide() self.window.hide()
self.update() self.update()
def cancel(self, widget): def cancel(self, widget):
self.window.hide() self.window.hide()
def labelEditor(self, path, pslice, size, data1, modify): def labelEditor(self, path, pslice, size, scheme, modify):
numb = int(size) numb = int(size)
self.window = Gtk.Window() self.window = Gtk.Window()
self.window.set_title("Add Partition") self.window.set_title("Add Partition")
@@ -146,23 +148,23 @@ class Partitions():
self.fstype.append_text('UFS+J') self.fstype.append_text('UFS+J')
self.fstype.append_text('UFS+SUJ') self.fstype.append_text('UFS+SUJ')
self.fstype.append_text('SWAP') self.fstype.append_text('SWAP')
if data1 == 1: if scheme == 'GPT':
read = open(boot_file, 'r')
line = read.readlines()
boot = line[0].strip()
if bios_or_uefi() == "UEFI": if bios_or_uefi() == "UEFI":
self.fstype.append_text("UEFI") self.fstype.append_text("UEFI")
self.fs = "UEFI" self.fs = "UEFI"
elif boot == "grub":
self.fstype.append_text("BIOS")
self.fs = "BIOS"
else: else:
self.fstype.append_text("BOOT") self.fstype.append_text("BOOT")
self.fs = "BOOT" self.fs = "BOOT"
if data1 == 1 and not os.path.exists(Part_label): if self.fs == "UEFI" and efi_exist(self.disk) is False:
self.fstype.set_active(5) if not os.path.exists(Part_label):
elif data1 == 1 and len(self.partfile) == 0: self.fstype.set_active(5)
self.fstype.set_active(5) elif len(self.prttn) == 0:
self.fstype.set_active(5)
elif self.fs == "BOOT":
if not os.path.exists(Part_label):
self.fstype.set_active(5)
elif len(self.prttn) == 0:
self.fstype.set_active(5)
elif self.lablebehind == "/": elif self.lablebehind == "/":
self.fstype.set_active(4) self.fstype.set_active(4)
self.fs = "SWAP" self.fs = "SWAP"
@@ -183,11 +185,11 @@ class Partitions():
# The space for root '/ ' is to recognise / from the file. # The space for root '/ ' is to recognise / from the file.
self.mountpoint.append_text('/') self.mountpoint.append_text('/')
if os.path.exists(Part_label): if os.path.exists(Part_label):
if data1 == 1 and len(self.partfile) == 1: if scheme == 'GPT' and len(self.prttn) == 1:
self.mountpoint.append_text('/boot') self.mountpoint.append_text('/boot')
elif data1 == 0 and len(self.partfile) == 0: elif scheme == 'MBR' and len(self.prttn) == 0:
self.mountpoint.append_text('/boot') self.mountpoint.append_text('/boot')
elif data1 == 0 and not os.path.exists(Part_label): elif scheme == 'MBR' and not os.path.exists(Part_label):
self.mountpoint.append_text('/boot') self.mountpoint.append_text('/boot')
self.mountpoint.append_text('/etc') self.mountpoint.append_text('/etc')
self.mountpoint.append_text('/root') self.mountpoint.append_text('/root')
@@ -218,17 +220,23 @@ class Partitions():
bbox.add(button) bbox.add(button)
button = Gtk.Button(stock=Gtk.STOCK_ADD) button = Gtk.Button(stock=Gtk.STOCK_ADD)
if modify is False: if modify is False:
if data1 == 0: if scheme == 'MBR':
button.connect("clicked", self.on_add_label, self.entry, button.connect("clicked", self.on_add_label, self.entry,
numb, path, True) numb, path, True)
elif data1 == 1: elif scheme == 'GPT' and self.fs == 'BOOT':
button.connect("clicked", self.on_add_partition, self.entry, button.connect("clicked", self.on_add_partition, self.entry,
numb, path, True) numb, path, True)
elif scheme == 'GPT' and self.fs == 'UEFI' and efi_exist(self.disk) is False:
button.connect("clicked", self.on_add_partition, self.entry,
numb, path, True)
else:
button.connect("clicked", self.on_add_partition, self.entry,
numb, path, False)
else: else:
if data1 == 0: if scheme == 'MBR':
button.connect("clicked", self.on_add_label, self.entry, numb, button.connect("clicked", self.on_add_label, self.entry, numb,
path, False) path, False)
elif data1 == 1: elif scheme == 'GPT':
button.connect("clicked", self.on_add_partition, self.entry, button.connect("clicked", self.on_add_partition, self.entry,
numb, path, False) numb, path, False)
bbox.add(button) bbox.add(button)
@@ -250,7 +258,7 @@ class Partitions():
if scheme_query(self.path) == "MBR" and self.path[1] < 4: if scheme_query(self.path) == "MBR" and self.path[1] < 4:
self.sliceEditor() self.sliceEditor()
elif scheme_query(self.path) == "GPT": elif scheme_query(self.path) == "GPT":
self.labelEditor(self.path, self.slice, self.size, 1, False) self.labelEditor(self.path, self.slice, self.size, 'GPT', False)
def autoSchemePartition(self, widget): def autoSchemePartition(self, widget):
diskSchemeChanger(self.scheme, self.path, self.slice, self.size) diskSchemeChanger(self.scheme, self.path, self.slice, self.size)
@@ -390,10 +398,10 @@ class Partitions():
def modify_partition(self, widget): def modify_partition(self, widget):
if len(self.path) == 3: if len(self.path) == 3:
if self.slice != 'freespace': if self.slice != 'freespace':
self.labelEditor(self.path, self.slice, self.size, 0, True) self.labelEditor(self.path, self.slice, self.size, 'MBR', True)
elif len(self.path) == 2 and self.slice != 'freespace': elif len(self.path) == 2 and self.slice != 'freespace':
if scheme_query(self.path) == "GPT": if scheme_query(self.path) == "GPT":
self.labelEditor(self.path, self.slice, self.size, 1, True) self.labelEditor(self.path, self.slice, self.size, 'GPT', True)
def autoPartition(self, widget): def autoPartition(self, widget):
if len(self.path) == 3: if len(self.path) == 3:
@@ -433,21 +441,17 @@ class Partitions():
self.treeview.expand_all() self.treeview.expand_all()
def create_partition(self, widget): def create_partition(self, widget):
print(len(self.path))
print(self.path)
print(how_partition(self.path))
if len(self.path) == 2 and how_partition(self.path) == 1 and self.slice == 'freespace': if len(self.path) == 2 and how_partition(self.path) == 1 and self.slice == 'freespace':
self.schemeEditor(False) self.schemeEditor(False)
elif len(self.path) == 3: elif len(self.path) == 3:
if self.slice == 'freespace': if self.slice == 'freespace':
self.labelEditor(self.path, self.slice, self.size, 0, False) self.labelEditor(self.path, self.slice, self.size, 'MBR', False)
elif len(self.path) == 2 and self.slice == 'freespace': elif len(self.path) == 2 and self.slice == 'freespace':
if scheme_query(self.path) == "MBR" and self.path[1] < 4: if scheme_query(self.path) == "MBR" and self.path[1] < 4:
self.sliceEditor() self.sliceEditor()
elif scheme_query(self.path) == "GPT": elif scheme_query(self.path) == "GPT":
self.labelEditor(self.path, self.slice, self.size, 1, False) self.labelEditor(self.path, self.slice, self.size, 'GPT', False)
else: else:
print('scheme')
if how_partition(self.path) == 1: if how_partition(self.path) == 1:
self.schemeEditor(True) self.schemeEditor(True)
elif how_partition(self.path) == 0: elif how_partition(self.path) == 0:
@@ -461,6 +465,7 @@ class Partitions():
self.path = model.get_path(self.iter) self.path = model.get_path(self.iter)
tree_iter3 = model.get_iter(self.path[0]) tree_iter3 = model.get_iter(self.path[0])
self.scheme = model.get_value(tree_iter3, 3) self.scheme = model.get_value(tree_iter3, 3)
self.disk = model.get_value(tree_iter3, 0)
tree_iter = model.get_iter(self.path) tree_iter = model.get_iter(self.path)
self.slice = model.get_value(tree_iter, 0) self.slice = model.get_value(tree_iter, 0)
self.size = model.get_value(tree_iter, 1) self.size = model.get_value(tree_iter, 1)
@@ -533,7 +538,9 @@ class Partitions():
self.delete_bt.set_sensitive(False) self.delete_bt.set_sensitive(False)
self.modifi_bt.set_sensitive(False) self.modifi_bt.set_sensitive(False)
self.auto_bt.set_sensitive(False) self.auto_bt.set_sensitive(False)
if how_partition(self.path) == 1 and first_is_free(self.path) == 'freespace': 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) self.create_bt.set_sensitive(False)
elif how_partition(self.path) == 0: elif how_partition(self.path) == 0:
self.create_bt.set_sensitive(True) self.create_bt.set_sensitive(True)
@@ -541,41 +548,76 @@ class Partitions():
self.create_bt.set_sensitive(False) self.create_bt.set_sensitive(False)
if os.path.exists(Part_label): if os.path.exists(Part_label):
rd = open(Part_label, 'r') rd = open(Part_label, 'r')
self.partfile = rd.readlines() self.prttn = rd.readlines()
rtbt = False
for line in self.prttn:
if "/boot\n" in line:
rtbt = True
break
# If Find GPT scheme. # If Find GPT scheme.
if os.path.exists(disk_schem): if os.path.exists(disk_schem):
rschm = open(disk_schem, 'r') rschm = open(disk_schem, 'r')
schm = rschm.readlines()[0] schm = rschm.readlines()[0]
efi = efi_exist(self.disk)
if 'GPT' in schm: if 'GPT' in schm:
if len(self.partfile) >= 2: if len(self.prttn) >= 2:
if 'BOOT' in self.partfile[0] or 'BIOS' in self.partfile[0] or 'UEFI' in self.partfile[0]: if 'BOOT' in self.prttn[0]:
if "/boot\n" in self.partfile[1]: if rtbt is True and "/boot\n" not in self.prttn[1]:
if len(self.partfile) >= 3: self.button3.set_sensitive(False)
if '/\n' in self.partfile[1]: elif "/boot\n" in self.prttn[1]:
if len(self.prttn) >= 3:
if '/\n' in self.prttn[2]:
self.button3.set_sensitive(True) self.button3.set_sensitive(True)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
elif '/\n' in self.partfile[1]: elif '/\n' in self.prttn[1]:
self.button3.set_sensitive(True) self.button3.set_sensitive(True)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
else: 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) self.button3.set_sensitive(False)
else: elif "/boot\n" in self.prttn[0] and efi is True:
self.button3.set_sensitive(False) if len(self.prttn) >= 2:
else: if '/\n' in self.prttn[1]:
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) self.button3.set_sensitive(True)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
elif '/\n' in self.partfile[0]: 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) self.button3.set_sensitive(True)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
@@ -584,7 +626,7 @@ class Partitions():
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
else: else:
self.button3.set_sensitive(False) self.button3.set_sensitive(False)
def __init__(self, button3): def __init__(self, button3):
self.button3 = button3 self.button3 = button3
@@ -687,4 +729,4 @@ class Partitions():
def get_model(self): def get_model(self):
self.tree_selection.select_path(0) self.tree_selection.select_path(0)
return self.vbox1 return self.box1