hand write code for software package

almost finished
This commit is contained in:
lizhi-rocky
2010-07-29 17:17:22 +08:00
parent 6f296eb876
commit a88fd5b5ae
8 changed files with 656 additions and 28 deletions

View File

@@ -8,6 +8,7 @@ import ri_data
import re
import copy
import sys
def quit():
''' correspond to quit button '''
@@ -153,22 +154,39 @@ def ncm_static():
for n in ('network_domain_name','network_ip','network_subnet_mask','network_gateway','network_primary_dns','network_secondary_dns'):
ri_widget.Widget.dict[n].tk_widget.configure(state='normal')
class GroupCheck(object):
''' A function class called whenever the group checkbox is clicked '''
dict={}
def __init__(self, n):
self.name = n
GroupCheck.dict[n] = self
def __call__(self):
print self.name
display.SoftwarePackageWindow.dict[self.name].show()
def software_group_construct(w):
''' draw group information on, based on actual data
w - Widget instance '''
for g in ri_data.Group.dict.values():
display.SoftwarePackageWindow(g)
mdt = [ m for m in ri_data.Group.dict.values() if m.install == 'mandatory' ]
opt = [ o for o in ri_data.Group.dict.values() if o.install != 'mandatory' ]
wit = w.widgets.pop()
for i in mdt:
print i
wi = copy.deepcopy(wit)
wi.attr['text'] = i.name
vn = "software_group_%s" %(i.name)
wi.attr['variable'] = vn
wi.variables = [(vn, 'StringVar', ''),]
wi.grid_location.dict['column'] = mdt.index(i)
wi.grid_location.dict['row'] = 0
idx = mdt.index(i)
wi.grid_location.dict['column'] = idx % int(w.grid_management.columns)
wi.grid_location.dict['row'] = idx / int(w.grid_management.columns)
gc = GroupCheck(i.name)
setattr(sys.modules[__name__], vn, gc)
wi.attr['command'] = vn
w.add_sub_widget(wi)
def software_group_init():
@@ -179,3 +197,5 @@ def software_group_quit():
def software_group_item():
pass

View File

@@ -309,7 +309,7 @@ g_node - group node '''
if n.attributes['install'].value == 'mandatory':
g.mandatory.append(n.attributes['package'].value.encode('ascii'))
else:
g.optional.append(n.attributes['package'].value.encode('ascii'), 'no')
g.optional.append([n.attributes['package'].value.encode('ascii'), 'no'])
@staticmethod
def init_from_config_xml(node):
@@ -338,7 +338,7 @@ g_node - group node '''
g.mandatory.extend([pkg.attributes['name'].value for pkg in grp_chld.childNodes
if pkg.nodeType == pkg.ELEMENT_NODE and pkg.nodeName == 'package'])
elif grp_chld.nodeName == 'optional':
g.optional.extend([(pkg.attributes['name'].value, pkg.attributes['install'].value) for pkg in grp_chld.childNodes
g.optional.extend([[pkg.attributes['name'].value, pkg.attributes['install'].value] for pkg in grp_chld.childNodes
if pkg.nodeType == pkg.ELEMENT_NODE and pkg.nodeName == 'package'])
init_from_xml = init_from_install_xml
@staticmethod
@@ -469,6 +469,16 @@ p_node - xml node (parent node)'''
srvs.appendChild(srv)
p_node.appendChild(srvs)
def init():
''' initialize '''
Partition.init_from_os()
Raid.init_from_os()
MountPoint.init_from_internal()
xmldoc_cfg = minidom.parse(config_xml)
root_cfg = xmldoc_cfg.firstChild
Group.init_from_config_xml(root_cfg)
Service.init_from_config_xml(root_cfg)
def init_from_xml():
''' init all classes in this module based input file (install xml) '''
xmldoc = minidom.parse(install_xml)

View File

@@ -166,3 +166,115 @@ def destroy_top_window(w):
''' w - Toplevel instance '''
w.tk_widget.destroy()
class SoftwarePackageWindow():
''' Toplevel window for a group of software packages '''
dict = {}
def __init__(self, g):
self.group = g
self.optional = []
SoftwarePackageWindow.dict[g.name] = self
def select_all(self):
''' callback function for check button select_all '''
self.group.selection = self.selection.get()
print self.group.selection
def ok(self):
''' callback function for button OK '''
self.group.selection = self.selection.get()
for i in range(len(self.group.optional)):
# install field, yes or no
self.group.optional[i][1] = self.optional[i].get()
self.win.destroy()
def cancel(self):
''' callback function for button cancel '''
self.win.destroy()
def show(self):
win = Tkinter.Toplevel(root_window)
self.win = win
win.geometry("%sx%s+%s+%s" %(int(root_window.winfo_screenwidth()*0.8),\
int(root_window.winfo_screenheight()*0.8),\
int(root_window.winfo_screenwidth()*0.1),\
int(root_window.winfo_screenheight()*0.1)))
win.columnconfigure(0, weight=1)
win.rowconfigure(1, weight=1)
win.rowconfigure(4, weight=1)
Tkinter.Label(win, text='Mandatory').grid(column=0, row=0)
cnv1 = Tkinter.Canvas(win)
hs1 = Tkinter.Scrollbar(win, orient='horizontal')
hs1.configure(command=cnv1.xview)
vs1 = Tkinter.Scrollbar(win, orient='vertical')
vs1.configure(command=cnv1.yview)
cnv1.grid(column=0, row=1, sticky='NWES')
vs1.grid(column=1, row=1, sticky='NSW')
hs1.grid(column=0, row=2, sticky='NWE')
cnv1.configure(yscrollcommand=vs1.set, xscrollcommand=hs1.set)
fr1 = Tkinter.Frame(cnv1)
cnv1.create_window((0,0), window=fr1, anchor='nw')
#column set to 5
fr1.columnconfigure(0, weight=1)
fr1.columnconfigure(1, weight=1)
fr1.columnconfigure(2, weight=1)
fr1.columnconfigure(3, weight=1)
fr1.columnconfigure(4, weight=1)
for i in range(len(self.group.mandatory)):
Tkinter.Label(fr1, text=self.group.mandatory[i]).grid(column=i%5, row=i/5, sticky='NWES')
Tkinter.Label(win, text='Optional').grid(column=0, row=3)
self.selection = Tkinter.StringVar(value="")
chk_sa = Tkinter.Checkbutton(win, text='Select all', command=self.select_all, variable=self.selection, onvalue='all', offvalue='manual')
chk_sa.grid(column=1, row=3)
if self.group.selection == 'all':
chk_sa.select()
else:
chk_sa.deselect()
cnv2 = Tkinter.Canvas(win)
hs2 = Tkinter.Scrollbar(win, orient='horizontal')
hs2.configure(command=cnv2.xview)
vs2 = Tkinter.Scrollbar(win, orient='vertical')
vs2.configure(command=cnv2.yview)
cnv2.grid(column=0, row=4, sticky='NWES')
vs2.grid(column=1, row=4, sticky='NSW')
hs2.grid(column=0, row=5, sticky='NWE')
cnv2.configure(yscrollcommand=vs2.set, xscrollcommand=hs2.set)
fr2 = Tkinter.Frame(cnv2)
cnv2.create_window((0,0), window=fr2, anchor='nw')
#column set to 5
fr2.columnconfigure(0, weight=1)
fr2.columnconfigure(1, weight=1)
fr2.columnconfigure(2, weight=1)
fr2.columnconfigure(3, weight=1)
fr2.columnconfigure(4, weight=1)
for i in range(len(self.group.optional)):
name, y_n = self.group.optional[i]
v = Tkinter.StringVar(value='no')
self.optional.append(v)
chk = Tkinter.Checkbutton(fr2, text=name, onvalue='yes', offvalue='no', variable=self.optional[i])
chk.grid(column=i%5, row=i/5, sticky='NWES')
if y_n == 'yes':
chk.select()
else:
chk.deselect()
Tkinter.Button(win, text='OK', command=self.ok).grid(column=0, row=6)
Tkinter.Button(win, text='Cancel', command=self.cancel).grid(column=1, row=6)
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())))
win.transient(root_window)
# grab all events into it
while True:
try:
win.grab_set()
except Tkinter.TclError:
pass
else:
break
win.wait_window()

View File

@@ -7,6 +7,8 @@ import ri_cmd
class GridManagement:
''' implement grid management '''
def __init__(self, xml_node):
self.rows = xml_node.attributes['rows'].value
self.columns = xml_node.attributes['columns'].value
self.cf_list=[]
for cf in xml_node.childNodes:
if cf.nodeType != cf.ELEMENT_NODE or cf.nodeName != "configure":

View File

@@ -36,6 +36,7 @@ else:
xmldoc = minidom.parse(itf_xml)
ri_data.install_xml = ins_xml
ri_data.init_from_xml()
#ri_data.init()
ri_widget.construct(xmldoc.firstChild)
ri_seq.construct(xmldoc.firstChild)