Modify partition-tools:
chage the base unit from 'B' to 's'
correct 4k align
Modify network configure:
provide a default network configure
Todo:
support making raid
modified: dialog/di_main.py
modified: dialog/di_newt.py
modified: interface/ri_data.py
modified: interface/ri_oper.py
modified: new_partition/interface_partition.py
modified: new_partition/partition_data.py
modified: operation/partition_disks.sh
This commit is contained in:
@@ -15,23 +15,17 @@ count=0
|
||||
while True :
|
||||
if count == 1:
|
||||
if init_partition_from_os_flag:
|
||||
partition_data.Partition.init_from_os()
|
||||
partition_data.Partition.init_from_os(unit='s')
|
||||
init_partition_from_os_flag = False
|
||||
#s = os.system("python ../new_partition/interface_partition.py")
|
||||
s = interface_partition.main()
|
||||
|
||||
if init_flag:
|
||||
ri_data.init()
|
||||
init_flag = False
|
||||
#print 'debug'
|
||||
#print len(di_newt.Raid.init_from_internal())
|
||||
#time.sleep(10)
|
||||
if len(di_newt.Raid.init_from_internal()) < 2:
|
||||
if list[2] == 'raid':
|
||||
del list[2]
|
||||
else:
|
||||
#print 'debug'
|
||||
#time.sleep(10)
|
||||
if list[2] != 'raid':
|
||||
list.insert(2, 'raid')
|
||||
else:
|
||||
|
||||
@@ -113,42 +113,48 @@ class Screen:
|
||||
|
||||
@staticmethod
|
||||
def initial_static_net():
|
||||
Screen.label_hostname = Label(' hostname: ')
|
||||
Screen.label_hostname = Label(' hostname: ')
|
||||
Screen.entry_hostname = Entry(20, getattr(ri_data.Network, 'hostname'))
|
||||
Screen.grid_hostname = Grid(2,1)
|
||||
Screen.grid_hostname.setField(Screen.label_hostname, 0, 0)
|
||||
Screen.grid_hostname.setField(Screen.entry_hostname, 1, 0)
|
||||
|
||||
Screen.label_domain = Label(' domain: ')
|
||||
Screen.label_domain = Label(' domain: ')
|
||||
Screen.entry_domain = Entry(20, getattr(ri_data.Network, 'domain'))
|
||||
Screen.grid_domain = Grid(2,1)
|
||||
Screen.grid_domain.setField(Screen.label_domain, 0, 0)
|
||||
Screen.grid_domain.setField(Screen.entry_domain, 1, 0)
|
||||
|
||||
Screen.label_ip = Label(' ip: ')
|
||||
Screen.label_ip = Label(' ip: ')
|
||||
Screen.entry_ip = Entry(20, getattr(ri_data.Network, 'ip'))
|
||||
Screen.grid_ip = Grid(2,1)
|
||||
Screen.grid_ip.setField(Screen.label_ip, 0, 0)
|
||||
Screen.grid_ip.setField(Screen.entry_ip, 1, 0)
|
||||
|
||||
Screen.label_netmask = Label(' netmask: ')
|
||||
Screen.label_netmask = Label(' netmask: ')
|
||||
Screen.entry_netmask = Entry(20, getattr(ri_data.Network, 'mask'))
|
||||
Screen.grid_netmask = Grid(2,1)
|
||||
Screen.grid_netmask.setField(Screen.label_netmask, 0, 0)
|
||||
Screen.grid_netmask.setField(Screen.entry_netmask, 1, 0)
|
||||
|
||||
Screen.label_gateway = Label(' gateway: ')
|
||||
Screen.label_gateway = Label(' gateway: ')
|
||||
Screen.entry_gateway = Entry(20, getattr(ri_data.Network, 'gateway'))
|
||||
Screen.grid_gateway = Grid(2,1)
|
||||
Screen.grid_gateway.setField(Screen.label_gateway, 0, 0)
|
||||
Screen.grid_gateway.setField(Screen.entry_gateway, 1, 0)
|
||||
|
||||
Screen.label_primary_dns = Label('primary_dns: ')
|
||||
Screen.label_primary_dns = Label(' primary_dns: ')
|
||||
Screen.entry_primary_dns = Entry(20, getattr(ri_data.Network, 'primary_dns'))
|
||||
Screen.grid_primary_dns = Grid(2,1)
|
||||
Screen.grid_primary_dns.setField(Screen.label_primary_dns, 0, 0)
|
||||
Screen.grid_primary_dns.setField(Screen.entry_primary_dns, 1, 0)
|
||||
|
||||
Screen.label_secondary_dns = Label('secondary_dns: ')
|
||||
Screen.entry_secondary_dns = Entry(20, getattr(ri_data.Network, 'secondary_dns'))
|
||||
Screen.grid_secondary_dns = Grid(2,1)
|
||||
Screen.grid_secondary_dns.setField(Screen.label_secondary_dns, 0, 0)
|
||||
Screen.grid_secondary_dns.setField(Screen.entry_secondary_dns, 1, 0)
|
||||
|
||||
@staticmethod
|
||||
def yesno(gridtitle, gridx, gridy, *widget):
|
||||
Screen.form = Form()
|
||||
@@ -502,7 +508,7 @@ class MountPoint(Screen):
|
||||
elif flag == 'all':
|
||||
list_mountpoint = []
|
||||
for d in self.disks:
|
||||
if p_d.Partition.dict[d]['partition_table'] == ' ':
|
||||
if p_d.Partition.dict[d]['partition_table'] == '':
|
||||
continue
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, d, 'partition'):
|
||||
if p_d.Partition.dict[d]['partition'][p]['mount_point'] != '':
|
||||
@@ -559,7 +565,7 @@ class MountPoint(Screen):
|
||||
list_col_label_align = [CENTER, CENTER, CENTER, CENTER, CENTER]
|
||||
Screen.widget_clistbox(list_col_widths, list_col_labels, list_col_label_align, h=5)
|
||||
for d in self.disks:
|
||||
if p_d.Partition.dict[d]['partition_table'] == ' ':
|
||||
if p_d.Partition.dict[d]['partition_table'] == '':
|
||||
continue
|
||||
partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition')
|
||||
for p in partitions:
|
||||
@@ -568,7 +574,8 @@ class MountPoint(Screen):
|
||||
if p == k:
|
||||
if p_d.Partition.dict[d]['partition'][p]['type'] == 'extended':
|
||||
continue
|
||||
size_pretty = interface_partition.pretty_unit(filter(str.isdigit, str(p_d.Partition.dict[d]['partition'][p]['size'])))
|
||||
#size_pretty = interface_partition.pretty_unit(filter(str.isdigit, str(p_d.Partition.dict[d]['partition'][p]['size'])))
|
||||
size_pretty = interface_partition.pretty_unit(interface_partition.get_num(p_d.Partition.dict[d]['partition'][p]['size']))
|
||||
Screen.clistbox.append(["%s" %(p),
|
||||
"%s" %(p_d.Partition.dict[d]['partition'][p]['mount_point'].ljust(10)),
|
||||
"%s" %(p_d.Partition.dict[d]['partition'][p]['filesystem'].ljust(10)),
|
||||
@@ -625,8 +632,8 @@ class Network(Screen):
|
||||
Screen.widget_buttonbar(Screen.buttonlist2)
|
||||
Screen.widget_textboxreflowed(50, 'Please configure the static net:')
|
||||
Screen.initial_static_net()
|
||||
Screen.container_grid(6, 1, Screen.grid_hostname, Screen.grid_domain, Screen.grid_ip,\
|
||||
Screen.grid_netmask, Screen.grid_gateway, Screen.grid_primary_dns)
|
||||
Screen.container_grid(7, 1, Screen.grid_hostname, Screen.grid_domain, Screen.grid_ip,\
|
||||
Screen.grid_netmask, Screen.grid_gateway, Screen.grid_primary_dns, Screen.grid_secondary_dns)
|
||||
|
||||
while True:
|
||||
s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Grid', 'eLabel', 'ButtonBar')
|
||||
@@ -642,6 +649,7 @@ class Network(Screen):
|
||||
setattr(ri_data.Network, 'mask', Screen.entry_netmask.value())
|
||||
setattr(ri_data.Network, 'gateway', Screen.entry_gateway.value())
|
||||
setattr(ri_data.Network, 'primary_dns', Screen.entry_primary_dns.value())
|
||||
setattr(ri_data.Network, 'secondary_dns', Screen.entry_secondary_dns.value())
|
||||
break
|
||||
else:
|
||||
Screen.pop_window('Tips', 'There is something wrong with your input network address.', 30)
|
||||
@@ -659,11 +667,11 @@ class Network(Screen):
|
||||
s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'Grid', 'eLabel', 'ButtonBar')
|
||||
|
||||
if s == 0 and self.rb_static.selected():
|
||||
ri_data.Network.configuration == 'static'
|
||||
ri_data.Network.configuration = 'static'
|
||||
s = self.set_network('static')
|
||||
|
||||
elif s == 0 and self.rb_dynamic.selected():
|
||||
ri_data.Network.configuration == 'dynamic'
|
||||
ri_data.Network.configuration = 'dynamic'
|
||||
s = self.set_network('dynamic')
|
||||
|
||||
return s
|
||||
|
||||
@@ -441,11 +441,11 @@ class Network:
|
||||
''' network '''
|
||||
hostname ='localhost'
|
||||
configuration =''
|
||||
domain = ''
|
||||
ip = ''
|
||||
mask = ''
|
||||
gateway = ''
|
||||
primary_dns = ''
|
||||
domain = 'in.linx'
|
||||
ip = '192.168.0.1'
|
||||
mask = '255.255.255.0'
|
||||
gateway = '192.168.0.254'
|
||||
primary_dns = '192.168.0.254'
|
||||
secondary_dns = ''
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -126,6 +126,8 @@ class MakePartitions(Operation):
|
||||
disks = p_d.Partition.dict.keys()
|
||||
disks.sort()
|
||||
for d in disks:
|
||||
if p_d.Partition.dict[d]['partition_table'] == '':
|
||||
continue
|
||||
if p_d.Partition.dict[d]['from_os'] == 'no':
|
||||
args += '%s mklabel %s\n' %(d, p_d.Partition.dict[d]['partition_table'])
|
||||
partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition')
|
||||
@@ -139,12 +141,6 @@ class MakePartitions(Operation):
|
||||
#fs_type = p_d.Partition.dict[d]['partition'][p]['filesystem']
|
||||
end = p_d.Partition.dict[d]['partition'][p]['end']
|
||||
start = p_d.Partition.dict[d]['partition'][p]['start']
|
||||
start = str(int(filter(str.isdigit,p_d.Partition.dict[d]['partition'][p]['start'])) + 511)+'B'
|
||||
#support 4k align
|
||||
if int(filter(str.isdigit,start)) < 2*1000*1000:
|
||||
start = '1048576B'
|
||||
if int(filter(str.isdigit,end)) < 2*1000*1000:
|
||||
end = '2000000'
|
||||
p_type = p_d.Partition.dict[d]['partition'][p]['type']
|
||||
partition = p_d.Partition.dict[d]['partition'][p]['num']
|
||||
flags = p_d.Partition.dict[d]['partition'][p]['flags']
|
||||
|
||||
@@ -5,73 +5,122 @@ import gettext, sys, os, re, string, time
|
||||
import partition_data as p_d
|
||||
|
||||
global base_unit
|
||||
base_unit = 'B'
|
||||
base_unit = 's'
|
||||
|
||||
# the origin unit is 's'
|
||||
#def pretty_unit(num):
|
||||
# if num*0.5*1.024 < 10*1000:
|
||||
# # < 10M unit is kB
|
||||
# num_pretty = num*0.5*1.024
|
||||
# unit = 'kB'
|
||||
# elif num*0.5*1.024 < 10*1000*1000:
|
||||
# # < 10G unit is MB
|
||||
# num_pretty = num*0.5*1.024/1000
|
||||
# unit = 'MB'
|
||||
# elif num*0.5*1.024 < 10000000000:
|
||||
# # < 10T unit is GB
|
||||
# num_pretty = num*0.5*1.024/1000/1000
|
||||
# unit = 'GB'
|
||||
# return str("%.0f" %num_pretty) + unit
|
||||
#
|
||||
#def unit_to_s(num):
|
||||
# if re.search('kB', num):
|
||||
# # unit kB to s
|
||||
# num_s = num/1.024*2
|
||||
# elif re.search('MB', num):
|
||||
# # unit MB to s
|
||||
# num_s = num/1000/1.024*2
|
||||
# elif re.search('GB', num):
|
||||
# # unit GB to s
|
||||
# num_s = num/1000/1000/1.024*2
|
||||
# return num_s
|
||||
|
||||
#the origin unit is 'byte'
|
||||
def pretty_unit(num):
|
||||
num = int(num)
|
||||
def pretty_unit(num, unit=base_unit):
|
||||
num = float(num)
|
||||
global num_pretty
|
||||
global unit_pretty
|
||||
if num < 1000:
|
||||
# < 1k unit is B
|
||||
num_pretty = num
|
||||
unit_pretty = 'B'
|
||||
elif num/1000 < 10*1000:
|
||||
# < 10M unit is kB
|
||||
num_pretty = num/1000
|
||||
unit_pretty = 'kB'
|
||||
elif num/1000/1000 < 10*1000:
|
||||
# < 10G unit is MB
|
||||
num_pretty = num/1000/1000
|
||||
unit_pretty = 'MB'
|
||||
elif num/1000/1000/1000 < 10*1000:
|
||||
# < 10T unit is GB
|
||||
num_pretty = num/1000/1000/1000
|
||||
unit_pretty = 'GB'
|
||||
return str("%.1f" %num_pretty) + unit_pretty
|
||||
if unit == 'kB':
|
||||
if num < 1:
|
||||
# < 1k unit is B
|
||||
num_pretty = num * 1000
|
||||
unit_pretty = 'B'
|
||||
elif num < 10*1000:
|
||||
# < 10M unit is kB
|
||||
num_pretty = num
|
||||
unit_pretty = 'kB'
|
||||
elif num < 10*1000*1000:
|
||||
# < 10G unit is MB
|
||||
num_pretty = num/1000
|
||||
unit_pretty = 'MB'
|
||||
elif num < 10*1000*1000*1000:
|
||||
# < 10T unit is GB
|
||||
num_pretty = num/1000/1000
|
||||
unit_pretty = 'GB'
|
||||
return str("%.1f" %num_pretty) + unit_pretty
|
||||
if unit == 'B':
|
||||
if num < 1000:
|
||||
# < 1k unit is B
|
||||
num_pretty = num
|
||||
unit_pretty = 'B'
|
||||
elif num < 10*1000*1000:
|
||||
# < 10M unit is kB
|
||||
num_pretty = num/1000
|
||||
unit_pretty = 'kB'
|
||||
elif num < 10*1000*1000*1000:
|
||||
# < 10G unit is MB
|
||||
num_pretty = num/1000/1000
|
||||
unit_pretty = 'MB'
|
||||
elif num < 10*1000*1000*1000*1000:
|
||||
# < 10T unit is GB
|
||||
num_pretty = num/1000/1000/1000
|
||||
unit_pretty = 'GB'
|
||||
return str("%.1f" %num_pretty) + unit_pretty
|
||||
if unit == 's':
|
||||
if num*512 < 1000:
|
||||
# < 1k unit is B
|
||||
num_pretty = num*512
|
||||
unit_pretty = 'B'
|
||||
elif num*512 < 10*1000*1000:
|
||||
# < 10M unit is kB
|
||||
num_pretty = num*512/1000
|
||||
unit_pretty = 'kB'
|
||||
elif num*512 < 10*1000*1000*1000:
|
||||
# < 10G unit is MB
|
||||
num_pretty = num*512/1000/1000
|
||||
unit_pretty = 'MB'
|
||||
elif num*512 < 10*1000*1000*1000*1000:
|
||||
# < 10T unit is GB
|
||||
num_pretty = num*512/1000/1000/1000
|
||||
unit_pretty = 'GB'
|
||||
return str("%.1f" %num_pretty) + unit_pretty
|
||||
|
||||
def unit_to_byte(num_unit):
|
||||
|
||||
def conform_unit(num_unit, unit = base_unit):
|
||||
#num = int(filter(str.isdigit, str(num_unit)))
|
||||
# because int('10.0') error
|
||||
num = int(float(get_size_num(str(num_unit))))
|
||||
if re.search('kB', num_unit):
|
||||
# unit kB to byte
|
||||
num_byte = num*1000
|
||||
elif re.search('MB', num_unit):
|
||||
# unit MB to byte
|
||||
num_byte = num*1000*1000
|
||||
elif re.search('GB', num_unit):
|
||||
# unit GB to byte
|
||||
num_byte = num*1000*1000*1000
|
||||
return num_byte
|
||||
num = float(get_num(str(num_unit)))
|
||||
if unit == 'B':
|
||||
if re.search('kB', num_unit):
|
||||
# unit kB to byte
|
||||
num_byte = num*1000
|
||||
elif re.search('MB', num_unit):
|
||||
# unit MB to byte
|
||||
num_byte = num*1000*1000
|
||||
elif re.search('GB', num_unit):
|
||||
# unit GB to byte
|
||||
num_byte = num*1000*1000*1000
|
||||
else:
|
||||
# unit is B
|
||||
num_byte = num
|
||||
return num_byte
|
||||
|
||||
if unit == 'kB':
|
||||
if re.search('kB', num_unit):
|
||||
# unit kB to kB
|
||||
num_kb = num
|
||||
elif re.search('MB', num_unit):
|
||||
# unit MB to kB
|
||||
num_kb = num*1000
|
||||
elif re.search('GB', num_unit):
|
||||
# unit GB to kB
|
||||
num_kb = num*1000*1000
|
||||
else:
|
||||
# unit B to kB
|
||||
if num < 1000:
|
||||
num_kb = 1.0
|
||||
else:
|
||||
num_kb = num/1000
|
||||
return num_kb
|
||||
|
||||
if unit == 's':
|
||||
if re.search('kB', num_unit):
|
||||
# unit kB to s
|
||||
num_s = num*1000/512
|
||||
elif re.search('MB', num_unit):
|
||||
# unit MB to s
|
||||
num_s = num*1000*1000/512
|
||||
elif re.search('GB', num_unit):
|
||||
# unit GB to s
|
||||
num_s = num*1000*1000*1000/512
|
||||
else:
|
||||
# unit B to s
|
||||
if num < 512:
|
||||
num_s = 1.0
|
||||
else:
|
||||
num_s = num/512
|
||||
return num_s
|
||||
|
||||
def showPartitionWindow():
|
||||
global clb
|
||||
@@ -95,7 +144,7 @@ def showPartitionWindow():
|
||||
clb.append(["%s" %(dev),"","","","",""], \
|
||||
"dev:%s:%s" %(dev,dev_size), [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT])
|
||||
|
||||
if partition_table == ' ':
|
||||
if partition_table == '':
|
||||
continue
|
||||
|
||||
if re.search('/cciss/', dev):
|
||||
@@ -112,15 +161,16 @@ def showPartitionWindow():
|
||||
flags = p_d.Partition.dict[dev]['partition'][partition]['flags']
|
||||
|
||||
try:
|
||||
if int(filter(str.isdigit, start)) < 2000000 and \
|
||||
int(filter(str.isdigit, size)) < 2000000:
|
||||
continue
|
||||
if base_unit == 's':
|
||||
if (float(get_num(size)) < 2000000/512.0 and float(get_num(start)) < 2048) \
|
||||
or float(get_num(size)) < 40:
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
|
||||
start_pretty = pretty_unit(filter(str.isdigit, str(start)))
|
||||
end_pretty = pretty_unit(filter(str.isdigit, str(end)))
|
||||
size_pretty = pretty_unit(filter(str.isdigit, str(size)))
|
||||
start_pretty = pretty_unit(get_num(str(start)))
|
||||
end_pretty = pretty_unit(get_num(str(end)))
|
||||
size_pretty = pretty_unit(get_num(str(size)))
|
||||
|
||||
# pretty free space partition
|
||||
if re.search('free', partition):
|
||||
@@ -149,13 +199,17 @@ def showPartitionWindow():
|
||||
res =f.run()
|
||||
screen.refresh
|
||||
|
||||
def get_size_num(size):
|
||||
def get_num(size):
|
||||
if re.search('kB', size):
|
||||
size_num = size.split('kB')[0]
|
||||
elif re.search('MB', size):
|
||||
size_num = size.split('MB')[0]
|
||||
elif re.search('GB', size):
|
||||
size_num = size.split('GB')[0]
|
||||
elif re.search('s', size):
|
||||
size_num = size.split('s')[0]
|
||||
else:
|
||||
size_num = size.split('B')[0]
|
||||
return size_num
|
||||
|
||||
def show_error(tips):
|
||||
@@ -164,6 +218,20 @@ def show_error(tips):
|
||||
g21.add(Button("OK"), 0, 1)
|
||||
g21.runOnce()
|
||||
|
||||
def ask_dialog(tips,dev):
|
||||
g21 = GridForm(screen, "Warning", 1, 3)
|
||||
g21.add(TextboxReflowed(45, "%s" %(tips)),0,0)
|
||||
#g21.add(Label("%s." %(tips)), 0, 0)
|
||||
g21.add(Label(''), 0, 1)
|
||||
bb4 = ButtonBar(screen, (('Continue','continue'),('Cancel','cancel')))
|
||||
g21.add(bb4, 0, 2)
|
||||
res4 = g21.runOnce()
|
||||
if bb4.buttonPressed(res4) == "continue":
|
||||
p_d.Partition.dict[dev]['from_os'] = 'no'
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_size_set(size, maxsize):
|
||||
if size == "":
|
||||
return ("Must specify a value")
|
||||
@@ -198,13 +266,13 @@ def add_partition(ptype='', extended='', label=''):
|
||||
dev_name = dev.split("/dev/")[1]
|
||||
size = clb.current().split(":")[3]
|
||||
size_pretty = clb.current().split(":")[7]
|
||||
free_space_start = filter(str.isdigit, clb.current().split(":")[4])
|
||||
free_space_end = filter(str.isdigit, clb.current().split(":")[5])
|
||||
free_space_start = get_num(clb.current().split(":")[4])
|
||||
free_space_end = get_num(clb.current().split(":")[5])
|
||||
free_space_sn = int(p_d.Partition.dict[dev]['partition'][free_space]['sn'])
|
||||
pre_partition_name = clb.current().split(":")[8]
|
||||
size_num = filter(str.isdigit, size)
|
||||
size_num = get_num(size)
|
||||
unit = filter(str.isalpha, size_pretty)
|
||||
size_pretty_num = get_size_num(size_pretty)
|
||||
size_pretty_num = get_num(size_pretty)
|
||||
|
||||
bb2 = ButtonBar(screen, (("OK", "ok"), ("Cancel", "cancel")))
|
||||
sg21 = Grid(2,1)
|
||||
@@ -262,10 +330,15 @@ def add_partition(ptype='', extended='', label=''):
|
||||
show_error(tips)
|
||||
else:
|
||||
size_set_pretty = entry_size.value() + unit
|
||||
size_set_num = unit_to_byte(size_set_pretty)
|
||||
size_set_num = conform_unit(size_set_pretty)
|
||||
size_set = str(size_set_num) + base_unit
|
||||
partition_start = free_space_start + base_unit
|
||||
partition_end = str(int(free_space_start) + size_set_num) + base_unit
|
||||
#partition_start = free_space_start + base_unit
|
||||
partition_end = str(float(free_space_start) + size_set_num) + base_unit
|
||||
# 4k align
|
||||
if float(free_space_start)/2048.0 == int(float(free_space_start)/2048.0) != 0:
|
||||
partition_start = free_space_start + base_unit
|
||||
else:
|
||||
partition_start = str((int(float(free_space_start)/2048.0)+1)*2048) + base_unit
|
||||
|
||||
flags = ''
|
||||
if cb_boot.value() == 1:
|
||||
@@ -311,7 +384,7 @@ def add_partition(ptype='', extended='', label=''):
|
||||
partition = pre_partition_name + str(partition_num)
|
||||
partition_sn = free_space_sn
|
||||
|
||||
if float(get_size_num(size_set_pretty)) == float(get_size_num(size_pretty)):
|
||||
if float(get_num(size_set_pretty)) == float(get_num(size_pretty)):
|
||||
partition_end = free_space_end + base_unit
|
||||
if len(list_free_sorted) > 1:
|
||||
for p in list_free_sorted:
|
||||
@@ -327,14 +400,14 @@ def add_partition(ptype='', extended='', label=''):
|
||||
del p_d.Partition.dict[dev]['partition'][free_space]
|
||||
else:
|
||||
list_partition_all_sorted = p_d.sort_partitions(p_d.Partition.dict, dev, 'all')
|
||||
p_d.Partition.dict[dev]['partition'][free_space]['start'] = str(int(free_space_start) + size_set_num + 1) + base_unit
|
||||
p_d.Partition.dict[dev]['partition'][free_space]['start'] = str(float(free_space_start) + size_set_num + 1) + base_unit
|
||||
for p in list_partition_all_sorted:
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > free_space_sn-1:
|
||||
p_d.Partition.dict[dev]['partition'][p]['sn'] = int(p_d.Partition.dict[dev]['partition'][p]['sn']) + 1
|
||||
p_d.Partition.dict[dev]['partition'][free_space]['sn'] = int(free_space_sn) + 1
|
||||
p_d.Partition.dict[dev]['partition'][free_space]['size'] = \
|
||||
str(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][free_space]['end'])) - \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][free_space]['start']))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][free_space]['end'])) - \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][free_space]['start']))) + base_unit
|
||||
|
||||
p_d.Partition.dict[dev]['partition'][partition]['sn'] = int(partition_sn)
|
||||
p_d.Partition.dict[dev]['partition'][partition]['num'] = int(partition_num)
|
||||
@@ -413,6 +486,7 @@ def del_msdos_partition(partition,dev):
|
||||
res3 = g3.runOnce()
|
||||
|
||||
if bb3.buttonPressed(res3) == "delete":
|
||||
pre_partition_name = clb.current().split(":")[8]
|
||||
list_partition_all_sorted = p_d.sort_partitions(p_d.Partition.dict, dev, "all")
|
||||
partition_sn = p_d.Partition.dict[dev]['partition'][partition]['sn']
|
||||
partition_num = p_d.Partition.dict[dev]['partition'][partition]['num']
|
||||
@@ -430,8 +504,8 @@ def del_msdos_partition(partition,dev):
|
||||
#for p in list_partition_all_sorted:
|
||||
p_start = p_d.Partition.dict[dev]['partition'][p]['start']
|
||||
p_end = p_d.Partition.dict[dev]['partition'][p]['end']
|
||||
if int(filter(str.isdigit, p_start)) >= int(filter(str.isdigit, partition_start)) and \
|
||||
int(filter(str.isdigit, p_end)) <= int(filter(str.isdigit, partition_end)):
|
||||
if float(get_num(p_start)) >= float(get_num(partition_start)) and \
|
||||
float(get_num(p_end)) <= float(get_num(partition_end)):
|
||||
p_d.delete_one_partition(p_d.Partition.dict, dev, p)
|
||||
del_partition_count += 1
|
||||
if re.search('free', p):
|
||||
@@ -463,11 +537,6 @@ def del_msdos_partition(partition,dev):
|
||||
elif p_sn == partition_sn + 1:
|
||||
next_partition = p
|
||||
|
||||
#if re.search('/cciss/', dev):
|
||||
# pre_partition_name = dev + 'p'
|
||||
#else:
|
||||
# pre_partition_name = dev
|
||||
|
||||
try:
|
||||
(extended_start, extended_end) = get_extended_start_end(dev)
|
||||
except:
|
||||
@@ -477,14 +546,14 @@ def del_msdos_partition(partition,dev):
|
||||
# pre_partition must exist
|
||||
if locals().has_key('next_partition'):
|
||||
if re.search('free',next_partition) and \
|
||||
int(filter(str.isdigit, p_d.Partition.dict[dev]['partition'][next_partition]['end']))\
|
||||
<= int(filter(str.isdigit,extended_end)):
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))\
|
||||
<= float(get_num(extended_end)):
|
||||
if re.search('free', pre_partition):
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = \
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['end']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
base_unit
|
||||
p_d.delete_one_partition(p_d.Partition.dict, dev, next_partition)
|
||||
p_d.delete_one_partition(p_d.Partition.dict, dev,partition)
|
||||
@@ -506,11 +575,16 @@ def del_msdos_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition'][p]['size']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['type'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['type']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['filesystem'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['filesystem']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['flags'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['flags']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['from_os'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['from_os']
|
||||
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['mount_point'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['mount_point']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['format'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['format']
|
||||
if re.search('free',p):
|
||||
p_num -= 1
|
||||
p_d.Partition.dict[dev]['partition']['free '+ str(p_num)]['num'] = \
|
||||
@@ -566,6 +640,10 @@ def del_msdos_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition'][p]['flags']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['from_os'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['from_os']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['mount_point'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['mount_point']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['format'] = \
|
||||
p_d.Partition.dict[dev]['partition'][p]['format']
|
||||
p_num_max = 1
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "partition"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['num'] > p_num_max:
|
||||
@@ -576,8 +654,8 @@ def del_msdos_partition(partition,dev):
|
||||
if re.search('free', pre_partition):
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = partition_end
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter.isdigit, partition_end) - \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+base_unit
|
||||
str(float(get_num(partition_end)) - \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+base_unit
|
||||
else:
|
||||
free_num = 0
|
||||
list_free_sorted = p_d.sort_partitions(p_d.Partition.dict, dev, "free")
|
||||
@@ -626,10 +704,16 @@ def del_msdos_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition'][p]['size']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['type']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['type']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['filesystem']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['filesystem']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['flags']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['flags']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['from_os']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['from_os']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['mount_point']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['mount_point']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition_name+str(p_num)]['format']=\
|
||||
p_d.Partition.dict[dev]['partition'][p]['format']
|
||||
p_d.delete_one_partition(p_d.Partition.dict, dev, \
|
||||
p_d.sort_partitions(p_d.Partition.dict,dev,"partition")[::-1][0])
|
||||
|
||||
@@ -657,14 +741,14 @@ def del_msdos_partition(partition,dev):
|
||||
if locals().has_key('pre_partition') and locals().has_key('next_partition'):
|
||||
if re.search('free', pre_partition) and re.search('free', next_partition):
|
||||
if locals().has_key('extended_start') and \
|
||||
(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= int(filter(str.isdigit, extended_start)) and \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['end']))\
|
||||
<= int(filter(str.isdigit, extended_end))):
|
||||
(float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= float(get_num(extended_start)) and \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['end']))\
|
||||
<= float(get_num(extended_end))):
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['start'] = partition_start
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['size'] = \
|
||||
str(int(filter(str.isdigit, p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit, partition_start))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(partition_start))) + base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn:
|
||||
#if not re.search('free', p):
|
||||
@@ -693,8 +777,8 @@ def del_msdos_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = \
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['end']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn + 1:
|
||||
@@ -722,10 +806,10 @@ def del_msdos_partition(partition,dev):
|
||||
|
||||
elif re.search('free', pre_partition) and not re.search('free', next_partition):
|
||||
if locals().has_key('extended_start') and \
|
||||
(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= int(filter(str.isdigit, extended_start)) or \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['end']))\
|
||||
<= int(filter(str.isdigit, extended_end))):
|
||||
(float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= float(get_num(extended_start)) or \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['end']))\
|
||||
<= float(get_num(extended_end))):
|
||||
len_free_list = len(p_d.sort_partitions(p_d.Partition.dict, dev, "free"))
|
||||
free_num_mid = 0
|
||||
for i in range(len_free_list)[::-1]:
|
||||
@@ -757,8 +841,8 @@ def del_msdos_partition(partition,dev):
|
||||
else:
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = partition_end
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter(str.isdigit, partition_end)) - \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
str(float(get_num(partition_end)) - \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn:
|
||||
@@ -786,8 +870,8 @@ def del_msdos_partition(partition,dev):
|
||||
elif not re.search('free', pre_partition) and re.search('free',next_partition):
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['start'] = partition_start
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['size'] = \
|
||||
str(int(filter(str.isdigit, p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit, partition_start))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(partition_start))) + base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn:
|
||||
#if not re.search('free', p):
|
||||
@@ -864,13 +948,14 @@ def del_msdos_partition(partition,dev):
|
||||
|
||||
elif locals().has_key('pre_partition') and not locals().has_key('next_partition'):
|
||||
if re.search('free', pre_partition) and ((locals().has_key('extended_start') and\
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= int(filter(str.isdigit, extended_end))) or \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start']))\
|
||||
>= float(get_num(extended_end))) or \
|
||||
not locals().has_key('extended_start')) :
|
||||
free = p_d.sort_partitions(p_d.Partition.dict, dev,"free")[::-1][0]
|
||||
p_d.Partition.dict[dev]['partition'][free]['end'] = partition_end
|
||||
p_d.Partition.dict[dev]['partition'][free]['size'] = \
|
||||
partition_end - p_d.Partition.dict[dev]['partition'][free]['start']
|
||||
str(float(get_num(partition_end)) - \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][free]['start']))) + base_unit
|
||||
else:
|
||||
free_num_max = 0
|
||||
for f in p_d.sort_partitions(p_d.Partition.dict, dev, "free"):
|
||||
@@ -900,8 +985,8 @@ def del_msdos_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['sn'] = partition_sn
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['start'] = partition_start
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['size'] = \
|
||||
str(int(filter(str.isdigit, p_d.Partition.dict[dev]['partition']['free 1']['end']))\
|
||||
- int(filter(str.isdigit, partition_start))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition']['free 1']['end']))\
|
||||
- float(get_num(partition_start))) + base_unit
|
||||
else:
|
||||
for f in p_d.sort_partitions(p_d.Partition.dict, dev,"free")[::-1]:
|
||||
free_num = p_d.Partition.dict[dev]['partition'][f]['num']
|
||||
@@ -940,6 +1025,7 @@ def del_gpt_partition(partition,dev):
|
||||
res3 = g3.runOnce()
|
||||
|
||||
if bb3.buttonPressed(res3) == "delete":
|
||||
pre_partition_name = clb.current().split(":")[8]
|
||||
list_partition_all_sorted = p_d.sort_partitions(p_d.Partition.dict, dev, "all")
|
||||
partition_sn = p_d.Partition.dict[dev]['partition'][partition]['sn']
|
||||
partition_num = p_d.Partition.dict[dev]['partition'][partition]['num']
|
||||
@@ -963,8 +1049,8 @@ def del_gpt_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = \
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['end']
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn + 1:
|
||||
@@ -992,8 +1078,8 @@ def del_gpt_partition(partition,dev):
|
||||
elif re.search('free', pre_partition) and not re.search('free', next_partition):
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['end'] = partition_end
|
||||
p_d.Partition.dict[dev]['partition'][pre_partition]['size'] = \
|
||||
str(int(filter(str.isdigit, partition_end)) - \
|
||||
int(filter(str.isdigit,p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
str(float(get_num(partition_end)) - \
|
||||
float(get_num(p_d.Partition.dict[dev]['partition'][pre_partition]['start'])))+\
|
||||
base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn:
|
||||
@@ -1001,8 +1087,8 @@ def del_gpt_partition(partition,dev):
|
||||
elif not re.search('free', pre_partition) and re.search('free',next_partition):
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['start'] = partition_start
|
||||
p_d.Partition.dict[dev]['partition'][next_partition]['size'] = \
|
||||
str(int(filter(str.isdigit, p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
int(filter(str.isdigit, partition_start))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition'][next_partition]['end']))-\
|
||||
float(get_num(partition_start))) + base_unit
|
||||
for p in p_d.sort_partitions(p_d.Partition.dict, dev, "all"):
|
||||
if p_d.Partition.dict[dev]['partition'][p]['sn'] > partition_sn:
|
||||
p_d.Partition.dict[dev]['partition'][p]['sn'] -= 1
|
||||
@@ -1071,8 +1157,8 @@ def del_gpt_partition(partition,dev):
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['sn'] = partition_sn
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['start'] = partition_start
|
||||
p_d.Partition.dict[dev]['partition']['free 1']['size'] = \
|
||||
str(int(filter(str.isdigit, p_d.Partition.dict[dev]['partition']['free 1']['end']))\
|
||||
- int(filter(str.isdigit, partition_start))) + base_unit
|
||||
str(float(get_num(p_d.Partition.dict[dev]['partition']['free 1']['end']))\
|
||||
- float(get_num(partition_start))) + base_unit
|
||||
else:
|
||||
for f in p_d.sort_partitions(p_d.Partition.dict, dev,"free")[::-1]:
|
||||
free_num = p_d.Partition.dict[dev]['partition'][f]['num']
|
||||
@@ -1135,6 +1221,7 @@ def main():
|
||||
if bb1.buttonPressed(res1) == "ok":
|
||||
label = rb.getSelection()
|
||||
p_d.Partition.dict[dev]['partition_table'] = label
|
||||
#os.system('parted -s %s mklabel %s' %(dev,label))
|
||||
p_d.delete_all_partitions(p_d.Partition.dict, dev)
|
||||
|
||||
# add partition when dev's label is msdos
|
||||
@@ -1142,6 +1229,9 @@ def main():
|
||||
clb.current().split(':')[6] == 'msdos'and \
|
||||
bb.buttonPressed(res) == "new":
|
||||
dev = clb.current().split(":")[2]
|
||||
if p_d.Partition.dict[dev]['from_os'] != 'no':
|
||||
if not ask_dialog('Changing the partition will damage the data on the disk %s, do you want to continue?' %(dev,),dev):
|
||||
continue
|
||||
dev_name = dev.split("/dev/")[1]
|
||||
free_space_start = clb.current().split(":")[4]
|
||||
free_space_end = clb.current().split(":")[5]
|
||||
@@ -1151,11 +1241,11 @@ def main():
|
||||
# add logical partition when an extended partition exists
|
||||
if re.search('extended', str(p_d.Partition.dict[dev])):
|
||||
(extended_start, extended_end) = get_extended_start_end(dev)
|
||||
if int(filter(str.isdigit,free_space_start)) >= int(filter(str.isdigit,extended_start)) \
|
||||
and int(filter(str.isdigit,free_space_end)) <= int(filter(str.isdigit,extended_end)):
|
||||
if float(get_num(free_space_start)) >= float(get_num(extended_start)) \
|
||||
and float(get_num(free_space_end)) <= float(get_num(extended_end)):
|
||||
ptype = 'logical'
|
||||
add_partition(ptype, 'extended', 'msdos')
|
||||
elif int(filter(str.isdigit,free_space_start)) >= int(filter(str.isdigit,extended_end)):
|
||||
elif float(get_num(free_space_start)) >= float(get_num(extended_end)):
|
||||
show_error("Bad partition scheme ! This free space can't be used any more !")
|
||||
else:
|
||||
if count_primary == 3:
|
||||
@@ -1172,6 +1262,9 @@ def main():
|
||||
clb.current().split(':')[6] == 'gpt'and \
|
||||
bb.buttonPressed(res) == "new":
|
||||
dev = clb.current().split(":")[2]
|
||||
if p_d.Partition.dict[dev]['from_os'] != 'no':
|
||||
if not ask_dialog('Changing the partition will damage the data on the disk %s, do you want to continue?' %(dev,),dev):
|
||||
continue
|
||||
free_space_start = clb.current().split(":")[4]
|
||||
free_space_end = clb.current().split(":")[5]
|
||||
free_space_size = clb.current().split(":")[3]
|
||||
@@ -1180,8 +1273,11 @@ def main():
|
||||
elif re.search("partition:free", clb.current()) == None and \
|
||||
re.search("dev:", clb.current()) == None and \
|
||||
bb.buttonPressed(res) == "delete":
|
||||
msdos_or_gpt = clb.current().split(':')[6]
|
||||
dev = clb.current().split(":")[2]
|
||||
if p_d.Partition.dict[dev]['from_os'] != 'no':
|
||||
if not ask_dialog('Changing the partition will damage the data on the disk %s,do you want to continue?' %(dev,),dev):
|
||||
continue
|
||||
msdos_or_gpt = clb.current().split(':')[6]
|
||||
partition = clb.current().split(":")[1]
|
||||
pre_partition_name = clb.current().split(':')[8]
|
||||
if msdos_or_gpt == 'msdos':
|
||||
@@ -1190,4 +1286,9 @@ def main():
|
||||
del_gpt_partition(partition, dev)
|
||||
|
||||
screen.finish()
|
||||
#p_d.write_to_xml_file()
|
||||
return ret
|
||||
|
||||
|
||||
#p_d.Partition.init_from_os(unit='s')
|
||||
#main()
|
||||
|
||||
@@ -383,16 +383,19 @@ def delete_all_partitions(d, k):
|
||||
d[k]['partition'].pop(key, None)
|
||||
|
||||
_device = _ped.device_get(k)
|
||||
_disk = _ped.Disk(_device)
|
||||
'''find the end !meta partition end as disks end '''
|
||||
_part = _disk.next_partition()
|
||||
while _part:
|
||||
if _part.type & 8:
|
||||
_part = _disk.next_partition(_part)
|
||||
continue
|
||||
p_g = _part.geom
|
||||
end = _device.unit_format_byte((p_g.end + 1) * _device.sector_size - 1)
|
||||
_part = _disk.next_partition(_part)
|
||||
|
||||
''' Get end size maybe use disk_new_fresh function is better.'''
|
||||
''' TODO: must use a function to convert to compact unit.'''
|
||||
if d[k]['partition_table'] == 'msdos':
|
||||
''' algorithm from libparted/labels/dos.c add_startend_metadata()'''
|
||||
end = "%ss" %(_device.length - 1)
|
||||
elif d[k]['partition_table'] == 'gpt':
|
||||
''' algorithm from libparted/labels/gpt.c gpt_alloc()'''
|
||||
GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE=int(16384)
|
||||
end = "%ss" %(_device.length-2 - \
|
||||
GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / _device.sector_size)
|
||||
else:
|
||||
end = d[k]['disk_size']
|
||||
|
||||
|
||||
partition = 'free 1'
|
||||
@@ -429,9 +432,12 @@ def sort_partition(dict, disk, p):
|
||||
elif p == "partition":
|
||||
return (sorted(p_d, key = lambda key: p_d[key]))
|
||||
else:
|
||||
return
|
||||
return []
|
||||
|
||||
def sort_partitions(dict, disk, p="all"):
|
||||
if dict[disk]['partition_table'] == '':
|
||||
return []
|
||||
|
||||
if p == "all":
|
||||
''' k, t: partitions '''
|
||||
return (sorted(((k) for k in dict[disk]["partition"]), key=lambda \
|
||||
@@ -459,8 +465,8 @@ def init_from_xml():
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Partition.init_from_os()
|
||||
#if __name__ == "__main__":
|
||||
#Partition.init_from_os(unit='s')
|
||||
#for d in Partition.get_raid_devices():
|
||||
# print d
|
||||
#print Partition.dict.keys()
|
||||
@@ -491,4 +497,3 @@ if __name__ == "__main__":
|
||||
#print Partition.get_disk_attr("/dev/sda", "disk_size")
|
||||
#print Partition.get_disk_attr("/dev/sda", "partition_table")
|
||||
#print Partition.get_partition_attr("/dev/sda1", "size")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash -
|
||||
#!/bin/bash
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: partition_disks.sh
|
||||
|
||||
Reference in New Issue
Block a user