From e8934228dc7ed201158e6ec51e2d26be7fd66bde Mon Sep 17 00:00:00 2001 From: lizhi-rocky Date: Mon, 18 Oct 2010 16:30:46 +0800 Subject: [PATCH] reset ri_data.py & ri_tk_cmd.py. These 2 files shall be modified by Li Zhi. --- interface/ri_data.py | 272 ++++++++++++++++++++--------------------- interface/ri_tk_cmd.py | 169 ++++++++++++++----------- 2 files changed, 233 insertions(+), 208 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index 978f549..ee64be3 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -1,7 +1,6 @@ #!/usr/bin/python import re -import sys import commands from xml.dom import minidom from xml.dom.ext import PrettyPrint @@ -41,7 +40,8 @@ p_node - xml node (parent node)''' class Partition: ''' disk partition ''' unit='' - dict={} + label='' + list=[] def __init__(self, dev, st, sz, tp, fs, fg, fr): ''' Partition init function ''' self.device = dev @@ -49,87 +49,69 @@ class Partition: self.size = sz self.type = tp self.filesystem = fs - self.israid = fg + self.flags = fg self.from_os = fr - Partition.dict[dev] = self + Partition.list.append(self) @staticmethod def init_from_os(): ''' create a Partition instance from hardware info''' - Partition.unit='MB' + device_list=[] + Partition.unit='GB' + p = re.compile(r"\s*") cmd_cat = 'cat /proc/partitions' + fs_list=["ext2","ext3","fat32","fat16","ntfs","reiserfs","xfs","jfs","linux-swap"] st,o = commands.getstatusoutput(cmd_cat) if st: print "Error cat : command not found or /proc/partitions dosen't exsit" return + for s in o.splitlines(): + ret = re.search(r".+([sh][a-zA-Z]+)\s*",s) + if ret: + if ret.group(1) in device_list: + continue + device_list.append(ret.group(1)) - # an example of `cat /proc/partitions` - # major minor #blocks name - # - # 8 0 488386584 sda - # 8 1 97659103 sda1 - # 8 2 1951897 sda2 - # 8 3 97659135 sda3 - # 8 4 291113865 sda4 - # 8 16 244197527 sdb - # 8 17 62918541 sdb1 - # 8 18 4200997 sdb2 - # 8 19 1 sdb3 - # 8 21 1238016 sdb5 - # 9 0 803136 md0 - - l = [ s.split()[-1] for s in o.splitlines() if re.match(r'\s*\d+', s)] - # devices : 1) sda, sdb(first if ), or md0 (second if) - for d in [ i for i in l if not re.search(r'\d+', i)\ - or re.search(r'([a-zA-Z]+)', i).group(1) not in l]: - st,o=commands.getstatusoutput('parted /dev/%s unit %s print'%(d,Partition.unit)) - if st: - print "Error parted execute error" - return - # an example of o's content - # Model: ATA Hitachi HDS72105 (scsi) - # Disk /dev/sda: 500GB - # Sector size (logical/physical): 512B/512B - # Partition Table: msdos - # - # Number Start End Size Type File system Flags - # 1 0.00GB 100GB 100GB primary ext3 boot - # 2 100GB 102GB 2.00GB primary linux-swap(v1) - # 3 102GB 202GB 100GB primary ext3 - # 4 202GB 500GB 298GB primary ext3 - - located = False - for s in o.splitlines(): - # Only match number, start, end, and size, that's enough. - # And when in raid case, no type appears. - title_p = re.compile('Number\s+Start\s+End\s+Size\s') - if title_p.match(s): - nm_i = s.find('Number') - st_i = s.find('Start') - end_i = s.find('End') - sz_i = s.find('Size') - tp_i = s.find('Type') - fs_i = s.find('File system') - flg_i= s.find('Flags') - if tp_i < 0: tp_i=fs_i - located = True - continue - - if located: - Partition(d+s[nm_i:st_i].strip(), # device name - s[st_i:end_i].strip().rstrip(Partition.unit), # start - s[sz_i:tp_i].strip().rstrip(Partition.unit), # size - s[tp_i:fs_i].strip(), # type - re.search('swap', s[fs_i:flg_i]) and 'swap' or s[fs_i:flg_i].strip(), # file system - re.search('raid',s[flg_i:]) and 'yes' or 'no', # flags - "yes" #from os - ) + for d in device_list: + st,o=commands.getstatusoutput('parted /dev/%s unit %s print'%(d,Partition.unit)) + if st: + print "Error parted :command not found" + return + for s in o.splitlines(): + ret = p.split(s) + if ret[0]=='Partition': + Partition.label=ret[-1] + if len(ret) > 1 and ret[1].isdigit(): + # ret[0] is [''] + #Number start end size type file_system flags + # 1 2.0B 33GB 1GB primary raid + # 2 32GB 33GB 1GB primary raid, boot ... + # 3 32GB 33GB 1GB primary boot, raid, lbx ... + # 4 32GB 33GB 1GB primary exit2 raid + # 5 32GB 33GB 1GB primary exit2 raid, boot ... + # 6 3.2kB 33GB 1GB primary + # 7 32GB 33GB 1GB primary linx-swap + # 8 32GB 33GB 1GB primary boot, lbx ... + # 9 32GB 33GB 1GB primary exit2 boot + #ret[1] ret[2] ret[3] ret[4] ret[5] ret[6] ret[7] + ret+=['','',''] + if "raid" in ret[6:] or "raid," in ret[6:]: + ret[7]='yes' + if ret[6][:3].lower()=='raid' or ret[6].lower() not in fs_list: + ret[6]='' + else: + ret[7]='no' + if ret[6].lower() not in fs_list: + ret[6]='' + Partition(d+ret[1],ret[2],ret[4],ret[5],ret[6][:10] == "linux-swap" and "swap" or ret[6] ,ret[7],'yes') + @staticmethod def init_from_xml(node): ''' create Partition instances from xml node ''' Partition.unit = node.attributes['unit'].value.encode('ascii') + Partition.label = node.attributes['label'].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'),\ @@ -137,7 +119,7 @@ class Partition: p.attributes['size'].value.encode('ascii'),\ p.attributes['type'].value.encode('ascii'),\ p.attributes['file-system'].value.encode('ascii'),\ - p.attributes['israid'].value.encode('ascii'),\ + p.attributes['flags'].value.encode('ascii'),\ p.attributes['from_os'].value.encode('ascii')) @@ -150,62 +132,72 @@ p_node - xml node (parent node)''' unit_attr = doc.createAttribute('unit') unit_attr.value = Partition.unit pts.setAttributeNode(unit_attr) - for p in Partition.dict.values(): + label_attr = doc.createAttribute('label') + label_attr.value = Partition.label + pts.setAttributeNode(label_attr) + for p in Partition.list: pt = doc.createElement('partition') dev_attr = doc.createAttribute('device') start_attr = doc.createAttribute('start') size_attr = doc.createAttribute('size') type_attr = doc.createAttribute('type') fs_attr = doc.createAttribute('file-system') - israid_attr = doc.createAttribute('israid') + flags_attr = doc.createAttribute('flags') from_attr = doc.createAttribute('from_os') dev_attr.value = p.device start_attr.value = p.start size_attr.value = p.size type_attr.value = p.type fs_attr.value = p.filesystem - israid_attr.value = p.israid + flags_attr.value = p.flags from_attr.value = p.from_os pt.setAttributeNode(dev_attr) pt.setAttributeNode(start_attr) pt.setAttributeNode(size_attr) pt.setAttributeNode(type_attr) pt.setAttributeNode(fs_attr) - pt.setAttributeNode(israid_attr) + pt.setAttributeNode(flags_attr) pt.setAttributeNode(from_attr) pts.appendChild(pt) p_node.appendChild(pts) - + # ri_tk_cmd.py use @staticmethod def get_size(dev): - # maybe add raid not in Partition.dict - if Partition.dict.has_key(dev): - return Partition.dict[dev].size - return + for p in Partition.list: + if p.device == dev: + return p.size class Raid: ''' raid information ''' - dict = {} - def __init__(self, dev, from_os, level, a_devs, s_devs=[]): + list = [] + def __init__(self, dev, from_os, level, sz, a_devs, s_devs=[]): ''' Raid init function ''' self.device = dev self.from_os = from_os self.level = level + self.size = sz self.active_components = a_devs self.spare_components = s_devs - Raid.dict[dev] = self + Raid.list.append(self) @staticmethod def init_from_os(): cmd = 'cat /proc/mdstat' st, o = commands.getstatusoutput(cmd) - if st: return + if st: + return dev_p = re.compile(r''' ^(md\d+)\s*: # md device \s*active\s* # "active" (\w+)\s* # raid type ''', re.VERBOSE) + size_p = re.compile(r''' + ^\s*(\d+) # block number + \s*blocks + ''', re.VERBOSE) + + for s in o.splitlines(): dev_res = dev_p.split(s) if len(dev_res)>1: # matched @@ -219,8 +211,15 @@ class Raid: spr_cmpts.append(ss[:ss.index('[')]) else: act_cmpts.append(ss[:ss.index('[')]) + size = size_p.match(s) + if size is not None: + raid_size = size.groups()[0] + # if already detect a raid dev + if raid_dev: + Raid(raid_dev, "yes", raid_level, raid_size, act_cmpts, spr_cmpts) + # clear raid dev + raid_dev='' - Raid(raid_dev, "yes", raid_level, act_cmpts, spr_cmpts) @staticmethod def add_component(node, l): @@ -240,6 +239,7 @@ l - list raid_dev = e.attributes['device'].value raid_from = e.attributes['from_os'].value raid_level = e.attributes['level'].value + raid_size = e.attributes['size'].value act_cmpts = [] spr_cmpts = [] for sub_e in e.childNodes: @@ -249,7 +249,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_size, act_cmpts, spr_cmpts) @staticmethod def to_xml(doc, p_node): @@ -257,7 +257,7 @@ l - list doc - xml document instance p_node - xml node (parent node) ''' raids = doc.createElement('raids') - for r in Raid.dict.values(): + for r in Raid.list: rd = doc.createElement('raid') rd_dev_attr = doc.createAttribute('device') @@ -272,6 +272,10 @@ p_node - xml node (parent node) ''' rd_level_attr.value = r.level rd.setAttributeNode(rd_level_attr) + rd_size_attr = doc.createAttribute('size') + rd_size_attr.value = r.size + rd.setAttributeNode(rd_size_attr) + rd_act_elem = doc.createElement('active') for act_c in r.active_components: act_c_e = doc.createElement('component') @@ -291,87 +295,77 @@ p_node - xml node (parent node) ''' raids.appendChild(rd) p_node.appendChild(raids) - + #ri_tk_cmd.py use @staticmethod def get_size(dev): - sz = sys.maxint - level = Raid.dict[dev].level - active = Raid.dict[dev].active_components - for d in active: - if float(Partition.dict[d].size) < float(sz): - sz=float(Partition.dict[d].size) - if level == '0': - sz=sz*len(active) - return str(sz) - elif level == '1': - sz=(len(active) * sz) / 2 - return str(sz) - elif level == '5': - sz=sz*(len(active)-1) - return str(sz) + for r in Raid.list: + if r.device == dev: + return r.size @staticmethod def get_next_device(): ''' get next available raid device name ''' num_p = re.compile(r'md(\d+)') - numbers = [ int(num_p.match(r).groups()[0]) for r in Raid.dict.keys() ] + numbers = [ int(num_p.match(r.device).groups()[0]) for r in Raid.list ] max = 0 for n in numbers: if n > max: max = n return 'md%d' %(max+1) - @staticmethod - def dev_in_raid(): - """if the device in raid or not""" - devices_in_raid=set() - for r in Raid.dict.values(): - devices_in_raid.update(r.active_components) - devices_in_raid.update(r.spare_components) - return devices_in_raid - class MountPoint: ''' mount-points ''' - dict={} - def __init__(self, dev, dir='', fs='', fm='no'): + list=[] + def __init__(self, dev, dir='', fs='', fm='no', sz='0'): self.device = dev self.directory = dir self.filesystem = fs self.format = fm - MountPoint.dict[dev]=self + self.size = sz + MountPoint.list.append(self) @staticmethod def change(dev, dir, fs, fm): - mp = MountPoint.dict[dev] - mp.directory = dir - mp.filesystem = fs - mp.format = fm + for mp in MountPoint.list: + if mp.device == dev: + mp.directory = dir + mp.filesystem = fs + mp.format = fm + + def device(self): + return self.device + @staticmethod def init_from_internal(): ''' init MountPoint from internal class Partition and class Raid ''' - # add raid device in dev_in_raid - dev_in_raid = Raid.dev_in_raid() + # add raid device in dev_in_raid + dev_in_raid = set() + for r in Raid.list: + dev_in_raid.update(r.active_components) + dev_in_raid.update(r.spare_components) - for dev in set(Partition.dict.keys()).difference(set(dev_in_raid)): - if MountPoint.dict.has_key(dev): continue - MountPoint(dev, fs=Partition.dict[dev].filesystem) + devs = [ m.device for m in MountPoint.list ] + for p in Partition.list: + if p.device not in devs and p.device not in dev_in_raid : + MountPoint(p.device,fs=p.filesystem,sz=p.size) + + for r in Raid.list: + if r.device not in devs and r.from_os == 'yes': + f_s = [p.filesystem for p in Partition.list if p.device == r.active_components[0]] + MountPoint(r.device, fs=''.join(f_s),sz=r.size) + elif r.device not in devs: + MountPoint(r.device,sz=r.size) - for dev in Raid.dict.keys(): - if MountPoint.dict.has_key(dev): - continue - MountPoint(dev) - # adding a raid device, the partition which is raid.active or raid.spare must be deleted - for d in Raid.dict[dev].active_components + Raid.dict[dev].spare_components: - if not MountPoint.dict.has_key(d):continue - del MountPoint.dict[d] - # now process whether a partition or raid was removed - # process has been tested. result's only remove raid device - s1 = set(MountPoint.dict.keys()) - s2 = set(Partition.dict.keys() + Raid.dict.keys()) + s1 = set([ m.device for m in MountPoint.list ]) + s2 = set([ p.device for p in Partition.list ] + [ r.device for r in Raid.list]) for dev in s1-s2: - if MountPoint.dict.has_key(dev): - del MountPoint.dict[dev] + for i in range(len(MountPoint.list)): + if dev == MountPoint.list[i].device: + del MountPoint.list[i] + break + # sort + MountPoint.list.sort(key=MountPoint.device) @staticmethod def init_from_xml(node): @@ -381,7 +375,8 @@ class MountPoint: MountPoint(m.attributes['device'].value.encode('ascii'), \ m.attributes['directory'].value.encode('ascii'), \ m.attributes['file-system'].value.encode('ascii'), \ - m.attributes['format'].value.encode('ascii')) + m.attributes['format'].value.encode('ascii'),\ + m.attributes['size'].value.encode('ascii')) @staticmethod def to_xml(doc, p_node): @@ -389,20 +384,23 @@ class MountPoint: doc - xml document instance p_node - xml node (parent node)''' mps = doc.createElement('mount-points') - for m in MountPoint.dict.values(): + for m in MountPoint.list: mp = doc.createElement('mount-point') dev_attr = doc.createAttribute('device') dir_attr = doc.createAttribute('directory') fs_attr = doc.createAttribute('file-system') fm_attr = doc.createAttribute('format') + sz_attr = doc.createAttribute('size') dev_attr.value = m.device dir_attr.value = m.directory fs_attr.value = m.filesystem fm_attr.value = m.format + sz_attr.value = m.size mp.setAttributeNode(dev_attr) mp.setAttributeNode(dir_attr) mp.setAttributeNode(fs_attr) mp.setAttributeNode(fm_attr) + mp.setAttributeNode(sz_attr) mps.appendChild(mp) p_node.appendChild(mps) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 9db87a8..7914c86 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -18,16 +18,21 @@ def serial_no_quit(): def mount_list_init(): ''' initialize mount list ''' + dev_in_raid = set() l = [] + for r in ri_data.Raid.list: + dev_in_raid.update(r.active_components) + dev_in_raid.update(r.spare_components) ri_data.MountPoint.init_from_internal() - for m in ri_data.MountPoint.dict.values(): + for m in ri_data.MountPoint.list: # get size from Partition info + if m.device in dev_in_raid: + continue sz = ri_data.Partition.get_size(m.device) if not sz: sz = ri_data.Raid.get_size(m.device) - s = m.device.ljust(10) + m.directory.ljust(10) + m.filesystem.ljust(10) + m.format.ljust(4) + sz.ljust(6)+ri_data.Partition.unit + s = m.device.ljust(10) + m.directory.ljust(10) + m.filesystem.ljust(10) + m.format.ljust(4) + sz.ljust(6) l.append(s) - l.sort() display.var_dict['mount.list'].set(value=tuple([str(i) for i in l])) def mount_list_modify(*args): @@ -38,25 +43,27 @@ def mount_list_modify(*args): def mp_top_init(): ''' mount dir top window initialize ''' ml_win = ri_widget.Widget.dict['mount.list'].tk_widget - get_dev = ml_win.selection_get().split(' ')[0] - mp = ri_data.MountPoint.dict[get_dev] - dev = mp.device - dir = mp.directory - fs = mp.filesystem - fm = mp.format - sz = ri_data.Partition.dict.has_key(dev) and ri_data.Partition.dict[dev].size or ri_data.Raid.get_size(dev) - display.var_dict['mp_top_dev'].set(value=dev) - display.var_dict['mp_top_size'].set(value=sz) - display.var_dict['mp_top_dir'].set(value=dir) - if fm == 'yes': - ri_widget.Widget.dict['mp_top_format'].tk_widget.select() - else: - ri_widget.Widget.dict['mp_top_not_format'].tk_widget.select() + idxs = ml_win.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + mp = ri_data.MountPoint.list[idx] + dev = mp.device + dir = mp.directory + fs = mp.filesystem + fm = mp.format + sz = mp.size + display.var_dict['mp_top_dev'].set(value=dev) + display.var_dict['mp_top_size'].set(value=sz) + display.var_dict['mp_top_dir'].set(value=dir) + if fm == 'yes': + ri_widget.Widget.dict['mp_top_format'].tk_widget.select() + else: + ri_widget.Widget.dict['mp_top_not_format'].tk_widget.select() - fs_values = eval(display.var_dict['mp_top_fs'].get()) - for i in range(len(fs_values)): - if fs == fs_values[i]: - ri_widget.Widget.dict['mp_top_fs'].tk_widget.selection_set(i) + fs_values = eval(display.var_dict['mp_top_fs'].get()) + for i in range(len(fs_values)): + if fs == fs_values[i]: + ri_widget.Widget.dict['mp_top_fs'].tk_widget.selection_set(i) def mp_top_ok(): ''' mount dir top window OK ''' @@ -70,15 +77,15 @@ def mp_top_ok(): dir = display.var_dict['mp_top_dir'].get() fm = display.var_dict['mp_top_format'].get() idxs2 = ri_widget.Widget.dict['mp_top_fs'].tk_widget.curselection() - for m in ri_data.Partition.dict.values(): - if m.device == dev2: - base_fs = m.filesystem + for m in ri_data.Partition.list: + if m.device == dev2: + base_fs = m.filesystem if len(idxs2) and fm =='yes' : - idx2 = int(idxs2[0]) - fs = eval(display.var_dict['mp_top_fs'].get())[idx2] + idx2 = int(idxs2[0]) + fs = eval(display.var_dict['mp_top_fs'].get())[idx2] elif fm=='no': - fs = base_fs - s2 = dev.ljust(10) + dir.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6)+ri_data.Partition.unit + fs = base_fs + s2 = dev.ljust(10) + dir.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6) l.append(s2) # make change in internal data structure ri_data.MountPoint.change(dev2, dir, fs, fm) @@ -259,9 +266,13 @@ def raid_raw_init(): if not raid_raw_initialized: raid_raw_initialized = True # get all component devices already in raid - devs=ri_data.Raid.dev_in_raid() - raw_devs = [ p.device for p in ri_data.Partition.dict.values() - if p.israid=='yes' and p.device not in devs ] + dev_in_raid = set() + for r in ri_data.Raid.list: + dev_in_raid.update(r.active_components) + dev_in_raid.update(r.spare_components) + + raw_devs = [ p.device for p in ri_data.Partition.list + if p.flags=='yes' and p.device not in dev_in_raid ] display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) def list_to_list(list_from, var_from, var_to): @@ -279,7 +290,6 @@ def list_to_list(list_from, var_from, var_to): l_to.append(itm) else: l_to = [ itm ] - l_to.sort() display.var_dict[var_to].set(value=tuple(l_to)) def raid_raw_to_active(): @@ -300,37 +310,49 @@ def raid_spare_to_raw(): def raid_device_init(): ''' initialize raid device list ''' - raid_devs = [ d for d in ri_data.Raid.dict.keys()] - raid_devs.sort() + raid_devs = [ r.device for r in ri_data.Raid.list ] display.var_dict['raid_devs'].set(value=tuple(raid_devs)) +def raid_calc_size(level, devs): + ''' calculate raid device size +level - raid level (0/1/5) +devs - raid component devices +''' + # all devs shall have same size. + unit=ri_data.Partition.unit + sz=99999999999 + for p in ri_data.Partition.list: + if p.device in devs: + if float(p.size[:-len(unit)])< float(sz): + sz = float(p.size[:-len(unit)]) + if level == '0': + sz=sz*len(devs) + return "%d%s"%(sz,unit) + elif level == '1': + return "%d%s"%(sz,unit) + elif level == '5': + sz=sz*(len(devs)-1) + return "%d%s"%(sz,unit) + def raid_device_add(): ''' add a new raid device ''' if display.var_dict['raid_active_devs'].get()=='': - active=[] + ri_widget.MessageBox.dict["raid_add_active_warning"].show() + return else: active = list(eval(display.var_dict['raid_active_devs'].get())) - if display.var_dict['raid_spare_devs'].get()=='': spare=[] else: spare = list(eval(display.var_dict['raid_spare_devs'].get())) - level = display.var_dict['raid_level'].get() if not active or not level: ri_widget.MessageBox.dict["raid_add_warning"].show() return - elif int(level) < 2 and len(active) < 2: - ri_widget.MessageBox.dict["raid_add_active_numbers"].show() - return - elif str(level) == "5" and len(active)<3: - ri_widget.MessageBox.dict["raid_add_active_2numbers"].show() - return dev = ri_data.Raid.get_next_device() - ri_data.Raid(dev, "no", level,active, spare) - + ri_data.Raid(dev, "no", level, raid_calc_size(level, active), active, spare) raid_device_init() display.var_dict['raid_active_devs'].set(value='') display.var_dict['raid_spare_devs'].set(value='') @@ -341,36 +363,42 @@ def raid_device_add(): def raid_device_delete(): ''' delete a raid device, put its component devices into active/spare device list ''' win_dev = ri_widget.Widget.dict['raid_dev.list'].tk_widget - get_dev=win_dev.selection_get() - r = ri_data.Raid.dict[get_dev] - if r.from_os == 'yes': - ri_widget.MessageBox.dict["raid_delete_warning"].show() - return - if display.var_dict['raid_active_devs'].get() == '': - active=[] - else: - active = list(eval(display.var_dict['raid_active_devs'].get())) - if display.var_dict['raid_spare_devs'].get()=='': - spare=[] - else: - spare = list(eval(display.var_dict['raid_spare_devs'].get())) + idxs = win_dev.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + r = ri_data.Raid.list[idx] + if r.from_os == 'yes': + ri_widget.MessageBox.dict["raid_delete_warning"].show() + return + if display.var_dict['raid_active_devs'].get() == '': + active=[] + else: + active = list(eval(display.var_dict['raid_active_devs'].get())) + if display.var_dict['raid_spare_devs'].get()=='': + spare=[] + else: + spare = list(eval(display.var_dict['raid_spare_devs'].get())) - active.extend(r.active_components) - spare.extend(r.spare_components) - # do not touch level - display.var_dict['raid_active_devs'].set(value=tuple(active)) - display.var_dict['raid_spare_devs'].set(value=tuple(spare)) - del ri_data.Raid.dict[get_dev] - raid_device_init() + active.extend(r.active_components) + spare.extend(r.spare_components) + # do not touch level + display.var_dict['raid_active_devs'].set(value=tuple(active)) + display.var_dict['raid_spare_devs'].set(value=tuple(spare)) + del ri_data.Raid.list[idx] + raid_device_init() def raid_device_list_detail(*args): ''' show details of a raid device ''' win = ri_widget.Widget.dict['raid_dev.list'].tk_widget - get_dev = win.selection_get() - r = ri_data.Raid.dict[get_dev] - display.var_dict['raid_detail_active'].set(value='active: %s' %(str(r.active_components))) - display.var_dict['raid_detail_spare'].set(value='spare: %s' %(str(r.spare_components))) - display.var_dict['raid_detail_level'].set(value='level: %s' %(str(r.level))) + idxs = win.curselection() + if len(idxs) == 1: + idx = int(idxs[0]) + r = ri_data.Raid.list[idx] + display.var_dict['raid_detail_active'].set(value='active: %s' %(str(r.active_components))) + display.var_dict['raid_detail_spare'].set(value='spare: %s' %(str(r.spare_components))) + display.var_dict['raid_detail_level'].set(value='level: %s' %(str(r.level))) + +raid_raw_initialized = False def install_information_init(): '''install information initialize''' @@ -378,4 +406,3 @@ def install_information_init(): t= ri_widget.Widget.dict['install_information.list'].tk_widget t.insert(1.0,ins_info) -raid_raw_initialized = False