From dd9762c629ded166d21bb42256379f26020b32c8 Mon Sep 17 00:00:00 2001 From: fling Date: Wed, 13 Oct 2010 19:31:19 +0800 Subject: [PATCH 01/37] modified: ri_data.py modified: ri_tk_cmd.py The size of from os that must be value. --- interface/ri_data.py | 33 ++++++++++++++++++--------------- interface/ri_tk_cmd.py | 12 ++++++------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index ee64be3..8257f4e 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -49,7 +49,7 @@ class Partition: self.size = sz self.type = tp self.filesystem = fs - self.flags = fg + self.israid = fg self.from_os = fr Partition.list.append(self) @@ -84,18 +84,21 @@ class 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 + #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 ... + # 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 ... + # 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[1] ret[2] ret[3] ret[4] ret[5] ret[6] ret[7] ret+=['','',''] + ret[2]=ret[2][:-len(Partition.unit)] + ret[3]=ret[3][:-len(Partition.unit)] + ret[4]=ret[4][:-len(Partition.unit)] 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: @@ -119,7 +122,7 @@ class Partition: 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['israid'].value.encode('ascii'),\ p.attributes['from_os'].value.encode('ascii')) @@ -142,21 +145,21 @@ p_node - xml node (parent node)''' size_attr = doc.createAttribute('size') type_attr = doc.createAttribute('type') fs_attr = doc.createAttribute('file-system') - flags_attr = doc.createAttribute('flags') + israid_attr = doc.createAttribute('israid') 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 - flags_attr.value = p.flags + israid_attr.value = p.israid 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(flags_attr) + pt.setAttributeNode(israid_attr) pt.setAttributeNode(from_attr) pts.appendChild(pt) p_node.appendChild(pts) @@ -373,10 +376,10 @@ class MountPoint: for m in node.childNodes: if m.nodeType == node.ELEMENT_NODE and m.nodeName == 'mount-point': 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['size'].value.encode('ascii')) + m.attributes['directory'].value.encode('ascii'), \ + m.attributes['file-system'].value.encode('ascii'), \ + m.attributes['format'].value.encode('ascii'),\ + m.attributes['size'].value.encode('ascii')) @staticmethod def to_xml(doc, p_node): diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 7914c86..1126500 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -31,7 +31,7 @@ def mount_list_init(): 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) + s = m.device.ljust(10) + m.directory.ljust(10) + m.filesystem.ljust(10) + m.format.ljust(4) + sz.ljust(6)+ri_data.Partition.unit l.append(s) display.var_dict['mount.list'].set(value=tuple([str(i) for i in l])) @@ -85,7 +85,7 @@ def mp_top_ok(): 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) + s2 = dev.ljust(10) + dir.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6)+ri_data.Partition.unit l.append(s2) # make change in internal data structure ri_data.MountPoint.change(dev2, dir, fs, fm) @@ -272,7 +272,7 @@ def raid_raw_init(): 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 ] + if p.israid=='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): @@ -327,12 +327,12 @@ devs - raid component devices sz = float(p.size[:-len(unit)]) if level == '0': sz=sz*len(devs) - return "%d%s"%(sz,unit) + return str(sz) elif level == '1': - return "%d%s"%(sz,unit) + return str(sz) elif level == '5': sz=sz*(len(devs)-1) - return "%d%s"%(sz,unit) + return str(sz) def raid_device_add(): ''' add a new raid device ''' From 4f81fc0f4677b429b1a3669c53d9594b55314812 Mon Sep 17 00:00:00 2001 From: fling Date: Wed, 13 Oct 2010 23:17:45 +0800 Subject: [PATCH 02/37] modified: ri_data.py modified: ri_tk_cmd.py add staticmothod of ri_data.Raid : dev_in_raid() --- interface/ri_data.py | 19 ++++++++++++------- interface/ri_tk_cmd.py | 18 +++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index 8257f4e..95e517a 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -315,6 +315,15 @@ p_node - xml node (parent node) ''' 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.list: + devices_in_raid.update(r.active_components) + devices_in_raid.update(r.spare_components) + return devices_in_raid + class MountPoint: ''' mount-points ''' list=[] @@ -341,15 +350,11 @@ class MountPoint: @staticmethod def init_from_internal(): ''' init MountPoint from internal class Partition and class 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) - + # add raid device in dev_in_raid + dves=Raid.dev_in_raid 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 : + if p.device not in devs and p.device not in devs : MountPoint(p.device,fs=p.filesystem,sz=p.size) for r in Raid.list: diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 1126500..e9ae652 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -18,15 +18,12 @@ 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) + devs=ri_data.Raid.dev_in_raid() ri_data.MountPoint.init_from_internal() for m in ri_data.MountPoint.list: # get size from Partition info - if m.device in dev_in_raid: + if m.device in devs: continue sz = ri_data.Partition.get_size(m.device) if not sz: @@ -266,13 +263,9 @@ def raid_raw_init(): if not raid_raw_initialized: raid_raw_initialized = True # get all component devices already in raid - 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) - + devs=ri_data.Raid.dev_in_raid() raw_devs = [ p.device for p in ri_data.Partition.list - if p.israid=='yes' and p.device not in dev_in_raid ] + if p.israid=='yes' and p.device not in devs ] display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) def list_to_list(list_from, var_from, var_to): @@ -398,11 +391,10 @@ def raid_device_list_detail(*args): 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''' ins_info = ri_data.install_information() t= ri_widget.Widget.dict['install_information.list'].tk_widget t.insert(1.0,ins_info) +raid_raw_initialized = False From fb83d4b5100ed94435dd911fba82bc423bf17c35 Mon Sep 17 00:00:00 2001 From: fling Date: Thu, 14 Oct 2010 15:05:40 +0800 Subject: [PATCH 03/37] modified: ri_tk_cmd.py add two showwarning messagebox for active devices that must be more than two --- interface/ri_tk_cmd.py | 19 +++++++++++++------ xml/interface.xml | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index e9ae652..9e25d0d 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -22,9 +22,9 @@ def mount_list_init(): devs=ri_data.Raid.dev_in_raid() ri_data.MountPoint.init_from_internal() for m in ri_data.MountPoint.list: - # get size from Partition info if m.device in devs: continue + # get size from Partition info sz = ri_data.Partition.get_size(m.device) if not sz: sz = ri_data.Raid.get_size(m.device) @@ -313,11 +313,11 @@ devs - raid component devices ''' # all devs shall have same size. unit=ri_data.Partition.unit - sz=99999999999 + sz=999999999 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 float(p.size)< float(sz): + sz = float(p.size) if level == '0': sz=sz*len(devs) return str(sz) @@ -330,19 +330,26 @@ devs - raid component devices def raid_device_add(): ''' add a new raid device ''' if display.var_dict['raid_active_devs'].get()=='': - ri_widget.MessageBox.dict["raid_add_active_warning"].show() - return + 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())) + 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, raid_calc_size(level, active), active, spare) diff --git a/xml/interface.xml b/xml/interface.xml index dc03a81..33c6bfb 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -727,7 +727,8 @@ row 4 | | - + + current_step --- interface/ri_oper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 4e15f00..9b7ddca 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -46,7 +46,7 @@ class Operation: return_value - shell script return value score - an abstract value, for example score is 5, steps - the subprocess of the number of runs - step - the subprocess run one time + current_step - the subprocess run one time total is 100, if this operations is completed, 5% work is done. and the following methods: @@ -68,7 +68,7 @@ class Operation: self.script = s self.score = scr self.steps = 1 - self.step = 0 + self.current_step = 0 def install(self): if display_operation: @@ -84,8 +84,8 @@ class Operation: line = process.stdout.readline() if not line: break - if line[0] == '@' and self.step < self.steps: - self.step += 1 + if line[0] == '@' and self.current_step < self.steps: + self.current_step += 1 if display_sub_operation: display_sub_operation(line[1:]) Rate.increase(float(self.score)/self.steps, max) From 212f213a096bfd0ae61319dab277e74c845b1d60 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 13:41:32 +0800 Subject: [PATCH 13/37] modified: ri_oper.py --- interface/ri_oper.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 9b7ddca..ba72aa4 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -52,7 +52,7 @@ class Operation: and the following methods: get_arguments - prepare arguments for scipt get_stdin - prepare stdin for script - install - install progress ''' + install - install progress ''' def __init__(self,e,c,s,scr): ''' Operation(base class) init method @@ -77,7 +77,7 @@ class Operation: max = Rate.value+self.score <100 and Rate.value+self.score or 100 process = subprocess.Popen("./%s " %self.script + ' '.join(self.get_arguments()),\ stdin=subprocess.PIPE,stdout=subprocess.PIPE, shell=True, \ - cwd="%s/../operation"%os.path.split(os.path.realpath(__file__))[0]) + cwd="%s/../operation" %os.path.split(os.path.realpath(__file__))[0]) process.stdin.write(self.get_stdin()) process.stdin.close() while True: @@ -118,7 +118,6 @@ class Format(Operation): class MakeRaid(Operation): """class for make raid""" - flag=False def __init__(self,scr): Operation.__init__(self,"make RAID",u"正在制作RAID磁盘阵列","mkraid_wrapper.sh",scr) def get_stdin(self): @@ -126,7 +125,6 @@ class MakeRaid(Operation): n = 0 for instance in ri_data.Raid.list: if instance.from_os == 'no': - MakeRaid.flag=True args += '-n /dev/%s -l %s -s %s -a %s\n' %(instance.device, instance.level, \ ','.join([ '/dev/%s' %sp for sp in instance.spare_components]), \ ','.join([ '/dev/%s' %ac for ac in instance.active_components])) @@ -139,8 +137,8 @@ class MakeRaidConfigure(Operation): def __init__(self,scr): Operation.__init__(self,"make raid configure file",u"配置raid配置文件","mkraidconf.sh",scr) def install(self): - if MakeRaid.flag: - Operation.install(self) + if ri_data.Raid.list: + return Operation.install(self) else: max = Rate.value+self.score <100 and Rate.value+self.score or 100 Rate.set(max) @@ -153,7 +151,6 @@ class Mount(Operation): """class for mount partition""" def __init__(self,scr): Operation.__init__(self,'mount partition',u'挂载分区','mount_partition.sh',scr) - self.return_value[2]=("device node doesn't exist",u"设备结点不存在") def get_stdin(self): mount='' @@ -209,6 +206,7 @@ class GenerateIssue(Operation): string = fd.read() list = string.split('\n')[0].split('-') args = ['-v']+[list[0][5:]]+["-a"]+[list[1]]+["-r"]+[list[2]]+['-d']+['-'.join(list[3:])] + fd.close() return args class ConfigureNetwork(Operation): @@ -304,4 +302,5 @@ class ConfigureBootloader(Operation): # only grub? bootloader=['-t','grub','-r',instance.device,'-k',ri_data.SerialNumber.value,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1]] break + fd.close() return bootloader From ac34d88e6c685a15830dd51be7c3c7bd38751d90 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 14:39:01 +0800 Subject: [PATCH 14/37] modified: ri_oper.py update error info --- interface/ri_oper.py | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index ba72aa4..6be6e05 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -50,7 +50,7 @@ class Operation: total is 100, if this operations is completed, 5% work is done. and the following methods: - get_arguments - prepare arguments for scipt + get_arguments - prepare arguments for script get_stdin - prepare stdin for script install - install progress ''' @@ -58,10 +58,10 @@ class Operation: ''' Operation(base class) init method return_value is a dict, key is return code, value is a tuple, first element is English, second element is Chinese.''' - self.return_value = {0:('success', u'成功'), \ - 1:('argument error',u'参数错误'), \ - 2:('deivce node do not exist',u'设备节点不存在'),\ - 3:('filesystem no implement',u'文件系统没有实现'),\ + self.return_value = {0:('Success', u'成功'), \ + 1:('Argument error',u'参数错误'), \ + 2:("Deivce node doesn't exist",u"设备节点不存在"),\ + 3:("File system hasn't been implemented",u'文件系统没有实现'),\ } self.english_name = e self.chinese_name = c @@ -103,8 +103,8 @@ class Operation: class Format(Operation): ''' class for format partition ''' def __init__(self, scr): - Operation.__init__(self, 'format partition', u'格式化分区', 'format_partition.sh', scr) - self.return_value[127] = ('format partition utils not found', u'没有格式化硬盘功能') + Operation.__init__(self, 'Format partition', u'格式化分区', 'format_partition.sh', scr) + self.return_value[127] = ('No tool to format partitions', u'没有格式化硬盘分区的工具') def get_stdin(self): format='' @@ -119,7 +119,7 @@ class Format(Operation): class MakeRaid(Operation): """class for make raid""" def __init__(self,scr): - Operation.__init__(self,"make RAID",u"正在制作RAID磁盘阵列","mkraid_wrapper.sh",scr) + Operation.__init__(self,"Making a RAID", u"正在制作RAID磁盘阵列", "mkraid_wrapper.sh", scr) def get_stdin(self): args = '' n = 0 @@ -135,7 +135,7 @@ class MakeRaid(Operation): class MakeRaidConfigure(Operation): """class for make raid configure""" def __init__(self,scr): - Operation.__init__(self,"make raid configure file",u"配置raid配置文件","mkraidconf.sh",scr) + Operation.__init__(self,"Generate /etc/mdadm.conf",u"生成raid配置文件","mkraidconf.sh",scr) def install(self): if ri_data.Raid.list: return Operation.install(self) @@ -150,7 +150,7 @@ class MakeRaidConfigure(Operation): class Mount(Operation): """class for mount partition""" def __init__(self,scr): - Operation.__init__(self,'mount partition',u'挂载分区','mount_partition.sh',scr) + Operation.__init__(self, 'Mount partition', u'挂载分区', 'mount_partition.sh',scr) def get_stdin(self): mount='' @@ -165,9 +165,9 @@ class Mount(Operation): class InstallPkg(Operation): """class for install packages""" def __init__(self,scr): - Operation.__init__(self,'install packages',u'安装软件包','install_pkg.sh',scr) - self.return_value[2]=("source directory pkg_source_dir doesn't exist",u"软件包所在目录不存在") - self.return_value[3]=("package in source doesn't exist",u"软件包不存在") + Operation.__init__(self,'Install packages',u'安装软件包','install_pkg.sh',scr) + self.return_value[2]=("Software source directory doesn't exist",u"软件包所在目录不存在") + self.return_value[3]=("Software package doesn't exist",u"软件包不存在") def get_stdin(self): pkgname=[] @@ -190,13 +190,13 @@ class InstallPkg(Operation): class ConfigureFstab(Mount): """class for configure /etc/fstab""" def __init__(self,scr): - Operation.__init__(self,'configure fstab',u'配置/etc/fstab文件','configure_fstab.sh',scr) - self.return_value[2]=("fstab doesn't exist",u"/etc/fstab文件不存在") + Operation.__init__(self,'Configure /etc/fstab',u'配置/etc/fstab文件','configure_fstab.sh',scr) + self.return_value[2]=("/etc/fstab doesn't exist",u"/etc/fstab文件不存在") class GenerateIssue(Operation): """class for generate /etc/issue""" def __init__(self,scr): - Operation.__init__(self,'generate issue',u'生成/etc/issue文件','generate_issue.sh',scr) + Operation.__init__(self,'Generate /etc/issue',u'生成/etc/issue文件','generate_issue.sh',scr) def get_arguments(self): args=[] @@ -212,9 +212,11 @@ class GenerateIssue(Operation): class ConfigureNetwork(Operation): """class for configure network""" def __init__(self,scr): - Operation.__init__(self,'configure network',u'配置网络','configure_network.sh',scr) - self.return_value[2]=("ip or netmask or geteway address incorrect",u"ip或子网掩码或网关不正确") - self.return_value[3]=("hosts/resolv.conf/ifcfg-eth0/network doesn't exist",u"文件hosts、resolv.conf、ifcfg-eht0、network 不存在") + Operation.__init__(self,'Configure network',u'配置网络','configure_network.sh',scr) + self.return_value[2]=("Ip address, network, or geteway is incorrect",u"Ip地址、子网掩码、网关不正确") + self.return_value[3]=("/etc/hosts, /etc/resolv.conf, /etc/sysconfig/network-devices/ifcfg.template, or /etc/sysconfig/network doesn't exist",\ + u"文件/etc/hosts,/etc/resolv.conf,/etc/sysconfig/network-devices/ifcfg.template或/etc/sysconfig/network文件不存在") + def get_arguments(self): network='' @@ -244,8 +246,8 @@ class ConfigureNetwork(Operation): class MakeServiceAutoBoot(Operation): """class for make service autoboot""" def __init__(self,scr): - Operation.__init__(self,"make service autoboot",u"启动服务器","mk_serv_autoboot.sh",scr) - self.return_value[2]=("boot script doesn't exist",u"引导脚本不存在") + Operation.__init__(self,"Make service autoboot",u"启动服务器","mk_serv_autoboot.sh",scr) + self.return_value[2]=("Boot script doesn't exist",u"引导脚本不存在") def get_stdin(self): serv='' @@ -260,23 +262,23 @@ class MakeServiceAutoBoot(Operation): class CopyKernel(Operation): """class for copy kernel""" def __init__(self,scr): - Operation.__init__(self,"copy kernle",u"拷贝内核","copy_kernels.sh",scr) - self.return_value[1]=("kernel directory/modules directory/initrd.gz/makeinitrd doesn't exist",u"内核目录、模块目录、initrd.gz、makeinitrd 不存在") + Operation.__init__(self,"Copy kernle",u"拷贝内核","copy_kernels.sh",scr) + self.return_value[1]=("kernel directory, modules directory, initrd.gz, or makeinitrd doesn't exist",u"内核目录、模块目录、initrd.gz文件、makeinitrd指令不存在") class ExecFinishInstall(Operation): """class for exec finish install""" def __init__(self,scr): - Operation.__init__(self,"exec finish install",u"安装完成执行的脚本","exec_finish_install.sh",scr) + Operation.__init__(self,"Exec finish_install script",u"安装完成执行的脚本","exec_finish_install.sh",scr) def get_stdin(self): return "99finish_install.sh\n" class BootLoader(Operation): """class for bootloader""" def __init__(self,scr): - Operation.__init__(self,"install bootloader",u"安装引导程序","install_bootloader.sh",scr) - self.return_value[2]=("bootloader type doesn't specify",u"没有指定引导程序的类型") - self.return_value[3]=("bootloader no implement",u"没有执行bootloader") - self.return_value[127]=("bootloader utils not found",u"没发现bootloader的utils") + Operation.__init__(self,"Install bootloader",u"安装引导程序","install_bootloader.sh",scr) + self.return_value[2]=("Bootloader type hasn't been specified",u"没有指定引导程序的类型") + self.return_value[3]=("Bootloader hasn't been implemented",u"没有执行bootloader") + self.return_value[127]=("Bootloader utils not found",u"没发现bootloader的utils") def get_arguments(self): # only grub? @@ -285,10 +287,10 @@ class BootLoader(Operation): class ConfigureBootloader(Operation): """class for configure bootloader file""" def __init__(self,scr): - Operation.__init__(self,"configure bootloader",u"配置bootloader","configure_bootloader_cnf.sh",scr) - self.return_value[2]=("bootloader type doesn't specify",u"没有指定引导程序的类型") - self.return_value[3]=("bootloader configure file doesn't exist",u"引导程序配置文件不存在") - self.return_value[4]=("bootloader configuration file doesn't exist",u"引导程序配置文件不存在") + Operation.__init__(self,"Configure bootloader",u"配置bootloader","configure_bootloader_cnf.sh",scr) + self.return_value[2]=("Bootloader type hasn't specified",u"没有指定引导程序的类型") + self.return_value[3]=("Bootloader hasn't been implemented",u"") + self.return_value[4]=("Bootloader configuration file doesn't exist",u"引导程序配置文件不存在") def get_arguments(self): bootloader=[] From 1acbf5e3273aadf1b70b5c5cf76f6af9e3491281 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 16:43:51 +0800 Subject: [PATCH 15/37] modified: ri_oper.py ConfigureBootloader mount.list.directory=/boot or / --- interface/ri_oper.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 6be6e05..7784abc 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -20,6 +20,9 @@ import ri_data import os import subprocess +if os.path.isfile("../xml/install.xml"): + ri_data.init_from_xml() + display_operation = None display_sub_operation = None display_scale = None @@ -277,8 +280,8 @@ class BootLoader(Operation): def __init__(self,scr): Operation.__init__(self,"Install bootloader",u"安装引导程序","install_bootloader.sh",scr) self.return_value[2]=("Bootloader type hasn't been specified",u"没有指定引导程序的类型") - self.return_value[3]=("Bootloader hasn't been implemented",u"没有执行bootloader") - self.return_value[127]=("Bootloader utils not found",u"没发现bootloader的utils") + self.return_value[3]=("Bootloader hasn't been implemented",u"没有实现bootloader") + self.return_value[127]=("No tool to bootloader. E.g grub",u"没有安装引导程序的工具。如grub等") def get_arguments(self): # only grub? @@ -289,20 +292,35 @@ class ConfigureBootloader(Operation): def __init__(self,scr): Operation.__init__(self,"Configure bootloader",u"配置bootloader","configure_bootloader_cnf.sh",scr) self.return_value[2]=("Bootloader type hasn't specified",u"没有指定引导程序的类型") - self.return_value[3]=("Bootloader hasn't been implemented",u"") + self.return_value[3]=("Bootloader hasn't been implemented",u"没有实现bootloader") self.return_value[4]=("Bootloader configuration file doesn't exist",u"引导程序配置文件不存在") def get_arguments(self): - bootloader=[] + list=[] + tp="grub" + isboot=False + isroot=False # FIXME if tag file format is error? if os.path.isfile("/tag"): fd = open("/tag","r") string = fd.read() list = string.split('-') - for instance in ri_data.MountPoint.list: - if instance.directory == '/': - # only grub? - bootloader=['-t','grub','-r',instance.device,'-k',ri_data.SerialNumber.value,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1]] - break - fd.close() + fd.close() + + bootloader=['-t',tp,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1]] + + for instance in ri_data.MountPoint.list: + if instance.directory == '/' and not isroot: + bootloader+=['-r',instance.device] + print "root" + isroot=True + continue + if isroot and instance.directory == '/boot' and not isboot : + bootloader+=['-b',instance.device] + print "boot" + isboot=True + continue + + if ri_data.SerialNumber.value: + bootloader+=['-k',"linx_serial=%s" %ri_data.SerialNumber.value] return bootloader From c3fa7d040489e57054a4de632ffb83bb92af5a73 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:05:23 +0800 Subject: [PATCH 16/37] modified: ../xml/interface.xml update main.help --- xml/interface.xml | 66 +++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/xml/interface.xml b/xml/interface.xml index 33c6bfb..cb38257 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -861,7 +861,7 @@ row 4 | | There are two kinds of dependent relationships. Dependent Functions and Dependent Packages. Dependent Functions :To provide systems function of packages. the left column is the systematic functions, the right column provides function of packages. - Dependent Packages : The current selection of the dependent packages on the missing package. The left column of the software package is dependent on the right of the software packages + Dependent Packages : Current selection of the dependent packages on the missing package. The software package in the left column is depended by the software packages in the right column. @@ -878,7 +878,7 @@ row 4 | | - Installation information recorded the process which the users choose operations during installation. Including: record the operation of the physical hard disk, choose the software packages which use to install and server to start system. + Installation information recorded the configuration the user chose during the installation, including the operation to the physical hard disks, the software packages chose to install, the selected self-starting servers since system startup, etc. 安装信息记录了用户在安装过程中所配置的数据。内容包括:对物理硬盘的操作,选择安装的软件包,选择系统启动时自启的服务等。 @@ -892,7 +892,8 @@ row 4 | | - There are five columns in the mount point display frame. The first is the hard disk partition, such as sdaX, mdx. The second is the mount point. The third is the file system of hard disk . The fourth is that if your format hard disk partition, "yes" means do ,"no" means don't . The fifth is the size of hard disk and raid equipment. + There are five columns in the mount point display frame. The first column lists the hard disk partitions, such as sdaX, mdx. The second lists the mount points. The third lists the file system type of the partitions. The fourth lists the choices whether to format the partitions, "yes" means do , "no" means don't . The fifth lists the sizes of the partitions or the raid devices. + Click one row to change configurations of the hard disk partition, including the mount point, whether to format the partition, the file system type, etc. 设置挂载点显示框中分为五列,第一列是硬盘分区,如sdaX、mdX。第二列是挂载点,是挂载硬盘分区时所在的目录。第三列是硬盘分区的文件系统类型。第四列是指是否要格式化该硬盘分区,no表示不格式化,yes表示要格式化。第五列是各硬盘分区或raid设备的大小。 @@ -902,12 +903,12 @@ row 4 | | - The host name identifies the computer system which use various forms of electronic transmission to identify the specific computer system. - Installation the program offers two ways. It is dynamic configureation IP (DHCP) and static configuration IP. - Dynamic allocation: It distributes IP address when you start your computer system every time. If you use dynamic IP address, it is necessary to ensure that computer network environment which there is DHCP server. - Staic configuration: Using a static IP address,netmask,gateway and DNS server. If you choose static IP, you must promise IP address,netmask,gateway,DNS cannot be empty. - Domain represent a name or a location that a unit, a organization or individual person use in the internet. - IP address,netmask,gateway,DNS: Input the four numbers from 0 to 255 by dots. E.g: 192.168.1.1 + Hostname is used to identify computers. It could identify a specific computer system in various forms of electronic transmissions. + The installation program offers two ways to set an IP address of the host. One is automatically configuration (DHCP) and the other is manually configuration. + Automatically Configuration: DHCP allows a computer to be configured automatically. The DHCP sever will allocate an IP address to the host since the host startup. If you want to choose this way to get an IP address, make sure there is an DHCP sever in the network. + Manually configuration: You could manually configure an static IP address, netmask, gateway and DNS server. If you choose to use this way to set an IP address, the netmask, gateway, DNS server and domain must be configured also. + Domain could be a definitized name or location in the internet used by an unit, an organization or private person. + IP address, netmask, gateway, primary DNS server, secondary DNS server: Input four numbers, each ranging from 0 to 255, separated by dots, e.g., 192.168.1.1 . 主机名标识计算机系统,主要用于各种形式的电子传输,以鉴别特定的计算机系统。 @@ -953,22 +954,24 @@ row 4 | | - RAID is a way to multi-block independentHard drive(Physical disk ) in different ways combined to form a disk group (logical drives) , which provides than a single disk more storage performance and providing data backup technology. - If your don't know RAID,plase press next step,which don't effect Rocky OS installation and run. - The hard disk in the raw display frame is able to make the RAID, E.g sda2,sdb2. The RAID’s equipments in the Device display frame have already existed. E.g: md0. Rocky os installation keep original raid equipment. If your want to make a RAID, please choose one or more hard disk in the Raw box, and press "-->". Hard disk will turn into active box or free box. If the hard disk turns into the active box, you can make a raid. After performing the operation, please choose level in Level box. In the end, you can make a raid according to press '-->'. + RAID is a technology that provides increased storage reliability through redundancy, combining multiple low-cost, less-reliable disk drives components into a logical unit where all drives in the array are interdependent. + If you don't want to make a RAID, you could click "next" to skip this step. The installation will go on normally. + The partitions whose file system type are raid are listed in the Original frame, e.g., sda2, sdb2. The RAID are listed in the Device frame, e.g., md0, md1. The partitions to make a RAID are listed in the Active frame, and the spare partitions for the RAID are listed in the Spare frame. + The original RAID will be retained. If you want to make a new RAID, select partitions in the original frame, then click "-->" to move them to the Active frame or Spare frame, according to their roles. There must be one or more partitions in the Active frame, relating to the raid level you want to make, but the spare partitions are not essential. A new RAID, named mdX (X stands for the number of the RAID), will be listed in the Device frame after you click "-->" beside the Device frame. 磁盘陈列技术(RAID)诞生于1987年,由美国加州大学伯克利分校提出。该技术是把多块独立的硬盘(物理硬盘)按不同的方式组合起来形成一个硬盘组(逻辑硬盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术。 如果用户不懂该技术可以直接点击下一步,系统将不制作RAID,并不影响系统的安装及运行。 - 原始框中是满足制作RAID的硬盘分区,如sda1、sdb2等。设备框中是原本系统已经制作好的RAID,如md0、md1等。系装安装时将保留原有的RAID设备。若要制作新RAID,请在原始框中选中硬盘分区后通过点击"->",硬盘分区会进入活动框或空闲框中。要制作RAID,活动框中必须要有硬盘分区,可以有一个或多个。空闲框中硬盘分区是可选的,可以有一个或多个,也可以没有。完成上步操作后在级别框中选择raid的级别,最后点击"->"在设备框中产生新的mdX设备。 + 原始框中是满足制作RAID的硬盘分区,如sda1、sdb2等。设备框中是原本系统已经制作好的RAID,如md0、md1等。系装安装时将保留原有的RAID设备。若要制作新RAID,请在原始框中选中硬盘分区后通过点击"->",硬盘分区会进入使用框或备用框中。要制作RAID,使用框中必须要有硬盘分区,可以有一个或多个。备用框中硬盘分区是可选的,可以有一个或多个,也可以没有。完成上步操作后在级别框中选择raid的级别,最后点击"->"在设备框中产生新的mdX设备。 - The serial number is that computer systems security operations of the Linx. In the serial number display frame, please input correct serial number so that the Rocky system can be start after the operating system installed. - How to get the serial number?please contact Linx. - web: www.linx-info.com + Serial number is the permission to run secure functions of Linx Rocky Secure OS. + Please Input the correct serial number in the frame, so that secure functions could run. + Please contact Linx Technology Co.,Ltd. to get the serial number. + Website: www.linx-info.com 安装序列号是计算机运行凝思磐石安全操作系统的许可,请在序列号框内输入正确的序列号,以便操作系统的安全功能,能从计算机启动。 @@ -988,14 +991,15 @@ row 4 | | - Package group was divided into required and optional parts. They system will be installed by default which in the Required Software. To install the optional packages, you can first click on an optional package group and find it. - Base package group is required parts. Basic package include required and optional aparts. Required packages are installed by default, the optional package can be free to choose. - Development package group, including C, C++, DDD and other developed tolls are available. You can choose to install. - Graphics software package group, including the various procedures related XII. Graphics software package can be divided into the required and optional package. When you select to choose this kind of package, the required one is installed by default and the optional one is free. - Network service package group is optional package , various network services package and network service software can choose to install. - Internet software, including World Wide Web browser and Firefox, divided into required and optional packages. The first is installed by default and the last one is free to choose. - Multimedia package group, including a variety of media library. Multimedia software packages are optional packages can choose to install. - Another package group is optional one, so you can choose to install freely. + There are two kinds of packages and package groups, one is mandatory, the other is optional. + The mandatory packages of a group will be installed by default if you select the group. You could first click a group, and then select optional packages want to install in the pop-up dialog box. + Base group is the only mandatory group to install, consist of packages for a base system. The mandatory packages of Base group will be installed by default, you could select optional packages of it. + Development group is consist of tools of C, C++, DDD, etc. There's no mandatory package in Development group, you could select optional packages of it. + GUI group is consist of various packages relating to X11. There are mandatory packages and optional packages. Mandatory packages will be installed by default if you select this group. You could select optional packages freely. + Network group is consist of various network sevices packages. There's no mandatory package, you could select optional packages of it. + Internet group is consist of software like World Wide Web browser Firefox. There are mandatory packages and optional packages. Mandatory packages will be installed by default if you select this group. You could select optional packages freely. + Multimedia group is consist of a variety of media libraries.There's no mandatory package, you could select optional packages of it. + Others group is consist of packages that are not included in groups above, e.g., kde, vm, network tools. There's no mandatory package, you could select optional packages of it. 软件包组分为必选软件包组和可选软件包。系统默认时会安装必选软件包组里的必选软件包。在安装软件包时,先点击软件包组,在弹出的对话框中选上所须要的软件包。 @@ -1016,22 +1020,10 @@ row 4 | | - Respect of user, hello! welcome to use that the operating system. Rocky! + Dear user, welcome to Linx Rocky Secure OS! 尊敬的用户,你好!欢迎使用凝思磐石操作系统。 - 凝思磐石安全操作系统遵循国内外安全操作系统GB17859、GB/T18336、GJB4936、 GJB4937、GB/T20272以及POSIX、TCSEC、ISO15408等标准进行设计和实现,为我国用户提供拥有自主知识产权、高安全、高可用和高效的操作系统平台。凝思科技经过多年的研究,开发出的凝思磐石安全操作系统具有以下主要特点: - 高安全性 - 安全性是凝思磐石安全操作系统的主要特征,充分结合凝思科技的独有技术与国内外多项安全标准的要求,在操作系统和应用程序的各个层次进行安全增强,使系统成为安全的有机整体。主要安全机制有一下几点:强制运行机制(MEC)、强制能力控制(MCC)、访问控制列表(ACL)、强制访问控制(MAC)、四权分立的系统管理 - 高可用性 - 凝思磐石安全操作系统发布前进行了长时间的压力测试,能够保证高内存和CPU负载环境下的稳定运行,为各类应用提供稳定运行平台。 - 高兼容性 - 凝思磐石安全操作系统系列产品包括安全服务器版、安全工作站版、安全专用设备版和安全桌面版,适用于从大型计算到桌面办公等各种环境,支持各类通用和专业应用,具有良好的软、硬件兼容性. - 凝思磐石安全操作系统提供丰富的驱动程序,支持各类主流磁盘驱动器、网卡驱动器和显示控制器等硬件设备。兼容国内外各大主流厂商的多款服务器和桌面计算机。凝思科技还可协助第三方硬件厂商完成驱动程序的研发和移植,实现加密卡等专用硬件设备支持。 - 高效性 - 凝思磐石安全操作系统的每一款产品均针对服务器、工作站、专用设备和桌面环境进行特别优化,能够获得比通用操作系统更高的运行效率. - 易维护性 - 凝思磐石安全操作系统的配置、使用和维护方法与传统UNIX和Linux保持一致,提供丰富的管理和维护软件,既可通过命令行工具完成系统配置和维护,又可通过图形界面完成相关操作,简化用户操作步骤,减少系统管理员的维护工作量。 From 4f9ec865717ae157a2ffd51ecf15575dbb7a8a67 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:16:59 +0800 Subject: [PATCH 17/37] modified: ri_data.py zli update --- interface/ri_data.py | 228 +++++++++++++++++++------------------------ 1 file changed, 101 insertions(+), 127 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index 9af2ee9..eab7177 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -40,8 +40,7 @@ p_node - xml node (parent node)''' class Partition: ''' disk partition ''' unit='' - label='' - list=[] + dict={} def __init__(self, dev, st, sz, tp, fs, fg, fr): ''' Partition init function ''' self.device = dev @@ -49,72 +48,86 @@ class Partition: self.size = sz self.type = tp self.filesystem = fs - self.israid = fg + self.flags = fg self.from_os = fr - Partition.list.append(self) + Partition.dict[dev] = self @staticmethod def init_from_os(): ''' create a Partition instance from hardware info''' device_list=[] - Partition.unit='MB' - p = re.compile(r"\s*") + Partition.unit='GB' 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)) - 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+=['','',''] - ret[2]=ret[2][:-len(Partition.unit)] - ret[3]=ret[3][:-len(Partition.unit)] - ret[4]=ret[4][:-len(Partition.unit)] - 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') + # 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 + + if located: + Partition(d+s[nm_i:st_i].strip(), # device name + s[st_i:end_i].strip(), # 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 + s[flg_i:].strip() # flags + ) @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'),\ @@ -122,7 +135,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')) @@ -135,9 +148,6 @@ p_node - xml node (parent node)''' unit_attr = doc.createAttribute('unit') unit_attr.value = Partition.unit pts.setAttributeNode(unit_attr) - 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') @@ -145,62 +155,52 @@ p_node - xml node (parent node)''' 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): - for p in Partition.list: - if p.device == dev: - return p.size + return Partition.dict[dev].size class Raid: ''' raid information ''' - list = [] - def __init__(self, dev, from_os, level, sz, a_devs, s_devs=[]): + dict = {} + def __init__(self, dev, from_os, level, 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.list.append(self) + Raid.dict[dev] = 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 @@ -214,15 +214,8 @@ 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, raid_size, act_cmpts, spr_cmpts) @staticmethod def add_component(node, l): @@ -242,7 +235,6 @@ 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: @@ -252,7 +244,7 @@ l - list elif sub_e.nodeName == 'spare': Raid.add_component(sub_e, spr_cmpts) - Raid(raid_dev, raid_from, raid_level, raid_size, act_cmpts, spr_cmpts) + Raid(raid_dev, raid_from, raid_level, act_cmpts, spr_cmpts) @staticmethod def to_xml(doc, p_node): @@ -275,10 +267,6 @@ 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') @@ -301,15 +289,14 @@ p_node - xml node (parent node) ''' #ri_tk_cmd.py use @staticmethod def get_size(dev): - for r in Raid.list: - if r.device == dev: - return r.size + # need fill + pass @staticmethod def get_next_device(): ''' get next available raid device name ''' num_p = re.compile(r'md(\d+)') - numbers = [ int(num_p.match(r.device).groups()[0]) for r in Raid.list ] + numbers = [ int(num_p.match(r).groups()[0]) for r in Raid.dict.keys() ] max = 0 for n in numbers: if n > max: max = n @@ -326,62 +313,52 @@ p_node - xml node (parent node) ''' class MountPoint: ''' mount-points ''' - list=[] - def __init__(self, dev, dir='', fs='', fm='no', sz='0'): + dict={} + def __init__(self, dev, dir='', fs='', fm='no'): self.device = dev self.directory = dir self.filesystem = fs self.format = fm - self.size = sz - MountPoint.list.append(self) + MountPoint.dict[dev]=self @staticmethod def change(dev, dir, fs, fm): - for mp in MountPoint.list: - if mp.device == dev: - mp.directory = dir - mp.filesystem = fs - mp.format = fm + mp = MountPoint.dict[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 ''' - # clean MountPoint.list before update - MountPoint.list=[] - # add partitions in Raid.list - raid_devs=Raid.dev_in_raid() - for p in Partition.list: - if p.device not in raid_devs : - MountPoint(p.device,fs=p.filesystem,sz=p.size) + # add raid device in dev_in_raid + dev_in_raid = Raid.dev_in_raid() - for r in Raid.list: - MountPoint(r.device,sz=r.size) + 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) + + for dev in Raid.dict.keys(): + if MountPoint.dict.has_key(dev) + continue + MountPoint(dev) # now process whether a partition or raid was removed - 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]) + s1 = set(MountPoint.dict.keys()) + s2 = set(Partition.dict.keys() + Raid.dict.keys()) for dev in s1-s2: - 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) - + del MountPoint.dict[dev] + + @staticmethod def init_from_xml(node): ''' create MountPoint instances from xml node ''' for m in node.childNodes: if m.nodeType == node.ELEMENT_NODE and m.nodeName == 'mount-point': 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['size'].value.encode('ascii')) + m.attributes['directory'].value.encode('ascii'), \ + m.attributes['file-system'].value.encode('ascii'), \ + m.attributes['format'].value.encode('ascii')) @staticmethod def to_xml(doc, p_node): @@ -395,17 +372,14 @@ p_node - xml node (parent node)''' 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) From 64b99ddbd922ab78828874a90f6b5c78aac626df Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:30:24 +0800 Subject: [PATCH 18/37] modified: ri_oper.py update date list --> dict{} --- interface/ri_oper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 7784abc..0e5452b 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -112,7 +112,7 @@ class Format(Operation): def get_stdin(self): format='' n = 0 - for instance in ri_data.MountPoint.list: + for instance in ri_data.MountPoint.dict.values(): if instance.format == "yes" and instance.filesystem != '': format+="/dev/%s %s\n"%(instance.device,instance.filesystem) n += 1 @@ -126,7 +126,7 @@ class MakeRaid(Operation): def get_stdin(self): args = '' n = 0 - for instance in ri_data.Raid.list: + for instance in ri_data.Raid.dict.values(): if instance.from_os == 'no': args += '-n /dev/%s -l %s -s %s -a %s\n' %(instance.device, instance.level, \ ','.join([ '/dev/%s' %sp for sp in instance.spare_components]), \ @@ -140,7 +140,7 @@ class MakeRaidConfigure(Operation): def __init__(self,scr): Operation.__init__(self,"Generate /etc/mdadm.conf",u"生成raid配置文件","mkraidconf.sh",scr) def install(self): - if ri_data.Raid.list: + if ri_data.Raid.dict.values(): return Operation.install(self) else: max = Rate.value+self.score <100 and Rate.value+self.score or 100 @@ -158,7 +158,7 @@ class Mount(Operation): def get_stdin(self): mount='' n = 0 - for instance in ri_data.MountPoint.list: + for instance in ri_data.MountPoint.dict.values(): if instance.directory != '' and instance.filesystem !='': mount+="/dev/%s %s %s\n"%(instance.device,instance.directory,instance.filesystem) n += 1 @@ -309,7 +309,7 @@ class ConfigureBootloader(Operation): bootloader=['-t',tp,'-o',list[0][5:].split('.')[0]+'.'+list[0][5:].split('.')[1]] - for instance in ri_data.MountPoint.list: + for instance in ri_data.MountPoint.dict.values(): if instance.directory == '/' and not isroot: bootloader+=['-r',instance.device] print "root" From 4a4f21fcde8bc8f905bf9ea9038c3cfb75d5132d Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:35:58 +0800 Subject: [PATCH 19/37] modified: ri_data.py --- interface/ri_data.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index eab7177..3ce1626 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -81,8 +81,8 @@ class Partition: 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] + 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" @@ -306,7 +306,7 @@ p_node - xml node (parent node) ''' def dev_in_raid(): """if the device in raid or not""" devices_in_raid=set() - for r in Raid.list: + for r in Raid.dict.values(): devices_in_raid.update(r.active_components) devices_in_raid.update(r.spare_components) return devices_in_raid @@ -339,7 +339,7 @@ class MountPoint: MountPoint(dev, fs=Partition.dict[dev].filesystem) for dev in Raid.dict.keys(): - if MountPoint.dict.has_key(dev) + if MountPoint.dict.has_key(dev): continue MountPoint(dev) From 92fc6d04bf9146cc8895df2c75cd6e7ba748f9b7 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:43:54 +0800 Subject: [PATCH 20/37] modified: ri_tk_cmd.py update date list--->dict --- interface/ri_tk_cmd.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 3d98b93..6a629de 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -20,7 +20,7 @@ def mount_list_init(): ''' initialize mount list ''' l = [] ri_data.MountPoint.init_from_internal() - for m in ri_data.MountPoint.list: + for m in ri_data.MountPoint.dict.values(): # get size from Partition info sz = ri_data.Partition.get_size(m.device) if not sz: @@ -41,7 +41,7 @@ def mp_top_init(): if len(idxs) == 1: idx = int(idxs[0]) - mp = ri_data.MountPoint.list[idx] + mp = ri_data.MountPoint.dict.values()[idx] dev = mp.device dir = mp.directory fs = mp.filesystem @@ -72,7 +72,7 @@ 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.list: + for m in ri_data.Partition.dict.values(): if m.device == dev2: base_fs = m.filesystem if len(idxs2) and fm =='yes' : @@ -262,7 +262,7 @@ def raid_raw_init(): 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.list + raw_devs = [ p.device for p in ri_data.Partition.dict.values() if p.israid=='yes' and p.device not in devs ] display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) @@ -301,7 +301,7 @@ def raid_spare_to_raw(): def raid_device_init(): ''' initialize raid device list ''' - raid_devs = [ r.device for r in ri_data.Raid.list ] + raid_devs = [ r.device for r in ri_data.Raid.dict.values()] display.var_dict['raid_devs'].set(value=tuple(raid_devs)) def raid_calc_size(level, devs): @@ -312,7 +312,7 @@ devs - raid component devices # all devs shall have same size. unit=ri_data.Partition.unit dev_size_list=[] - for p in ri_data.Partition.list: + for p in ri_data.Partition.dict.values(): if p.device in devs: dev_size_list.append(float(p.size)) dev_size_list.sort() @@ -366,7 +366,7 @@ def raid_device_delete(): idxs = win_dev.curselection() if len(idxs) == 1: idx = int(idxs[0]) - r = ri_data.Raid.list[idx] + r = ri_data.Raid.dict.values()[idx] if r.from_os == 'yes': ri_widget.MessageBox.dict["raid_delete_warning"].show() return @@ -384,7 +384,7 @@ def raid_device_delete(): # 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] + del ri_data.Raid.dict.values()[idx] raid_device_init() def raid_device_list_detail(*args): @@ -393,7 +393,7 @@ def raid_device_list_detail(*args): idxs = win.curselection() if len(idxs) == 1: idx = int(idxs[0]) - r = ri_data.Raid.list[idx] + r = ri_data.Raid.dict.values()[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))) From 1f01c5ff85ef69159f402fb3b7cacceae2c9dda1 Mon Sep 17 00:00:00 2001 From: fling Date: Fri, 15 Oct 2010 18:52:42 +0800 Subject: [PATCH 21/37] modified: ../xml/interface.xml update main.help --- xml/interface.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xml/interface.xml b/xml/interface.xml index cb38257..55a1d5a 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -982,7 +982,8 @@ row 4 | | - Display frame illustrate which type of service will be supported after installation. Gray box means this service cann't be supported because there is no match with software package. + The color of the servers listed in the frame suggests whether they are self-starting since system startup. Gary means no, and the probable + reason is packages providing the servers haven't been selected to install. 显示框中表示系统启动过程中自动启动的服务。 From 56609c0fec4f4ecd82d21a8e0e205dbe06596c84 Mon Sep 17 00:00:00 2001 From: fling Date: Sat, 16 Oct 2010 11:32:06 +0800 Subject: [PATCH 22/37] modified: ri_data.py fix class Partition and test it is ok fill Raid.get_size mothod. --- interface/ri_data.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index 3ce1626..ae946df 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -4,6 +4,7 @@ import re import commands from xml.dom import minidom from xml.dom.ext import PrettyPrint +from ri_tk_cmd import raid_calc_size # xml file names install_xml = '../xml/install.xml' @@ -114,14 +115,16 @@ class Partition: 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(), # start + 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 - s[flg_i:].strip() # flags + re.search('raid',s[flg_i:]) and 'yes' or 'no' # flags + "yes" #from os ) @staticmethod @@ -148,7 +151,7 @@ p_node - xml node (parent node)''' unit_attr = doc.createAttribute('unit') unit_attr.value = Partition.unit pts.setAttributeNode(unit_attr) - for p in Partition.list: + for p in Partition.dict.values(): pt = doc.createElement('partition') dev_attr = doc.createAttribute('device') start_attr = doc.createAttribute('start') @@ -252,7 +255,7 @@ l - list doc - xml document instance p_node - xml node (parent node) ''' raids = doc.createElement('raids') - for r in Raid.list: + for r in Raid.dict.values(): rd = doc.createElement('raid') rd_dev_attr = doc.createAttribute('device') @@ -289,8 +292,9 @@ p_node - xml node (parent node) ''' #ri_tk_cmd.py use @staticmethod def get_size(dev): - # need fill - pass + active=Raid.dict[dev].active + level=Raid.dict[dev].level + return raid_calc_size(level,active) @staticmethod def get_next_device(): @@ -366,7 +370,7 @@ class MountPoint: doc - xml document instance p_node - xml node (parent node)''' mps = doc.createElement('mount-points') - for m in MountPoint.list: + for m in MountPoint.dict.values(): mp = doc.createElement('mount-point') dev_attr = doc.createAttribute('device') dir_attr = doc.createAttribute('directory') From dffc9194cd4a6cc7bc9cd89b6141fb49ba6dbd4d Mon Sep 17 00:00:00 2001 From: fling Date: Sat, 16 Oct 2010 18:26:28 +0800 Subject: [PATCH 23/37] modified: ri_data.py add mothod of Raid.get_size --- interface/ri_data.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index ae946df..483ae88 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -1,10 +1,10 @@ #!/usr/bin/python import re +import sys import commands from xml.dom import minidom from xml.dom.ext import PrettyPrint -from ri_tk_cmd import raid_calc_size # xml file names install_xml = '../xml/install.xml' @@ -49,15 +49,14 @@ class Partition: self.size = sz self.type = tp self.filesystem = fs - self.flags = fg + self.israid = fg self.from_os = fr Partition.dict[dev] = self @staticmethod def init_from_os(): ''' create a Partition instance from hardware info''' - device_list=[] - Partition.unit='GB' + Partition.unit='MB' cmd_cat = 'cat /proc/partitions' st,o = commands.getstatusoutput(cmd_cat) @@ -123,10 +122,10 @@ class Partition: 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 + re.search('raid',s[flg_i:]) and 'yes' or 'no', # flags "yes" #from os ) - + @staticmethod def init_from_xml(node): ''' create Partition instances from xml node ''' @@ -138,7 +137,7 @@ class Partition: 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['israid'].value.encode('ascii'),\ p.attributes['from_os'].value.encode('ascii')) @@ -158,28 +157,30 @@ p_node - xml node (parent node)''' size_attr = doc.createAttribute('size') type_attr = doc.createAttribute('type') fs_attr = doc.createAttribute('file-system') - flags_attr = doc.createAttribute('flags') + israid_attr = doc.createAttribute('israid') 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 - flags_attr.value = p.flags + israid_attr.value = p.israid 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(flags_attr) + pt.setAttributeNode(israid_attr) pt.setAttributeNode(from_attr) pts.appendChild(pt) p_node.appendChild(pts) # ri_tk_cmd.py use @staticmethod def get_size(dev): - return Partition.dict[dev].size + if Partition.dict.has_key(dev): + return Partition.dict[dev].size + return class Raid: ''' raid information ''' @@ -292,9 +293,20 @@ p_node - xml node (parent node) ''' #ri_tk_cmd.py use @staticmethod def get_size(dev): - active=Raid.dict[dev].active + sz=sys.maxint level=Raid.dict[dev].level - return raid_calc_size(level,active) + 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': + return str(sz) + elif level == '5': + sz=sz*(len(active)-1) + return str(sz) @staticmethod def get_next_device(): @@ -353,6 +365,8 @@ class MountPoint: for dev in s1-s2: del MountPoint.dict[dev] + #MountPoint.dict.keys().sort() + #print "keys=",MountPoint.dict.keys() @staticmethod def init_from_xml(node): From f536b578c5e88b62cb86c22e83eb1b029827cd46 Mon Sep 17 00:00:00 2001 From: fling Date: Sat, 16 Oct 2010 22:35:50 +0800 Subject: [PATCH 24/37] modified: ri_tk_cmd.py fix: ri_data.Raid(dev, "no", level,active, spare) sz = ri_data.Partition.dict.has_key(dev) and \ ri_data.Partition.dict[dev].size or ri_data.Raid.get_size(dev) display index data of Mount.dict --- interface/ri_tk_cmd.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 6a629de..072103c 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -27,6 +27,7 @@ def mount_list_init(): 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 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,15 +39,16 @@ def mp_top_init(): ''' mount dir top window initialize ''' ml_win = ri_widget.Widget.dict['mount.list'].tk_widget idxs = ml_win.curselection() - + key_sort_list=ri_data.MountPoint.dict.keys() + key_sort_list.sort() if len(idxs) == 1: idx = int(idxs[0]) - mp = ri_data.MountPoint.dict.values()[idx] + mp = ri_data.MountPoint.dict[key_sort_list[idx]] dev = mp.device dir = mp.directory fs = mp.filesystem fm = mp.format - sz = mp.size + 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) @@ -351,7 +353,7 @@ def raid_device_add(): return dev = ri_data.Raid.get_next_device() - ri_data.Raid(dev, "no", level, raid_calc_size(level, active), active, spare) + ri_data.Raid(dev, "no", level,active, spare) raid_device_init() display.var_dict['raid_active_devs'].set(value='') From 9322af8a4f2c2c020bd08d2932af463b7f76d329 Mon Sep 17 00:00:00 2001 From: fling Date: Sun, 17 Oct 2010 00:21:01 +0800 Subject: [PATCH 25/37] modified: ri_tk_cmd.py fix display index data of Mount.dict, top_windows, raid, etc. --- interface/ri_tk_cmd.py | 130 ++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 79 deletions(-) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 072103c..9db87a8 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -38,29 +38,25 @@ def mount_list_modify(*args): def mp_top_init(): ''' mount dir top window initialize ''' ml_win = ri_widget.Widget.dict['mount.list'].tk_widget - idxs = ml_win.curselection() - key_sort_list=ri_data.MountPoint.dict.keys() - key_sort_list.sort() - if len(idxs) == 1: - idx = int(idxs[0]) - mp = ri_data.MountPoint.dict[key_sort_list[idx]] - 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() + 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() - 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 ''' @@ -75,13 +71,13 @@ def mp_top_ok(): 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 + 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 + fs = base_fs s2 = dev.ljust(10) + dir.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6)+ri_data.Partition.unit l.append(s2) # make change in internal data structure @@ -283,6 +279,7 @@ 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(): @@ -303,31 +300,10 @@ def raid_spare_to_raw(): def raid_device_init(): ''' initialize raid device list ''' - raid_devs = [ r.device for r in ri_data.Raid.dict.values()] + raid_devs = [ d for d in ri_data.Raid.dict.keys()] + raid_devs.sort() 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 - dev_size_list=[] - for p in ri_data.Partition.dict.values(): - if p.device in devs: - dev_size_list.append(float(p.size)) - dev_size_list.sort() - sz=float(dev_size_list[0]) - if level == '0': - sz=sz*len(devs) - return str(sz) - elif level == '1': - return str(sz) - elif level == '5': - sz=sz*(len(devs)-1) - return str(sz) - def raid_device_add(): ''' add a new raid device ''' if display.var_dict['raid_active_devs'].get()=='': @@ -365,40 +341,36 @@ 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 - idxs = win_dev.curselection() - if len(idxs) == 1: - idx = int(idxs[0]) - r = ri_data.Raid.dict.values()[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())) + 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())) - 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.values()[idx] - 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.dict[get_dev] + 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 - idxs = win.curselection() - if len(idxs) == 1: - idx = int(idxs[0]) - r = ri_data.Raid.dict.values()[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))) + 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))) def install_information_init(): '''install information initialize''' From 6df3e0f7baebff3593a796a23444545f4edf9a63 Mon Sep 17 00:00:00 2001 From: fling Date: Sun, 17 Oct 2010 09:49:48 +0800 Subject: [PATCH 26/37] modified: ri_data.py fix: add a raid device , must be del partition on MountPoint.dict --- interface/ri_data.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index 483ae88..c69bc6c 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -175,9 +175,10 @@ p_node - xml node (parent node)''' 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 @@ -290,12 +291,12 @@ 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 + 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) @@ -303,6 +304,7 @@ p_node - xml node (parent node) ''' 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) @@ -358,15 +360,18 @@ class MountPoint: 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()) for dev in s1-s2: - del MountPoint.dict[dev] - - #MountPoint.dict.keys().sort() - #print "keys=",MountPoint.dict.keys() + if MountPoint.dict.has_key(dev): + del MountPoint.dict[dev] @staticmethod def init_from_xml(node): From 6e699121400606799054f767038b6f88c6549af3 Mon Sep 17 00:00:00 2001 From: fling Date: Sun, 17 Oct 2010 19:57:17 +0800 Subject: [PATCH 27/37] modified: ri_oper.py format --- interface/ri_oper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 0e5452b..0338486 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -204,7 +204,7 @@ class GenerateIssue(Operation): def get_arguments(self): args=[] # FIXME if tag file format is error? - if os.path.isfile("/tag") : + if os.path.isfile("/tag"): fd=open("/tag","r") string = fd.read() list = string.split('\n')[0].split('-') From 73871b03ac6450a5e98d7e110cfdba58352864b9 Mon Sep 17 00:00:00 2001 From: fling Date: Sun, 17 Oct 2010 20:47:08 +0800 Subject: [PATCH 28/37] modified: ri_inst_tk.py tk placement --- interface/ri_inst_tk.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/interface/ri_inst_tk.py b/interface/ri_inst_tk.py index 130e978..9b85af2 100644 --- a/interface/ri_inst_tk.py +++ b/interface/ri_inst_tk.py @@ -66,34 +66,30 @@ lab_progress_bar=Label(root,text='%s:'%(language=="chinese" and u"进度" \ lab_operation=Label(root,text="") lab_linx=Label(root,text="Linx") -txt_suboperation=Text(root,width=70,height=10) +txt_suboperation=Text(root,width=100,height=10) #operation lable and taskname -lab_task.grid (row=1, column=0, sticky='SEW') -lab_operation.grid (row=1, column=1, columnspan=2,sticky="S") -txt_suboperation.grid(row=2, column=1,columnspan=2) -lab_progress_bar.grid(row=3, column=0, sticky='NEW') -lab_linx.grid (row=4, column=1, sticky='E') +lab_task.grid (row=1, column=0, sticky='E') +lab_operation.grid (row=1, column=1, sticky='') +txt_suboperation.grid(row=2, column=1) +lab_progress_bar.grid(row=3, column=0) +lab_linx.grid (row=4, column=1, sticky='') #logo photo_bm = PhotoImage(file="%s/../data/linxlogo.gif"\ %os.path.split(os.path.realpath(__file__))[0]) logo_label=Label(root,image=photo_bm) -logo_label.grid(row=0,column=0,padx=50,pady=50,sticky='NW') +logo_label.grid(row=0,column=0,padx=50, pady=50, sticky='NW') #progress bar scl_progress=Scale(root,orient=HORIZONTAL,resolution=0.01,digits=4,from_=0,to=100,variable=stringvar_bar,label='%') -scl_progress.grid(row=3,column=1,columnspan=2,sticky='NEW') +scl_progress.grid(row=3,column=1,padx=50, sticky='NEW') #root root.rowconfigure(0,weight=1) root.rowconfigure(1,weight=1) -root.rowconfigure(2,weight=1) root.rowconfigure(3,weight=1) root.rowconfigure(4,weight=1) -root.columnconfigure(0,weight=1) root.columnconfigure(1,weight=1) -root.columnconfigure(2,weight=1) -root.columnconfigure(3,weight=1) From 4a4d822cfd54e348667dca1d2abbf576c3a307ae Mon Sep 17 00:00:00 2001 From: lizhi-rocky Date: Mon, 18 Oct 2010 10:55:19 +0800 Subject: [PATCH 29/37] modify based on code inspection comments. - continue work in weekend. --- interface/ri_data.py | 44 ++++++++++----- interface/ri_dep.py | 16 ++---- interface/ri_tk.py | 9 ++- interface/ri_tk_cmd.py | 123 ++++++++++++++++++----------------------- 4 files changed, 95 insertions(+), 97 deletions(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index eab7177..a06ab8b 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -10,7 +10,7 @@ install_xml = '../xml/install.xml' config_xml = '../xml/config.xml' def to_xml_attr(doc, node, cls, name): - ''' This method is called by to_xml. Its function is to create an attribute, and set its value based on Network data member + ''' This method is called by to_xml. Its function is to create an attribute, and set its value based on xml data member doc - xml document node - xml node cls - python class/python instance @@ -289,8 +289,13 @@ p_node - xml node (parent node) ''' #ri_tk_cmd.py use @staticmethod def get_size(dev): - # need fill - pass + ''' get raid device size ''' + rd = Raid.dict[dev] + sz = min([ Partition.dict[d].size for d in rd.active_components]) + if rd.level == '0': return sz*len(rd.active_components) + elif rd.level == '1': return sz + elif rd.level == '5': return sz*len(rd.active_components) #??? + @staticmethod def get_next_device(): @@ -383,6 +388,14 @@ p_node - xml node (parent node)''' mps.appendChild(mp) p_node.appendChild(mps) + @staticmethod + def get_size(dev): + '''get size of this mount point ''' + if dev in Partition.dict.keys(): + return Partition.get_size(dev) + elif dev in Raid.dict.keys(): + return Raid.get_size(dev) + class Network: ''' network ''' hostname ='' @@ -527,6 +540,20 @@ p_node - xml node (parent node)''' grp.appendChild(optl) grps.appendChild(grp) p_node.appendChild(grps) + @staticmethod + def get_install_pkgs(): + ''' get package names that should be installed ''' + l = [] + for g in Group.dict.values(): + if g.install != 'no': + l.extend([ p for p in g.mandatory ]) + if g.selection == 'manual': + l.extend([ p[0] for p in g.optional if p[1] == 'yes' ]) + elif g.selection == 'all': + l.extend([ p[0] for p in g.optional ]) + else: # selection is 'none' + pass + return l class Service: ''' service ''' @@ -564,16 +591,7 @@ p - pkg, that includes this service def change_state(): ''' Based on package information in Group class, change 'start' data member from 'disable' to 'no', or from 'yes'/'no' to 'disable' ''' - l = [] - for g in Group.dict.values(): - if g.install == 'mandatory' or g.install == 'yes': - l.extend(g.mandatory) - if g.selection == 'all': - l.extend([ n for n, i in g.optional]) - elif g.selection == 'manual': - l.extend([ n for n, i in g.optional if i == 'yes']) - else: # selection is 'none' - pass + l = Group.get_install_pkgs() for s in Service.list: if s.package in l: diff --git a/interface/ri_dep.py b/interface/ri_dep.py index a36dff9..8b42694 100644 --- a/interface/ri_dep.py +++ b/interface/ri_dep.py @@ -62,16 +62,7 @@ def construct_depended(): Depended.dict[dep].depended_by.add(d.name) def get_extra_depending(pkg_list = []): - l = [] - for g in ri_data.Group.dict.values(): - if g.install != 'no': - l.extend([ p for p in g.mandatory ]) - if g.selection == 'manual': - l.extend([ p[0] for p in g.optional if p[1] == 'yes' ]) - else: - l.extend([ p[0] for p in g.optional ]) - - l = l + pkg_list + l = ri_data.Group.get_install_pkgs() + pkg_list set1 = set(l) set2 = set(set1) @@ -79,9 +70,12 @@ def get_extra_depending(pkg_list = []): for d in set1: set2.update(Depending.dict[d].depending) + global extra_pkgs + extra_pkgs = set2.difference(set1) res = {} - for d in set2.difference(set1): + for d in extra_pkgs: res[d] = Depended.dict[d].depended_by.intersection(set1) return res +extra_pkgs = [] diff --git a/interface/ri_tk.py b/interface/ri_tk.py index c20d605..5849248 100644 --- a/interface/ri_tk.py +++ b/interface/ri_tk.py @@ -6,6 +6,7 @@ import tkMessageBox import sys import ri_cmd import ri_widget +import os.path var_dict={} # language should be all lower case letters @@ -55,8 +56,6 @@ def create_widget(w): set_step_info(w.name) set_help_info('#'+w.name+'.help') -import os.path - class MyImage: ''' MyImage - a dummy class to hold Image variable ''' count = 0 @@ -97,6 +96,8 @@ def create_widget_sub(w, p_win): if not v_n in var_dict.keys(): # if not yet in dict, create it var_dict[v_n] = getattr(Tkinter, v_t)(value=v_v) + else: + print 'error: variable(%s) already defined' %v_n # change attr, if needed to suit tk tk_attr = dict(w.attr) @@ -217,7 +218,6 @@ class SoftwarePackageWindow(): class member --------------------------- dict - class static member - --------------------------- instance member --------------------------- @@ -343,6 +343,9 @@ class SoftwarePackageWindow(): Tkinter.Button(win, text='OK', command=self.ok).grid(column=0, row=6, pady=2) Tkinter.Button(win, text='Cancel', command=self.cancel).grid(column=1, row=6, pady=2) + # bind WM_DELETE_WINDOW + win.protocol("WM_DELETE_WINDOW", self.cancel) + win.after_idle(lambda : cnv1.configure(scrollregion=(0,0, fr1.winfo_width(), fr1.winfo_height()))) win.after_idle(lambda : cnv2.configure(scrollregion=(0,0, fr2.winfo_width(), fr2.winfo_height()))) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 875eaa3..3ae58f6 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -22,9 +22,7 @@ def mount_list_init(): ri_data.MountPoint.init_from_internal() for d in ri_data.MountPoint.dict.keys().sort(): # get size from Partition info - sz = ri_data.Partition.get_size(d) - if not sz: - sz = ri_data.Raid.get_size(d) + sz = MountPoint.get_size(d) m = ri_data.MountPoint.dict[d] s = m.device.ljust(10) + m.directory.ljust(10) + m.filesystem.ljust(10) + m.format.ljust(4) + sz.ljust(6) l.append(s) @@ -41,15 +39,16 @@ def mp_top_init(): idxs = ml_win.curselection() if len(idxs) == 1: idx = int(idxs[0]) - mp = ri_data.MountPoint.list[idx] - dev = mp.device - dir = mp.directory + l = eval(display.var_dict['mount.list'].get()) + dev = l[idx].split()[0] + mp = ri_data.MountPoint.dict[dev] + dr = mp.directory fs = mp.filesystem fm = mp.format - sz = mp.size + sz = MountPoint.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) + display.var_dict['mp_top_dir'].set(value=dr) if fm == 'yes': ri_widget.Widget.dict['mp_top_format'].tk_widget.select() else: @@ -66,24 +65,22 @@ def mp_top_ok(): for itm in eval(display.var_dict['mount.list'].get()): dev = itm.split()[0] dev2 = display.var_dict['mp_top_dev'].get() - base_fs='' if dev == dev2: sz = display.var_dict['mp_top_size'].get() - dir = display.var_dict['mp_top_dir'].get() + dr = 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.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] - elif fm=='no': - fs = base_fs - s2 = dev.ljust(10) + dir.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6) - l.append(s2) + # if format, use the filesystem just set + idx2 = int(idxs2[0]) + fs = eval(display.var_dict['mp_top_fs'].get())[idx2] + else: + # else use the filesystem in Partition + fs = dev in Partition.dict.keys() and Partition.dict[dev].filesystem + s2 = dev.ljust(10) + dr.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) + ri_data.MountPoint.change(dev, dir, fs, fm) else: l.append(itm) @@ -133,12 +130,12 @@ class GroupButton(object): dict={} def __init__(self, g): self.name = g.name + self.win = display.SoftwarePackageWindow(g) GroupButton.dict[g.name] = self - display.SoftwarePackageWindow(g) + def __call__(self): - print self.name - display.SoftwarePackageWindow.dict[self.name].show() + self.win.show() class GroupCheck(GroupButton): ''' A function class called whenever the group check button is checked ''' @@ -191,10 +188,8 @@ def software_group_optional_quit(): ''' software group window quit, record optional group state ''' opt = [ o for o in ri_data.Group.dict.values() if o.install != 'mandatory' ] for i in opt: - print i.name vn = "software_group_%s" %(i.name) i.install = display.var_dict[vn].get() - print i.name, i.install def dependency_list_init(): ''' init function for list in dependency step ''' @@ -261,13 +256,10 @@ def raid_raw_init(): if not raid_raw_initialized: raid_raw_initialized = True # get all component devices already in raid - 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) + dev_in_raid = ri_data.Raid.dev_in_raid() - raw_devs = [ p.device for p in ri_data.Partition.list - if p.flags=='yes' and p.device not in 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 ] display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) def list_to_list(list_from, var_from, var_to): @@ -308,38 +300,18 @@ def raid_device_init(): 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()=='': - ri_widget.MessageBox.dict["raid_add_active_warning"].show() - return - else: + try: active = list(eval(display.var_dict['raid_active_devs'].get())) - if display.var_dict['raid_spare_devs'].get()=='': - spare=[] - else: + except: + active = [] + + try: spare = list(eval(display.var_dict['raid_spare_devs'].get())) + except: + spare = [] + level = display.var_dict['raid_level'].get() if not active or not level: @@ -347,7 +319,7 @@ def raid_device_add(): return dev = ri_data.Raid.get_next_device() - ri_data.Raid(dev, "no", level, raid_calc_size(level, active), active, spare) + ri_data.Raid(dev, "no", level, active, spare) raid_device_init() display.var_dict['raid_active_devs'].set(value='') display.var_dict['raid_spare_devs'].set(value='') @@ -361,25 +333,30 @@ def raid_device_delete(): idxs = win_dev.curselection() if len(idxs) == 1: idx = int(idxs[0]) - r = ri_data.Raid.list[idx] + try: + l = eval(display.var_dict['raid_devs'].get()) + except: + # a null string? + return + dev = l[idx].split()[0] + r = ri_data.Raid.dict[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: + try: active = list(eval(display.var_dict['raid_active_devs'].get())) - if display.var_dict['raid_spare_devs'].get()=='': - spare=[] - else: + except: + active=[] + try: spare = list(eval(display.var_dict['raid_spare_devs'].get())) - + except: + spare=[] 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] + del ri_data.Raid.dict[dev] raid_device_init() def raid_device_list_detail(*args): @@ -388,7 +365,13 @@ def raid_device_list_detail(*args): idxs = win.curselection() if len(idxs) == 1: idx = int(idxs[0]) - r = ri_data.Raid.list[idx] + try: + l = eval(display.var_dict['raid_devs'].get()) + except: + # a null string? + return + dev = l[idx].split()[0] + r = ri_data.Raid.dict[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))) From fa939fbd9fc90f165ce63a9a25c21bab6bb5375e Mon Sep 17 00:00:00 2001 From: lizhi-rocky Date: Mon, 18 Oct 2010 10:46:34 +0800 Subject: [PATCH 30/37] incorporate Ling Fen's fix --- interface/mine/install_xml.py | 107 ---------------------------------- interface/ri_data.py | 45 ++++++++------ 2 files changed, 27 insertions(+), 125 deletions(-) delete mode 100644 interface/mine/install_xml.py diff --git a/interface/mine/install_xml.py b/interface/mine/install_xml.py deleted file mode 100644 index 85b28f7..0000000 --- a/interface/mine/install_xml.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/python - -import sys -from xml.dom import minidom -import Tkinter - -def attr_to_dict(attr): - ''' convert (widget or grid_location) attributes into a dict ''' - dict = {} - for a in attr.values(): - if a.name == 'image': - dict[a.name] = Tkinter.PhotoImage(file=a.value) - elif a.name == 'command': - module = sys.modules[__name__] - dict[a.name] = getattr(module, a.value) - else: - dict[a.name] = a.value - return dict - -def construct_widget_dict(): - ''' Go through all widget xml nodes on first level, I mean, those widgets defined -inside other widget will not be checked. If the widget has a name, it will -be recorded in the widget_dict.''' - widgets = [e for e in xmldoc.firstChild.childNodes - if e.nodeType == e.ELEMENT_NODE and e.nodeName == "widget"] - for w in widgets: - if "name" in w.attributes.keys(): - widget_dict[w.attributes["name"].value] = w - -def widget(w_xml, p_win): - ''' create a widget. - w_xml is a xml node describing the widget. - p_win is the parent widget.''' - func = getattr(Tkinter, w_xml.attributes["type"].value) - # convert attributes into dictionary - wa_list = [wa for wa in w_xml.childNodes - if wa.nodeType == wa.ELEMENT_NODE and wa.nodeName =="widget_attribute"] - if wa_list: - # only process the first element, and there should be only one element. - attr_dict = attr_to_dict(wa_list[0].attributes) - w_win = func(p_win, attr_dict) - else: - w_win = func(p_win) - - gm_list = [m for m in w_xml.childNodes - if m.nodeType == m.ELEMENT_NODE and m.nodeName == "grid_management"] - gl_list = [l for l in w_xml.childNodes - if l.nodeType == l.ELEMENT_NODE and l.nodeName == "grid_location"] - w_list = [ w for w in w_xml.childNodes - if w.nodeType == w.ELEMENT_NODE and w.nodeName == "widget" ] - - for w in w_list: - widget(w, w_win) - - for m in gm_list: - for cf in m.childNodes: - if cf.nodeType != m.ELEMENT_NODE or cf.nodeName != "configure": - continue - if "row" in cf.attributes.keys(): - cf_func = getattr(w_win, "rowconfigure") - n = cf.attributes["row"].value - elif "column" in cf.attributes.keys(): - cf_func = getattr(w_win, "columnconfigure") - n = cf.attributes["column"].value - else: - continue - cf_func(n, weight=cf.attributes["weight"].value) - # only process the first item - break - - for l in gl_list: - ld = attr_to_dict(l.attributes) - w_win.grid(ld) - # only process the first item - break - -def display(): - ''' Display a series of widgets ''' - root_window = Tkinter.Tk() - - # first display the main frame - widget(widget_dict["main"], root_window) - root_window.columnconfigure(0, weight=1) - root_window.rowconfigure(0, weight=1) - root_window.geometry('800x600+0+0') - root_window.mainloop() - -# commands for buttons -def quit(): - print "quit" - -def previous_step(): - print "previous step" - -def next_step(): - - print "next step" - -xmldoc = minidom.parse("../../xml/interface_t.xml") - -widget_dict={} -construct_widget_dict() - -sequence_dict={} -construct_sequence_dict() - -display() diff --git a/interface/ri_data.py b/interface/ri_data.py index eab7177..8d8c22c 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -55,7 +55,6 @@ class Partition: @staticmethod def init_from_os(): ''' create a Partition instance from hardware info''' - device_list=[] Partition.unit='GB' cmd_cat = 'cat /proc/partitions' @@ -82,7 +81,7 @@ class Partition: 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] + 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" @@ -114,14 +113,14 @@ class Partition: flg_i= s.find('Flags') if tp_i < 0: tp_i=fs_i located = True - - if located: + elif located: Partition(d+s[nm_i:st_i].strip(), # device name - s[st_i:end_i].strip(), # start + 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 - s[flg_i:].strip() # flags + s[flg_i:].strip(), # flags + 'yes' ) @staticmethod @@ -148,7 +147,8 @@ p_node - xml node (parent node)''' unit_attr = doc.createAttribute('unit') unit_attr.value = Partition.unit pts.setAttributeNode(unit_attr) - for p in Partition.list: + for k in Partition.dict.keys().sort(): + p = Partition.dict[k] pt = doc.createElement('partition') dev_attr = doc.createAttribute('device') start_attr = doc.createAttribute('start') @@ -173,10 +173,13 @@ p_node - xml node (parent node)''' pt.setAttributeNode(from_attr) pts.appendChild(pt) p_node.appendChild(pts) - # ri_tk_cmd.py use + @staticmethod def get_size(dev): - return Partition.dict[dev].size + try: + return Partition.dict[dev].size + except: + return None class Raid: ''' raid information ''' @@ -252,7 +255,8 @@ l - list doc - xml document instance p_node - xml node (parent node) ''' raids = doc.createElement('raids') - for r in Raid.list: + for k in Raid.dict.keys().sort(): + r = Raid.dict[k] rd = doc.createElement('raid') rd_dev_attr = doc.createAttribute('device') @@ -289,8 +293,12 @@ p_node - xml node (parent node) ''' #ri_tk_cmd.py use @staticmethod def get_size(dev): - # need fill - pass + ''' 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 sz*len(rd.active_components) + elif rd.level == '1': return sz*len(rd.active_components)/2 + elif rd.level == '5': return sz*(len(rd.active_components)-1) @staticmethod def get_next_device(): @@ -306,7 +314,7 @@ p_node - xml node (parent node) ''' def dev_in_raid(): """if the device in raid or not""" devices_in_raid=set() - for r in Raid.list: + for r in Raid.dict.values(): devices_in_raid.update(r.active_components) devices_in_raid.update(r.spare_components) return devices_in_raid @@ -339,13 +347,13 @@ class MountPoint: MountPoint(dev, fs=Partition.dict[dev].filesystem) for dev in Raid.dict.keys(): - if MountPoint.dict.has_key(dev) - continue + if MountPoint.dict.has_key(dev): continue MountPoint(dev) - # now process whether a partition or raid was removed + # now delete unexist partition/raid mount point, or + # partition that used in raid. s1 = set(MountPoint.dict.keys()) - s2 = set(Partition.dict.keys() + Raid.dict.keys()) + s2 = set(Partition.dict.keys() + Raid.dict.keys()) - set(dev_in_raid) for dev in s1-s2: del MountPoint.dict[dev] @@ -366,7 +374,8 @@ class MountPoint: doc - xml document instance p_node - xml node (parent node)''' mps = doc.createElement('mount-points') - for m in MountPoint.list: + for k in MountPoint.dict.keys().sort(): + m = MountPoint.dict[k] mp = doc.createElement('mount-point') dev_attr = doc.createAttribute('device') dir_attr = doc.createAttribute('directory') From f2818afcb901c6b5f8b2af49f1e910040e859903 Mon Sep 17 00:00:00 2001 From: lizhi-rocky Date: Mon, 18 Oct 2010 11:32:24 +0800 Subject: [PATCH 31/37] 1. modify ri_oper.py to include dependcy extra pkgs 2. incorporate Ling Fen's modification on ri_tk_cmd.py --- interface/ri_oper.py | 13 ++----------- interface/ri_tk_cmd.py | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 20b9c7b..e127a8c 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -17,6 +17,7 @@ # Ling Fen 2010-09-04 create import ri_data +import ri_dep import os import subprocess @@ -173,17 +174,7 @@ class InstallPkg(Operation): self.return_value[3]=("package in source doesn't exist",u"软件包不存在") def get_stdin(self): - pkgname=[] - for i in ri_data.Group.dict.values(): - if i.install=='no': - continue - else: - pkgname+=i.mandatory - if i.selection=='all': - pkgname += [ j[0] for j in i.optional ] - else: - pkgname += [ j[0] for j in i.optional if j[1] == 'yes' ] - + pkgname = ri_data.Group.get_install_pkgs() + ri_dep.extra_pkgs self.steps += len(pkgname) return '\n'.join(pkgname) diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py index 3ae58f6..cfc50fa 100644 --- a/interface/ri_tk_cmd.py +++ b/interface/ri_tk_cmd.py @@ -74,11 +74,13 @@ def mp_top_ok(): # if format, use the filesystem just set idx2 = int(idxs2[0]) fs = eval(display.var_dict['mp_top_fs'].get())[idx2] - else: + elif dev in Partition.dict.keys(): # else use the filesystem in Partition - fs = dev in Partition.dict.keys() and Partition.dict[dev].filesystem - s2 = dev.ljust(10) + dr.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6) - l.append(s2) + fs = Partition.dict[dev].filesystem + else: + fs = ' ' + s2 = dev.ljust(10) + dr.ljust(10) + fs.ljust(10) + fm.ljust(4) + sz.ljust(6) + ri_data.Partition.unit + l.append(s2) # make change in internal data structure ri_data.MountPoint.change(dev, dir, fs, fm) else: @@ -259,7 +261,7 @@ def raid_raw_init(): 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 ] + if re.search('raid', ri_data.Partition.dict[d].flags) and d not in dev_in_raid ].sort() display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs)) def list_to_list(list_from, var_from, var_to): @@ -276,7 +278,7 @@ def list_to_list(list_from, var_from, var_to): l_to = list(eval(display.var_dict[var_to].get())) l_to.append(itm) else: - l_to = [ itm ] + l_to = [ itm ].sort() display.var_dict[var_to].set(value=tuple(l_to)) def raid_raw_to_active(): @@ -297,7 +299,7 @@ def raid_spare_to_raw(): def raid_device_init(): ''' initialize raid device list ''' - raid_devs = [ r.device for r in ri_data.Raid.list ] + raid_devs = [ k for k in ri_data.Raid.keys() ].sort() display.var_dict['raid_devs'].set(value=tuple(raid_devs)) def raid_device_add(): @@ -317,6 +319,12 @@ def raid_device_add(): 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_numbers_2"].show() + return dev = ri_data.Raid.get_next_device() ri_data.Raid(dev, "no", level, active, spare) @@ -376,11 +384,10 @@ def raid_device_list_detail(*args): 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''' ins_info = ri_data.install_information() t= ri_widget.Widget.dict['install_information.list'].tk_widget t.insert(1.0,ins_info) +raid_raw_initialized = False From a20990551bd53710cdb2f454615ae97751c725c1 Mon Sep 17 00:00:00 2001 From: fling Date: Mon, 18 Oct 2010 12:53:30 +0800 Subject: [PATCH 32/37] modified: ../xml/interface.xml add swap filesystem on top_windows --- xml/interface.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/interface.xml b/xml/interface.xml index 55a1d5a..20def4e 100644 --- a/xml/interface.xml +++ b/xml/interface.xml @@ -804,7 +804,7 @@ row 4 | | - + From 378e927993b833af6966156375325defda4d6af9 Mon Sep 17 00:00:00 2001 From: fling Date: Mon, 18 Oct 2010 13:53:57 +0800 Subject: [PATCH 33/37] modified: ri_oper.py fix: confiugre fstab --- interface/ri_oper.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 0338486..79a0b39 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -196,6 +196,17 @@ class ConfigureFstab(Mount): Operation.__init__(self,'Configure /etc/fstab',u'配置/etc/fstab文件','configure_fstab.sh',scr) self.return_value[2]=("/etc/fstab doesn't exist",u"/etc/fstab文件不存在") + def get_stdin(self): + fstab='' + flag=True + for d in MountPoint.dict.values(): + if d.filesystem != '' and d.directory !='': + fstab += "/dev/%s %s %s\n" %(d.device, d.directory, d.filesystem) + elif d.filesystem == 'swap' and flag: + fstab += "/dev/%s swap swap\n" %d.device + flag=False + return fstab + class GenerateIssue(Operation): """class for generate /etc/issue""" def __init__(self,scr): @@ -312,12 +323,10 @@ class ConfigureBootloader(Operation): for instance in ri_data.MountPoint.dict.values(): if instance.directory == '/' and not isroot: bootloader+=['-r',instance.device] - print "root" isroot=True continue if isroot and instance.directory == '/boot' and not isboot : bootloader+=['-b',instance.device] - print "boot" isboot=True continue From 5fb6a5ea494cf98d2d76b1166bcf35f25b99e54b Mon Sep 17 00:00:00 2001 From: fling Date: Mon, 18 Oct 2010 15:05:07 +0800 Subject: [PATCH 34/37] modified: ri_data.py --- interface/ri_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/ri_data.py b/interface/ri_data.py index c69bc6c..978f549 100644 --- a/interface/ri_data.py +++ b/interface/ri_data.py @@ -220,7 +220,7 @@ class Raid: else: act_cmpts.append(ss[:ss.index('[')]) - Raid(raid_dev, "yes", raid_level, raid_size, act_cmpts, spr_cmpts) + Raid(raid_dev, "yes", raid_level, act_cmpts, spr_cmpts) @staticmethod def add_component(node, l): From 1dbcc675c35068651d5921c304c0e1d2ab838f00 Mon Sep 17 00:00:00 2001 From: fling Date: Mon, 18 Oct 2010 15:07:49 +0800 Subject: [PATCH 35/37] modified: ../operation/install.txt --- operation/install.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operation/install.txt b/operation/install.txt index 717a568..959c318 100644 --- a/operation/install.txt +++ b/operation/install.txt @@ -65,7 +65,7 @@ Usage: 配置fstab,configure_fstab.sh 输入: stdin - 1)block devices:块设备,(swap则用by-id,其他都用by-uuid) + 1)block devices:块设备 2)mount point:挂载点 3)filesystem type:文件系统类型 以下参数为可选参数,如果不指定,会有默认的配置,如果指定5)那么4)也需要指定,依次类推 From 0042ee1fc7c90141bf3fde9c5ee57cb0210eef6c Mon Sep 17 00:00:00 2001 From: fling Date: Mon, 18 Oct 2010 15:17:24 +0800 Subject: [PATCH 36/37] modified: ri_oper.py --- interface/ri_oper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/ri_oper.py b/interface/ri_oper.py index 79a0b39..ca4cd5e 100644 --- a/interface/ri_oper.py +++ b/interface/ri_oper.py @@ -21,7 +21,7 @@ import os import subprocess if os.path.isfile("../xml/install.xml"): - ri_data.init_from_xml() + ri_data.init_from_xml() display_operation = None display_sub_operation = None From e8934228dc7ed201158e6ec51e2d26be7fd66bde Mon Sep 17 00:00:00 2001 From: lizhi-rocky Date: Mon, 18 Oct 2010 16:30:46 +0800 Subject: [PATCH 37/37] 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