Modif di_newt mount_point and raid for new datastructure
modified: dialog/di_main.py modified: dialog/di_newt.py modified: new_partition/partition_data.py Signed-off-by: Qin Bo <bqin@linx-info.com>
This commit is contained in:
@@ -10,7 +10,7 @@ list=['welcome','partition','raid','mountpoint','serialnumber','network','group'
|
||||
count=0
|
||||
while True :
|
||||
if count == 1:
|
||||
s = os.system("python ../new_partition/new_partition.py")
|
||||
s = os.system("python ../new_partition/interface_partition.py")
|
||||
|
||||
ri_data.init()
|
||||
if len(di_newt.Raid.raid_raw_init()) < 2:
|
||||
|
||||
@@ -4,8 +4,10 @@ import sys
|
||||
import re
|
||||
import time
|
||||
sys.path.append('../interface/')
|
||||
sys.path.append('../new_partition/')
|
||||
|
||||
import ri_data
|
||||
import partition_data as p_d
|
||||
|
||||
config_xml = "../xml/config.xml"
|
||||
|
||||
@@ -234,19 +236,18 @@ class Raid(Screen):
|
||||
self.title = 'Making Raid devices'
|
||||
|
||||
@staticmethod
|
||||
def raid_raw_init():
|
||||
''' initialize raid raw devices (parttion with id 'fd' '''
|
||||
def init_from_internal():
|
||||
''' initialize raid raw devices partition with id 'fd' '''
|
||||
# get all component devices already in raid
|
||||
dev_in_raid = ri_data.Raid.dev_in_raid()
|
||||
|
||||
raw_devs = [ d for d in ri_data.Partition.dict.keys()
|
||||
if re.search('raid', ri_data.Partition.dict[d].flags) and d not in dev_in_raid ]
|
||||
raw_devs = [ d for d in p_d.Partition.get_raid() and d not in dev_in_raid ]
|
||||
raw_devs.sort()
|
||||
return raw_devs
|
||||
|
||||
def raid_raw_map(self):
|
||||
list=[]
|
||||
fd=Raid.raid_raw_init()
|
||||
fd=Raid.init_from_internal()
|
||||
for d in fd:
|
||||
list.append((d,'','off'))
|
||||
return list
|
||||
@@ -326,7 +327,7 @@ class Raid(Screen):
|
||||
return s
|
||||
|
||||
def make_raid(self):
|
||||
fd_devices=Raid.raid_raw_init()
|
||||
fd_devices=Raid.init_from_internal()
|
||||
|
||||
# from os
|
||||
raid_text=''
|
||||
@@ -384,7 +385,7 @@ class Raid(Screen):
|
||||
def set_data(self):
|
||||
while True:
|
||||
list = ['Making the raid device','Delect raid device']
|
||||
fd_devices=Raid.raid_raw_init()
|
||||
fd_devices=Raid.init_from_internal()
|
||||
fd_devices_text=''
|
||||
raid_text=''
|
||||
|
||||
@@ -429,6 +430,9 @@ class MountPoint(Screen):
|
||||
self.title = 'MountPoint Configure'
|
||||
|
||||
def set_mountpoint(self, device):
|
||||
disk = device.split(':')[0]
|
||||
dev = device.split(':')[1]
|
||||
|
||||
Screen.widget_buttonbar(Screen.buttonlist1)
|
||||
Screen.widget_textboxreflowed(30, 'Please input the mountpoint and select the file system type.')
|
||||
Screen.label_mp = Label('mountpoint : ')
|
||||
@@ -442,33 +446,38 @@ class MountPoint(Screen):
|
||||
Screen.container_grid_complex(3, 2, Screen.label_mp, Screen.entry, Screen.label, Screen.label, Screen.label_fs, Screen.listbox)
|
||||
s = Screen.yesno(self.title, 1, 6, 'TextboxReflowed', 'eLabel', 'Grid_Complex', 'eLabel', 'ButtonBar')
|
||||
if s == 0:
|
||||
ri_data.MountPoint.dict[device].filesystem= Screen.listbox.current()
|
||||
ri_data.MountPoint.dict[device].directory= Screen.entry.value()
|
||||
ri_data.MountPoint.dict[device].format='yes'
|
||||
p_d.Partition.dict[disk]['partition'][dev]['filesystem'] = Screen.listbox.current()
|
||||
p_d.Partition.dict[disk]['partition'][dev]['mount_point'] = Screen.entry.value()
|
||||
p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes'
|
||||
|
||||
return s
|
||||
|
||||
def set_data(self):
|
||||
ri_data.MountPoint.init_from_internal()
|
||||
while True:
|
||||
keys=ri_data.MountPoint.dict.keys()
|
||||
keys.sort()
|
||||
disks = p_d.Partition.dict.keys()
|
||||
disks.sort()
|
||||
|
||||
len_keys = len(keys)
|
||||
list_col_widths = [6, 12, 10, 5, 10]
|
||||
#len_keys = len(keys)
|
||||
# 18 is length of '/dev/cciss/c0d0p1'
|
||||
list_col_widths = [18, 12, 10, 15, 10]
|
||||
list_col_labels = []
|
||||
list_col_label_align = [CENTER, CENTER, CENTER, CENTER, CENTER]
|
||||
|
||||
Screen.widget_clistbox(list_col_widths, list_col_labels, list_col_label_align, h=len_keys)
|
||||
|
||||
for d in keys:
|
||||
Screen.clistbox.append(["%s" %(ri_data.MountPoint.dict[d].device),
|
||||
"%s" %(ri_data.MountPoint.dict[d].directory.ljust(10)),
|
||||
"%s" %(ri_data.MountPoint.dict[d].filesystem.ljust(10)),
|
||||
"%s" %(ri_data.MountPoint.dict[d].format.ljust(5)),
|
||||
"%s%s" %(ri_data.MountPoint.get_size(d),ri_data.Partition.unit)],
|
||||
"%s" %(ri_data.MountPoint.dict[d].device),
|
||||
[LEFT, LEFT, LEFT, LEFT, RIGHT])
|
||||
Screen.widget_clistbox(list_col_widths, list_col_labels, list_col_label_align, h=5)
|
||||
for d in disks:
|
||||
partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition')
|
||||
for p in partitions:
|
||||
# loop for nest dict to find partition
|
||||
for k in p_d.Partition.dict[d]['partition'].keys():
|
||||
if p == k:
|
||||
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)),
|
||||
"%s" %(p_d.Partition.dict[d]['partition'][p]['format'].ljust(5)),
|
||||
"%s%s" %(p_d.Partition.dict[d]['partition'][p]['size'], p_d.Partition.unit)],
|
||||
"%s:%s" %(d, p),
|
||||
[LEFT, LEFT, LEFT, LEFT, RIGHT])
|
||||
break
|
||||
|
||||
Screen.widget_buttonbar(Screen.buttonlist3)
|
||||
Screen.widget_textboxreflowed(50, 'There are five colums in the mount point display frame.\nDevice Mountpoint Filesystem Format Size')
|
||||
|
||||
@@ -9,7 +9,10 @@ from collections import defaultdict
|
||||
import _ped
|
||||
import parted_devices
|
||||
|
||||
DEBUG = False
|
||||
if os.environ.get('DEBUG'):
|
||||
DEBUG = True
|
||||
else:
|
||||
DEBUG = False
|
||||
|
||||
''' algorithm from libparted/unit.c '''
|
||||
def parse_unit_suffix(suffix):
|
||||
@@ -176,44 +179,86 @@ class Partition:
|
||||
flags = get_flags(_part)
|
||||
|
||||
sn += 1
|
||||
if DEBUG:
|
||||
print "sn:%s, num:%s, %s, start:%s, end:%s, size:%s, type_name:%s, fs: %s, flags: %s" %(sn, num, partition, start, end, size, type_name, fs, flags)
|
||||
|
||||
''' create a Partition instance from hardware info'''
|
||||
Partition(dev , # device name
|
||||
disk_size, # disk size
|
||||
partition_table, # partition table
|
||||
sn, # partition sequence number
|
||||
partition, # partition
|
||||
num, # num
|
||||
start, # start
|
||||
end, # end
|
||||
size, # size
|
||||
type_name, # type
|
||||
fs, # file system
|
||||
flags, # flags
|
||||
'yes', # from os
|
||||
' ', # whether format
|
||||
' ' # mount point
|
||||
if DEBUG:
|
||||
print "sn:%s, num:%s, %s, start:%s, end:%s, size:%s,\
|
||||
type_name:%s, fs: %s, flags: %s" %(sn, num, partition, start, end, size, \
|
||||
type_name, fs, flags)
|
||||
|
||||
''' create a Partition instance from hardware info '''
|
||||
Partition(dev , # device name
|
||||
disk_size, # disk size
|
||||
partition_table, # partition table
|
||||
sn, # partition sequence number
|
||||
partition, # partition
|
||||
num, # num
|
||||
start, # start
|
||||
end, # end
|
||||
size, # size
|
||||
type_name, # type
|
||||
fs, # file system
|
||||
flags, # flags
|
||||
'yes', # from os
|
||||
' ', # whether format
|
||||
' ' # mount point
|
||||
)
|
||||
|
||||
''' next partition '''
|
||||
_part = _disk.next_partition(_part)
|
||||
|
||||
'''TODO:
|
||||
need fix for new data structure or abandon
|
||||
'''
|
||||
@staticmethod
|
||||
def init_from_xml(node):
|
||||
''' create Partition instances from xml node '''
|
||||
Partition.unit = node.attributes['unit'].value.encode('ascii')
|
||||
for p in node.childNodes:
|
||||
if p.nodeType == node.ELEMENT_NODE and p.nodeName == 'partition':
|
||||
Partition(p.attributes['device'].value.encode('ascii'),\
|
||||
p.attributes['start'].value.encode('ascii'),\
|
||||
p.attributes['size'].value.encode('ascii'),\
|
||||
p.attributes['type'].value.encode('ascii'),\
|
||||
p.attributes['file-system'].value.encode('ascii'),\
|
||||
p.attributes['flags'].value.encode('ascii'),\
|
||||
p.attributes['from_os'].value.encode('ascii'))
|
||||
if DEBUG:
|
||||
print Partition.unit
|
||||
for d in node.childNodes:
|
||||
if d.nodeType == node.ELEMENT_NODE and d.nodeName == 'disk':
|
||||
dev = d.attributes['disk'].value.encode('ascii')
|
||||
disk_size = d.attributes['disk_size'].value.encode('ascii')
|
||||
partition_table = d.attributes['partition_table'].value.encode('ascii')
|
||||
|
||||
if DEBUG:
|
||||
print dev
|
||||
print partition_table
|
||||
print disk_size
|
||||
|
||||
for p in d.getElementsByTagName('partition'):
|
||||
sn = p.attributes['sn'].value.encode('ascii')
|
||||
partition = p.attributes['partition'].value.encode('ascii')
|
||||
num = p.attributes['num'].value.encode('ascii')
|
||||
start = p.attributes['start'].value.encode('ascii')
|
||||
end = p.attributes['end'].value.encode('ascii')
|
||||
size = p.attributes['size'].value.encode('ascii')
|
||||
type_name = p.attributes['type'].value.encode('ascii')
|
||||
fs = p.attributes['filesystem'].value.encode('ascii')
|
||||
flags = p.attributes['flags'].value.encode('ascii')
|
||||
from_os = p.attributes['from_os'].value.encode('ascii')
|
||||
fmt = p.attributes['format'].value.encode('ascii')
|
||||
mp = p.attributes['mount_point'].value.encode('ascii')
|
||||
|
||||
if DEBUG:
|
||||
print "sn:%s, num:%s, %s, start:%s, end:%s, size:%s,\
|
||||
type_name:%s, fs: %s, flags: %s" %(sn, num, partition, start, end, size, \
|
||||
type_name, fs, flags)
|
||||
|
||||
''' initialise from xml '''
|
||||
Partition(dev , # device name
|
||||
disk_size, # disk size
|
||||
partition_table, # partition table
|
||||
sn, # partition sequence number
|
||||
partition, # partition
|
||||
num, # num
|
||||
start, # start
|
||||
end, # end
|
||||
size, # size
|
||||
type_name, # type
|
||||
fs, # file system
|
||||
flags, # flags
|
||||
from_os, # from os
|
||||
fmt, # whether format
|
||||
mp # mount point
|
||||
)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -245,7 +290,15 @@ p_node - xml node (parent node)'''
|
||||
except:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_raid_devices():
|
||||
rd = []
|
||||
for key in Partition.dict:
|
||||
for k in Partition.dict[key]['partition'].keys():
|
||||
if Partition.dict[key]['partition'][k]['flags'] == 'raid':
|
||||
rd.append(k)
|
||||
|
||||
return rd
|
||||
|
||||
''' Fix Me:
|
||||
make recursive is better '''
|
||||
@@ -314,19 +367,18 @@ def sort_partition(dict, disk, p):
|
||||
if k.startswith("free"):
|
||||
f_d[k] = dict[disk]["partition"][k]["num"]
|
||||
else:
|
||||
p_d[k] = dict[disk]["partition"][k]["num"]
|
||||
p_d[k] = dict[disk]["partition"][k]["num"]
|
||||
|
||||
if p == "free":
|
||||
return (sorted(f_d, key = lambda key: f_d[key]))
|
||||
elif p == "partition":
|
||||
return (sorted(p_d, key = lambda key: p_d[key]))
|
||||
return (sorted(p_d, key = lambda key: p_d[key]))
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
def sort_partitions(dict, disk, p="all"):
|
||||
# k, t: partitions
|
||||
if p == "all":
|
||||
''' k, t: partitions '''
|
||||
return (sorted(((k) for k in dict[disk]["partition"]), key=lambda \
|
||||
t: dict[disk]["partition"][t]["sn"]))
|
||||
elif p == "free":
|
||||
@@ -342,32 +394,44 @@ def write_to_xml_file():
|
||||
xml_string =xmldoc.toprettyxml(indent=" ")
|
||||
print xml_string
|
||||
|
||||
def init_from_xml():
|
||||
xmldoc = minidom.parse('install.xml')
|
||||
root = xmldoc.firstChild
|
||||
for n in root.childNodes:
|
||||
if n.nodeType == n.ELEMENT_NODE:
|
||||
if n.nodeName == 'disks':
|
||||
Partition.init_from_xml(n)
|
||||
|
||||
|
||||
|
||||
#if __name__ == "__main__":
|
||||
# Partition.init_from_os()
|
||||
if __name__ == "__main__":
|
||||
Partition.init_from_os()
|
||||
#for d in Partition.get_raid_devices():
|
||||
# print d
|
||||
#print Partition.dict.keys()
|
||||
#pretty(Partition.dict)
|
||||
#write_to_xml_file()
|
||||
disks = Partition.dict.keys()
|
||||
#disks.sort()
|
||||
#for key in disks:
|
||||
# partitions = sort_partitions(Partition.dict, key, 'partition')
|
||||
# for p in partitions:
|
||||
# for k in Partition.dict[key]['partition'].keys():
|
||||
# if k == p:
|
||||
# print "%s, %s, %s" %(key, k, Partition.dict[key]['partition'][k]['filesystem'])
|
||||
#init_from_xml()
|
||||
#pretty(Partition.dict)
|
||||
#delete_all_partitions(Partition.dict, "/dev/sda")
|
||||
# delete_one_partition(Partition.dict, "/dev/sdb", "free 1")
|
||||
#delete_one_partition(Partition.dict, "/dev/sdb", "free 1")
|
||||
#pretty(Partition.dict)
|
||||
# print sort_partitions(Partition.dict, "/dev/sda", "all")
|
||||
# print "+"*100
|
||||
# print sort_partitions(Partition.dict, "/dev/sda", "free")
|
||||
# print "+"*100
|
||||
# print sort_partitions(Partition.dict, "/dev/sda", "partition")
|
||||
# write_to_xml_file()
|
||||
#print sort_partitions(Partition.dict, "/dev/sda", "all")
|
||||
#print "+"*100
|
||||
#print sort_partitions(Partition.dict, "/dev/sda", "free")
|
||||
#print "+"*100
|
||||
#print sort_partitions(Partition.dict, "/dev/sda", "partition")
|
||||
#print Partition.dict
|
||||
#print Partition.get_size("/dev/sda")
|
||||
#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")
|
||||
|
||||
# xmldoc = minidom.Document()
|
||||
# root = xmldoc.createElement('install')
|
||||
# xmldoc.appendChild(root)
|
||||
# Partition.to_xml(xmldoc, root)
|
||||
# xml_string = xmldoc.toprettyxml(indent=" ")
|
||||
|
||||
# print xml_string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user