modify based on code inspection comments. - continue work in weekend.

This commit is contained in:
lizhi-rocky
2010-10-18 10:55:19 +08:00
parent 4fe47045f6
commit 4a4d822cfd
4 changed files with 95 additions and 97 deletions

View File

@@ -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:

View File

@@ -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 = []

View File

@@ -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())))

View File

@@ -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)))