From 2ab2cc76390917ee8c836d230e5fc30a64dad512 Mon Sep 17 00:00:00 2001 From: Peng Zhihui Date: Thu, 16 Jan 2014 16:06:09 +0800 Subject: [PATCH] Support making raid and Fix problems of partition-tool Merge the button 'Next' to 'OK' on the network configure interface 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 --- dialog/di_main.py | 7 + dialog/di_newt.py | 191 +++++++++++---------------- interface/ri_data.py | 43 ++++-- interface/ri_oper.py | 33 +++++ new_partition/interface_partition.py | 51 +++++-- new_partition/partition_data.py | 15 ++- 6 files changed, 205 insertions(+), 135 deletions(-) diff --git a/dialog/di_main.py b/dialog/di_main.py index 194cc28..26d9e89 100644 --- a/dialog/di_main.py +++ b/dialog/di_main.py @@ -11,9 +11,13 @@ list=['welcome','partition','raid','mountpoint','serialnumber','network','group' init_partition_from_os_flag = True init_flag = True +init_raid_from_os = True count=0 while True : if count == 1: + if init_raid_from_os: + ri_data.Raid.init_from_os() + init_raid_from_os = False if init_partition_from_os_flag: partition_data.Partition.init_from_os(unit='s') init_partition_from_os_flag = False @@ -26,6 +30,9 @@ while True : if list[2] == 'raid': del list[2] else: + #if init_raid_from_os: + # ri_data.Raid.init_from_os() + # init_raid_from_os = False if list[2] != 'raid': list.insert(2, 'raid') else: diff --git a/dialog/di_newt.py b/dialog/di_newt.py index f6bb84b..bd4ef4e 100644 --- a/dialog/di_newt.py +++ b/dialog/di_newt.py @@ -221,11 +221,19 @@ class Screen: return s @staticmethod - def pop_window(title, text, width): + def pop_window(title, text, width, button='one'): Screen.p_window = GridForm(Screen.screen, title, 1, 2) Screen.p_window.add(TextboxReflowed(width, text),0,0) - Screen.p_window.add(Button('OK'),0,1) - Screen.p_window.runOnce() + if button == 'one': + Screen.p_window.add(Button('OK'),0,1) + else: + p_bb = ButtonBar(Screen.screen,(('Yes','yes'),('No','no'))) + Screen.p_window.add(p_bb,0,1) + p_res = Screen.p_window.runOnce() + if p_bb.buttonPressed(p_res) == 'yes': + return 0 + else: + pass @@ -272,8 +280,8 @@ class Raid(Screen): #raw_devs = [ d for d in p_d.Partition.get_raid_devices() and d not in dev_in_raid ] raw_devs = [] for d in p_d.Partition.get_raid_devices(): - if d not in dev_in_raid: - raw_devs.append(d) + if d.split('/dev/')[1] not in dev_in_raid: + raw_devs.append(d.split('/dev/')[1]) raw_devs.sort() return raw_devs @@ -295,38 +303,26 @@ class Raid(Screen): for i in list: list_ct.append(i[0]) - #Screen.widget_checkboxlist(list_cb) - #if len(list_ct) <= 5: - # h = len(list_ct) - #else: - # h = 5 h = 5 if len(list_ct) > 5 else len(list_ct) Screen.widget_checkboxtree(h,list_ct) - - #num_widget = len(list) + 4 Screen.widget_buttonbar(Screen.buttonlist0) Screen.widget_textboxreflowed(47, 'Please select the active fd') while True: s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'CheckboxTree', 'eLabel', 'ButtonBar') - #s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') if s == 0: actives = [] for i in Screen.checkboxtree.getSelection(): actives.append(i) - #for i in list: - # if Screen.d_cbl[i[0]].value() == 1: - # actives.append(i[0]) if int(level) < 2 and len(actives) < 2 : - #ButtonChoiceWindow(Screen.screen, 'Warning', 'Making a raid0 or raid1 needs two or more partitions.') Screen.pop_window('Tips', 'Making a raid0 or raid1 needs two or more partitions.',30) elif int(level) == 5 and len(actives) < 3: ButtonChoiceWindow(Screen.screen, 'Warning', 'Making a raid5 needs three or more partitions.') else: #(dev, from_os, level, a_devs, s_devs=[]): if dname not in ri_data.Raid.dict.keys(): - ri_data.Raid(dname,'no',level,actives,[]) + ri_data.Raid(dname,'no',level,'','no','',actives,[]) else: #print 'get_next_name error in active?' #print dname @@ -344,34 +340,21 @@ class Raid(Screen): if not list: return 0 - #Screen.d_cbl = {} - #for i in list: - # Screen.d_cbl[i[0]] = Checkbox(i[0]) list_ct = [] for i in list: list_ct.append(i[0]) - #if len(list_ct) <= 5: - # h = len(list_ct) - #else: - # h = 5 h = 5 if len(list_ct) > 5 else len(list_ct) Screen.widget_checkboxtree(h, list_ct) - #num_widget = len(list) + 4 - Screen.widget_textboxreflowed(47, 'Please select the spare fd') Screen.widget_buttonbar(Screen.buttonlist0) - #s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'CheckboxTree', 'eLabel', 'ButtonBar') if s == 0: spares = [] - #for i in list: - # if Screen.d_cbl[i[0]].value() == 1: - # spares.append(i[0]) for i in Screen.checkboxtree.getSelection(): spares.append(i) @@ -405,7 +388,8 @@ class Raid(Screen): raid = Screen.listbox.current() dname = ri_data.Raid.get_next_device() self.raid_raw_to_active(raid[-1],dname) - self.raid_raw_to_spare(raid[-1],dname) + if raid[-1] != '0': + self.raid_raw_to_spare(raid[-1],dname) else: return s @@ -414,17 +398,12 @@ class Raid(Screen): raid_text='' raid_choices=[] - for R in [ d for d in ri_data.Raid.dict.values() if d.from_os == 'no' ]: + #for R in [ d for d in ri_data.Raid.dict.values() if d.from_os == 'no' ]: + for R in [ d for d in ri_data.Raid.dict.values() ]: raid_text+='%s (%s):\n active %s; spare %s\n'%(R.device,R.from_os,R.active_components,R.spare_components) raid_choices.append((R.device,'')) len_raid_choices = len(raid_choices) - #Screen.widget_listbox(len_raid_choices, *raid_choices) - - #if len(raid_choices) > 5: - # h = 5 - #else: - # h = len(raid_choices) h = 5 if len(raid_choices) > 5 else len(raid_choices) Screen.widget_buttonbar(Screen.buttonlist5) @@ -447,7 +426,8 @@ class Raid(Screen): fd_devices_text='' raid_text='' - from_os_list= [ R.from_os for R in ri_data.Raid.dict.values() if R.from_os == 'no' ] + #from_os_list= [ R.from_os for R in ri_data.Raid.dict.values() if R.from_os == 'no' ] + from_os_list= [ R.from_os for R in ri_data.Raid.dict.values() ] if len(fd_devices) < 2 and not from_os_list : return 0 @@ -481,13 +461,13 @@ class Raid(Screen): return ( s == 'help' and '0' or s) class MountPoint(Screen): - #fs = '' - #dict = {} def __init__(self): Screen.__init__(self, name='mountpoint') self.title = 'MountPoint Configure' self.disks = p_d.Partition.dict.keys() self.disks.sort() + self.mds = ri_data.Raid.dict.keys() + self.mds.sort() def check_mountpoint(self,flag='one'): nonmount_dir = ['/dev','/etc','/lib64','/lib','/bin','/sbin','/proc','/sys'] @@ -507,6 +487,11 @@ class MountPoint(Screen): return True elif flag == 'all': list_mountpoint = [] + for m in ri_data.Raid.dict.keys(): + R = ri_data.Raid.dict[m] + if R.mp != '': + list_mountpoint.append(R.mp) + for d in self.disks: if p_d.Partition.dict[d]['partition_table'] == '': continue @@ -521,21 +506,35 @@ class MountPoint(Screen): def set_mountpoint(self, device): disk = device.split(':')[0] dev = device.split(':')[1] + MD = True if re.search('md',disk) else False Screen.widget_buttonbar(Screen.buttonlist0) Screen.widget_textboxreflowed(30, 'Please input the mountpoint and select the file system type.') Screen.label_mp = Label('mountpoint : ') Screen.label_fs = Label('File System Type : ') Screen.widget_label('') - - Screen.widget_checkbox('Format the partition') - if p_d.Partition.dict[disk]['partition'][dev]['format'] == 'yes': - Screen.checkbox.setValue('*') - fs_list = ['ext2','ext3', 'ext4', 'swap', 'reiserfs', 'xfs', 'jfs'] Screen.widget_listbox(3, *fs_list) + Screen.widget_checkbox('Format the partition') Screen.listbox.setCurrent('ext3') - Screen.widget_entry(15, text=p_d.Partition.dict[disk]['partition'][dev]['mount_point']) + + if MD: + if ri_data.Raid.dict[disk].fmt == 'yes': + Screen.checkbox.setValue('*') + try: + Screen.listbox.setCurrent(ri_data.Raid.dict[disk].filesystem) + except: + pass + Screen.widget_entry(15, text=ri_data.Raid.dict[disk].mp) + else: + if p_d.Partition.dict[disk]['partition'][dev]['format'] == 'yes': + Screen.checkbox.setValue('*') + try: + Screen.listbox.setCurrent(p_d.Partition.dict[disk]['partition'][dev]['filesystem']) + except: + pass + Screen.widget_entry(15, text=p_d.Partition.dict[disk]['partition'][dev]['mount_point']) + Screen.container_grid_complex(3, 2, Screen.label_mp, Screen.entry, Screen.label, Screen.label, Screen.label_fs, Screen.listbox) while True: s = Screen.yesno(self.title, 1, 8, 'TextboxReflowed', 'eLabel', 'Grid_Complex', 'eLabel', 'Checkbox','eLabel','ButtonBar') @@ -543,14 +542,23 @@ class MountPoint(Screen): if not self.check_mountpoint(flag='one'): Screen.pop_window('Invalid mount point','The mount point you entered is invalid.\nMount point must start with "/".They cannot contain spaces.\nMount point cannot be "/dev","/etc","/lib","lib64","/bin","/sbin","/proc","/sys".\n', 50) continue - if Screen.entry.value() != '' or Screen.checkbox.value() == 1: - p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes' + if MD: + if Screen.entry.value() != '' or Screen.checkbox.value() == 1: + ri_data.Raid.dict[disk].fmt = 'yes' + else: + ri_data.Raid.dict[disk].fmt = 'no' + ri_data.Raid.dict[disk].filesystem = Screen.listbox.current() + ri_data.Raid.dict[disk].mp = Screen.entry.value() + break + #p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes' else: + if Screen.entry.value() != '' or Screen.checkbox.value() == 1: + p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes' + else: p_d.Partition.dict[disk]['partition'][dev]['format'] = 'no' - p_d.Partition.dict[disk]['partition'][dev]['filesystem'] = Screen.listbox.current() - p_d.Partition.dict[disk]['partition'][dev]['mount_point'] = Screen.entry.value() - break - #p_d.Partition.dict[disk]['partition'][dev]['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() + break else: break return s @@ -564,6 +572,18 @@ class MountPoint(Screen): 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=5) + for k in ri_data.Raid.dict.keys(): + R = ri_data.Raid.dict[k] + dev = ri_data.Raid.dict[k].device + Screen.clistbox.append(["/dev/%s" %(dev), + "%s" %(R.mp.ljust(10)), + "%s" %(R.filesystem.ljust(10)), + "%s" %(R.fmt.ljust(5)), + "%s" %(ri_data.Raid.get_size(dev))], + "%s:%s" %(dev, 'p'), + [LEFT, LEFT, LEFT, LEFT, CENTER]) + + dev_in_raid = ri_data.Raid.dev_in_raid() for d in self.disks: if p_d.Partition.dict[d]['partition_table'] == '': continue @@ -572,9 +592,8 @@ class MountPoint(Screen): # loop for nest dict to find partition for k in p_d.Partition.dict[d]['partition'].keys(): if p == k: - if p_d.Partition.dict[d]['partition'][p]['type'] == 'extended': + if p_d.Partition.dict[d]['partition'][p]['type'] == 'extended' or p.split('/dev/')[1] in dev_in_raid: 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(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)), @@ -629,7 +648,7 @@ class Network(Screen): setattr(ri_data.Network, 'hostname', Screen.entry.value()) elif t == 'static': - Screen.widget_buttonbar(Screen.buttonlist2) + Screen.widget_buttonbar(Screen.buttonlist1) Screen.widget_textboxreflowed(50, 'Please configure the static net:') Screen.initial_static_net() Screen.container_grid(7, 1, Screen.grid_hostname, Screen.grid_domain, Screen.grid_ip,\ @@ -655,8 +674,8 @@ class Network(Screen): Screen.pop_window('Tips', 'There is something wrong with your input network address.', 30) elif s == -1: break - else: - return (s == 'help' and '0' or s) + #else: + # return (s == 'help' and '0' or s) return s @@ -692,27 +711,16 @@ class Group(Screen): Screen.widget_buttonbar(Screen.buttonlist1) Screen.widget_textboxreflowed(50, 'Please select the software package groups') - #Screen.widget_checkboxlist(g_list) h = 5 if len(g_list) > 5 else len(g_list) Screen.widget_checkboxtree(h, g_list) for g in g_list: if ri_data.Group.dict[g].install == 'yes': - #Screen.d_cbl[g].setValue('*') Screen.checkboxtree.setEntryValue(g, selected=1) - #num_widget = len(g_list) + 4 - - #s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'CheckboxTree', 'eLabel', 'ButtonBar') if s == 0: - #for g in g_list: - # if Screen.d_cbl[g].value() == 1: - # ri_data.Group.dict[g].install='yes' - # ri_data.Group.dict[g].selection='all' - # else: - # ri_data.Group.dict[g].install='no' for g in g_list: if g in Screen.checkboxtree.getSelection(): ri_data.Group.dict[g].install='yes' @@ -732,40 +740,22 @@ class Service(Screen): ri_data.Service.change_state() s_list = ['check all'] - #print ri_data.Service.list for s in ri_data.Service.list: if s.start != 'disable': s_list.append(s.name) - #print s_list Screen.widget_buttonbar(Screen.buttonlist1) Screen.widget_textboxreflowed(50, 'Please select the start services') - #Screen.widget_checkboxlist(s_list) h = 5 if len(s_list) > 5 else len(s_list) Screen.widget_checkboxtree(h, s_list) for service in ri_data.Service.list: if service.start == 'yes': - #Screen.d_cbl[service.name].setValue('*') Screen.checkboxtree.setEntryValue(service.name, selected=1) - #num_widget = len(s_list) + 4 - - #s = Screen.yesno(self.title, 1, num_widget, 'TextboxReflowed', 'eLabel', 'CheckboxList', 'eLabel', 'ButtonBar') s = Screen.yesno(self.title, 1, 5, 'TextboxReflowed', 'eLabel', 'CheckboxTree', 'eLabel', 'ButtonBar') if s == 0: - #if Screen.d_cbl[s_list[0]].value() == 1: - # for service in ri_data.Service.list: - # if service.start != 'disable': - # service.start='yes' - #else: - # for service in ri_data.Service.list: - # if service.start != 'disable': - # if Screen.d_cbl[service.name].value() == 1: - # service.start = 'yes' - # else: - # service.start = 'no' if 'check all' in Screen.checkboxtree.getSelection(): for service in ri_data.Service.list: if service.start != 'disable': @@ -781,9 +771,6 @@ class Service(Screen): return s - - - class Prepar_installation(Screen): def __init__(self): Screen.__init__(self, name='information') @@ -797,25 +784,3 @@ class Prepar_installation(Screen): return s - - - -#SerialNumber() -#s = Screen.dict['serialnumber'].set_data() - -#Welcome() -#s = Screen.dict['welcome'].set_data() - -#Raid() -#s = Screen.dict['raid'].make_raid() -#s = Screen.dict['raid'].raid_raw_to_active() -#s = Screen.dict['raid'].set_data() - -#Network() -#s = Screen.dict['network'].set_data() - -#Screen.screen.finish() - -#print s -#print s -#print Screen.dict diff --git a/interface/ri_data.py b/interface/ri_data.py index 1e0472d..5071a83 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -6,6 +6,7 @@ from xml.dom import minidom from xml.dom.ext import PrettyPrint sys.path.append('../new_partition/') import partition_data as p_d +import interface_partition @@ -197,11 +198,14 @@ p_node - xml node (parent node)''' class Raid: ''' raid information ''' dict = {} - def __init__(self, dev, from_os, level, a_devs, s_devs=[]): + def __init__(self, dev, from_os, level, mp, fmt, filesystem,a_devs, s_devs=[]): ''' Raid init function ''' self.device = dev self.from_os = from_os self.level = level + self.mp = mp + self.fmt = fmt + self.filesystem = filesystem self.active_components = a_devs self.spare_components = s_devs Raid.dict[dev] = self @@ -232,7 +236,7 @@ class Raid: else: act_cmpts.append(ss[:ss.index('[')]) - Raid(raid_dev, "yes", raid_level, act_cmpts, spr_cmpts) + Raid(raid_dev, "yes", raid_level, '', 'no', '', act_cmpts, spr_cmpts) @staticmethod def add_component(node, l): @@ -252,6 +256,9 @@ l - list raid_dev = e.attributes['device'].value raid_from = e.attributes['from_os'].value raid_level = e.attributes['level'].value + raid_mp = e.attributes['mp'].value + raid_fmt = e.attributes['fmt'].value + raid_fs = e.attributes['filesystem'].value act_cmpts = [] spr_cmpts = [] for sub_e in e.childNodes: @@ -261,7 +268,7 @@ l - list elif sub_e.nodeName == 'spare': Raid.add_component(sub_e, spr_cmpts) - Raid(raid_dev, raid_from, raid_level, act_cmpts, spr_cmpts) + Raid(raid_dev, raid_from, raid_level, raid_mp, raid_fmt, raid_fs, act_cmpts, spr_cmpts) @staticmethod def to_xml(doc, p_node): @@ -287,6 +294,18 @@ p_node - xml node (parent node) ''' rd_level_attr.value = r.level rd.setAttributeNode(rd_level_attr) + rd_mp_attr = doc.createAttribute('mp') + rd_mp_attr.value = r.mp + rd.setAttributeNode(rd_mp_attr) + + rd_fmt_attr = doc.createAttribute('fmt') + rd_fmt_attr.value = r.fmt + rd.setAttributeNode(rd_fmt_attr) + + rd_fs_attr = doc.createAttribute('filesystem') + rd_fs_attr.value = r.filesystem + rd.setAttributeNode(rd_fs_attr) + rd_act_elem = doc.createElement('active') for act_c in r.active_components: act_c_e = doc.createElement('component') @@ -311,10 +330,11 @@ p_node - xml node (parent node) ''' def get_size(dev): ''' calculate raid device size ''' rd = Raid.dict[dev] - sz = min([ float(Partition.dict[d].size) for d in rd.active_components]) - if rd.level == '0': return str(sz*len(rd.active_components)) - elif rd.level == '1': return str(sz*len(rd.active_components)/2) - elif rd.level == '5': return str(sz*(len(rd.active_components)-1)) + sz = min([ float(interface_partition.get_num(p_d.Partition.dict[p_d.Partition.get_disk_from_partition('/dev/'+d)]\ + ['partition']['/dev/'+d]['size'])) for d in rd.active_components]) + if rd.level == '0': return str(interface_partition.pretty_unit(sz*len(rd.active_components))) + elif rd.level == '1': return str(interface_partition.pretty_unit(sz*len(rd.active_components)/2)) + elif rd.level == '5': return str(interface_partition.pretty_unit(sz*(len(rd.active_components)-1))) @staticmethod def get_next_device(): @@ -335,6 +355,13 @@ p_node - xml node (parent node) ''' devices_in_raid.update(r.spare_components) return devices_in_raid + @staticmethod + def get_raid_from_partition(partition): + for raid in Raid.dict.keys(): + for p in Raid.dict[raid].active_components + Raid.dict[Raid].spare.components: + if p == partition: + return raid + class MountPoint: ''' mount-points ''' dict={} @@ -677,7 +704,7 @@ def prepar_installation(): def init(): ''' initialize ''' Partition.init_from_os() - Raid.init_from_os() + #Raid.init_from_os() MountPoint.init_from_internal() xmldoc_cfg = minidom.parse(config_xml) root_cfg = xmldoc_cfg.firstChild diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 2017bbc..73b1920 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -87,6 +87,7 @@ class Operation: process.stdin.close() while True: line = process.stdout.readline() + print line if not line: break if line[0] == '@' and self.current_step < self.steps: @@ -167,6 +168,9 @@ class Format(Operation): n = 0 disks = p_d.Partition.dict.keys() disks.sort() + mds = ri_data.Raid.dict.keys() + mds.sort() + for d in disks: partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition') for p in partitions: @@ -175,6 +179,13 @@ class Format(Operation): if fmt.strip() == 'yes' and fs_type.strip(): format += "%s %s\n" %(p, fs_type) n += 1 + for m in mds: + R = ri_data.Raid.dict[m] + fs_type = R.filesystem + fmt = R.fmt + if fmt.strip() == 'yes' and fs_type.strip(): + format += "/dev/%s %s\n" %(m, fs_type) + n += 1 self.steps += n return format @@ -231,6 +242,8 @@ class Mount(Operation): n = 0 disks = p_d.Partition.dict.keys() disks.sort() + mds = ri_data.Raid.dict.keys() + mds.sort() for d in disks: partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition') for p in partitions: @@ -239,6 +252,14 @@ class Mount(Operation): if mp.strip() and fs.strip(): mount += "%s %s %s\n" %(p, mp, fs) n += 1 + for m in mds: + R = ri_data.Raid.dict[m] + mp = R.mp + fs = R.filesystem + if mp.strip() and fs.strip(): + mount += "/dev/%s %s %s\n" %(m, mp, fs) + n += 1 + self.steps += n return mount @@ -271,6 +292,9 @@ class ConfigureFstab(Mount): fstab='' disks = p_d.Partition.dict.keys() disks.sort() + mds = ri_data.Raid.dict.keys() + mds.sort() + for d in disks: partitions = p_d.sort_partitions(p_d.Partition.dict, d, 'partition') for p in partitions: @@ -281,6 +305,15 @@ class ConfigureFstab(Mount): mp = 'swap' if mp.strip() and fs.strip(): fstab += "%s %s %s\n" %(p, mp, fs) + for m in mds: + R = ri_data.Raid.dict[m] + mp = R.mp + fs = R.filesystem + if fs.strip() == 'linux-swap': + fs = 'swap' + mp = 'swap' + if mp.strip() and fs.strip(): + fstab += "/dev/%s %s %s\n" %(m, mp, fs) # process fstab to sort fstab_new = '' diff --git a/new_partition/interface_partition.py b/new_partition/interface_partition.py index c1d4604..a8ee918 100755 --- a/new_partition/interface_partition.py +++ b/new_partition/interface_partition.py @@ -4,6 +4,9 @@ import gettext, sys, os, re, string, time import partition_data as p_d +sys.path.append('../interface/') +import ri_data + global base_unit base_unit = 's' @@ -141,6 +144,9 @@ def showPartitionWindow(): partition_table = p_d.Partition.dict[dev]['partition_table'] dev_size = p_d.Partition.dict[dev]['disk_size'] + if re.search('/dev/md/',dev): + continue + clb.append(["%s" %(dev),"","","","",""], \ "dev:%s:%s" %(dev,dev_size), [LEFT, RIGHT, RIGHT, RIGHT, LEFT, LEFT]) @@ -160,10 +166,17 @@ def showPartitionWindow(): ptype = p_d.Partition.dict[dev]['partition'][partition]['type'] flags = p_d.Partition.dict[dev]['partition'][partition]['flags'] + try: + partition_name = partition.split('/dev/')[1] + if partition_name in ri_data.Raid.dev_in_raid(): + continue + except: + pass + try: if base_unit == 's': if (float(get_num(size)) < 2000000/512.0 and float(get_num(start)) < 2048) \ - or float(get_num(size)) < 40: + or float(get_num(size)) < 2048: continue except: pass @@ -218,6 +231,23 @@ def show_error(tips): g21.add(Button("OK"), 0, 1) g21.runOnce() +def del_raid(dev): + md = '' + try: + for partition in p_d.sort_partitions(p_d.Partition.dict, dev, 'partition'): + for raid in ri_data.Raid.dict.keys(): + for p in ri_data.Raid.dict[raid].active_components + ri_data.Raid.dict[raid].spare_components: + if p == partition.split('/dev/')[1]: + md = raid + del ri_data.Raid.dict[md] + raise StopIteration() + except StopIteration: + pass + try: + os.system('mdadm --stop /dev/%s >/dev/null 2>&1' %(md)) + except: + pass + def ask_dialog(tips,dev): g21 = GridForm(screen, "Warning", 1, 3) g21.add(TextboxReflowed(45, "%s" %(tips)),0,0) @@ -228,6 +258,9 @@ def ask_dialog(tips,dev): res4 = g21.runOnce() if bb4.buttonPressed(res4) == "continue": p_d.Partition.dict[dev]['from_os'] = 'no' + for p in p_d.sort_partitions(p_d.Partition.dict, dev, 'partition'): + p_d.Partition.dict[dev]['partition'][p]['from_os'] = 'no' + del_raid(dev) return True else: return False @@ -1289,6 +1322,8 @@ def main(): if bb1.buttonPressed(res1) == "ok": label = rb.getSelection() p_d.Partition.dict[dev]['partition_table'] = label + + del_raid(dev) #os.system('parted -s %s mklabel %s' %(dev,label)) p_d.delete_all_partitions(p_d.Partition.dict, dev) @@ -1297,9 +1332,6 @@ 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] @@ -1313,8 +1345,8 @@ def main(): and float(get_num(free_space_end)) <= float(get_num(extended_end)): ptype = 'logical' add_partition(ptype, 'extended', 'msdos') - 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 !") + #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: show_error('You can not add new primary or extended partition any more !') @@ -1330,9 +1362,6 @@ 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] @@ -1342,11 +1371,11 @@ def main(): re.search("dev:", clb.current()) == None and \ bb.buttonPressed(res) == "delete": dev = clb.current().split(":")[2] - if p_d.Partition.dict[dev]['from_os'] != 'no': + partition = clb.current().split(":")[1] + if p_d.Partition.dict[dev]['from_os'] != 'no' and p_d.Partition.dict[dev]['partition'][partition]['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': del_msdos_partition(partition, dev) diff --git a/new_partition/partition_data.py b/new_partition/partition_data.py index bb48a15..5baad7c 100755 --- a/new_partition/partition_data.py +++ b/new_partition/partition_data.py @@ -329,12 +329,20 @@ p_node - xml node (parent node)''' except: return None + @staticmethod + def get_disk_from_partition(partition): + for d in Partition.dict: + for p in Partition.dict[d]['partition']: + if p == partition: + return d + @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': + #if Partition.dict[key]['partition'][k]['flags'] == 'raid': + if re.search('raid',Partition.dict[key]['partition'][k]['flags']): rd.append(k) return rd @@ -465,8 +473,9 @@ def init_from_xml(): -#if __name__ == "__main__": - #Partition.init_from_os(unit='s') +if __name__ == "__main__": + Partition.init_from_os(unit='s') + print Partition.get_disk_from_partition('/dev/sdc7') #for d in Partition.get_raid_devices(): # print d #print Partition.dict.keys()