complete software group screen
This commit is contained in:
167
python/ri_cmd.py
167
python/ri_cmd.py
@@ -1,13 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
''' handle gui button related commands.'''
|
||||
''' handle commands.'''
|
||||
|
||||
import ri_tk as display
|
||||
import ri_widget
|
||||
import ri_data
|
||||
|
||||
import re
|
||||
import copy
|
||||
import sys
|
||||
|
||||
def quit():
|
||||
''' correspond to quit button '''
|
||||
@@ -40,163 +34,6 @@ def next():
|
||||
else:
|
||||
ri_widget.MessageBox.dict["next"].show()
|
||||
|
||||
def serial_no_init():
|
||||
display.var_dict['serial_no.number'].set(value=ri_data.SerialNumber.value)
|
||||
|
||||
def serial_no_quit():
|
||||
ri_data.SerialNumber.value = display.var_dict['serial_no.number'].get()
|
||||
|
||||
|
||||
def mount_list_init():
|
||||
''' initialize mount list '''
|
||||
l = []
|
||||
for m in ri_data.MountPoint.list:
|
||||
# get size from Partition info
|
||||
sz = ri_data.Partition.get_size(m.device)
|
||||
if not sz:
|
||||
sz = ri_data.Raid.get_size(m.device)
|
||||
print m.device, m.directory, m.filesystem, m.format, sz
|
||||
s = m.device.ljust(10) + m.directory.ljust(10) + m.filesystem.ljust(10) + m.format.ljust(4) + sz.ljust(6)
|
||||
l.append(s)
|
||||
display.var_dict['mount.list'].set(value=tuple([str(i) for i in l]))
|
||||
|
||||
def mount_list_modify(*args):
|
||||
''' modify an item in mount list '''
|
||||
tw = ri_widget.TopWindow.dict['mount_list_modify']
|
||||
tw.show()
|
||||
|
||||
def mp_top_init():
|
||||
''' mount dir top window initialize '''
|
||||
ml_win = ri_widget.Widget.dict['mount.list'].tk_widget
|
||||
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)
|
||||
|
||||
def mp_top_ok():
|
||||
''' mount dir top window OK '''
|
||||
l = []
|
||||
for itm in eval(display.var_dict['mount.list'].get()):
|
||||
dev = itm.split()[0]
|
||||
dev2 = display.var_dict['mp_top_dev'].get()
|
||||
if dev == dev2:
|
||||
sz = display.var_dict['mp_top_size'].get()
|
||||
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()
|
||||
if len(idxs2):
|
||||
idx2 = int(idxs2[0])
|
||||
fs = eval(display.var_dict['mp_top_fs'].get())[idx2]
|
||||
else:
|
||||
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)
|
||||
else:
|
||||
l.append(itm)
|
||||
|
||||
display.var_dict['mount.list'].set(value=tuple(l))
|
||||
ri_widget.TopWindow.dict['mount_list_modify'].hide()
|
||||
|
||||
def mp_top_cancel():
|
||||
''' mount dir top window cancel '''
|
||||
ri_widget.TopWindow.dict['mount_list_modify'].hide()
|
||||
pass
|
||||
|
||||
def network_init():
|
||||
''' network initialize '''
|
||||
display.var_dict['network_host_name']. set(value=ri_data.Network.hostname)
|
||||
ri_widget.Widget.dict['network_config_%s' %(ri_data.Network.configuration and ri_data.Network.configuration or 'static')].tk_widget.invoke()
|
||||
display.var_dict['network_domain_name']. set(value=ri_data.Network.domain)
|
||||
display.var_dict['network_ip']. set(value=ri_data.Network.ip)
|
||||
display.var_dict['network_subnet_mask']. set(value=ri_data.Network.mask)
|
||||
display.var_dict['network_gateway']. set(value=ri_data.Network.gateway)
|
||||
display.var_dict['network_primary_dns']. set(value=ri_data.Network.primary_dns)
|
||||
display.var_dict['network_secondary_dns'].set(value=ri_data.Network.secondary_dns)
|
||||
|
||||
def network_quit():
|
||||
''' network quit '''
|
||||
ri_data.Network.hostname = display.var_dict['network_host_name'].get()
|
||||
ri_data.Network.configuration = display.var_dict['network_config_method'].get()
|
||||
ri_data.Network.domain = display.var_dict['network_domain_name'].get()
|
||||
ri_data.Network.ip = display.var_dict['network_ip'].get()
|
||||
ri_data.Network.mask = display.var_dict['network_subnet_mask'].get()
|
||||
ri_data.Network.gateway = display.var_dict['network_gateway'].get()
|
||||
ri_data.Network.primary_dns = display.var_dict['network_primary_dns'].get()
|
||||
ri_data.Network.secondary_dns = display.var_dict['network_secondary_dns'].get()
|
||||
|
||||
def ncm_dynamic():
|
||||
''' when radio button ncm dynamic is checked, several data entry will be set 'disable' '''
|
||||
|
||||
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='disable')
|
||||
|
||||
def ncm_static():
|
||||
''' when radio button ncm static is checked, several data entry will be set 'normal' '''
|
||||
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:
|
||||
wi = copy.deepcopy(wit)
|
||||
wi.attr['text'] = i.name
|
||||
vn = "software_group_%s" %(i.name)
|
||||
wi.attr['variable'] = vn
|
||||
wi.variables = [(vn, 'StringVar', ''),]
|
||||
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():
|
||||
pass
|
||||
|
||||
def software_group_quit():
|
||||
pass
|
||||
|
||||
def software_group_item():
|
||||
pass
|
||||
from ri_tk_cmd import *
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ from xml.dom import minidom
|
||||
from xml.dom.ext import PrettyPrint
|
||||
|
||||
# xml file names
|
||||
install_xml = '../../xml/install.xml'
|
||||
config_xml = './config.xml'
|
||||
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
|
||||
@@ -361,6 +361,7 @@ g_node - group node '''
|
||||
elif grp_chld.nodeName == 'optional':
|
||||
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'])
|
||||
g.selection = grp_chld.attributes['selection'].value
|
||||
init_from_xml = init_from_install_xml
|
||||
@staticmethod
|
||||
def to_xml(doc, p_node):
|
||||
@@ -397,6 +398,9 @@ p_node - xml node (parent node)'''
|
||||
|
||||
if g.optional:
|
||||
optl = doc.createElement('optional')
|
||||
sel_attr = doc.createAttribute('selection')
|
||||
sel_attr.value = g.selection
|
||||
optl.setAttributeNode(sel_attr)
|
||||
for o in g.optional:
|
||||
pkg = doc.createElement('package')
|
||||
pname_attr = doc.createAttribute('name')
|
||||
|
||||
@@ -184,24 +184,40 @@ def destroy_top_window(w):
|
||||
w.tk_widget.destroy()
|
||||
|
||||
class SoftwarePackageWindow():
|
||||
''' Toplevel window for a group of software packages '''
|
||||
''' Toplevel window for a group of software packages
|
||||
class member
|
||||
---------------------------
|
||||
dict - class static member
|
||||
---------------------------
|
||||
|
||||
instance member
|
||||
---------------------------
|
||||
group - data layer group instance
|
||||
win - Tk widget
|
||||
selection - StringVar variable for 'select_all'
|
||||
opt_vars - a list to hold variables containing status for optional packages
|
||||
opt_chks - a list to hold Checkbuttons for optional packages
|
||||
'''
|
||||
dict = {}
|
||||
def __init__(self, g):
|
||||
self.group = g
|
||||
self.optional = []
|
||||
self.opt_vars = []
|
||||
self.opt_chks = []
|
||||
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
|
||||
if self.selection.get() == 'all':
|
||||
for ck in self.opt_chks:
|
||||
ck.configure(state='disable')
|
||||
|
||||
|
||||
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.group.optional[i][1] = self.opt_vars[i].get()
|
||||
self.win.destroy()
|
||||
|
||||
def cancel(self):
|
||||
@@ -241,7 +257,7 @@ class SoftwarePackageWindow():
|
||||
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="")
|
||||
self.selection = Tkinter.StringVar(value=self.group.selection)
|
||||
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':
|
||||
@@ -270,16 +286,20 @@ class SoftwarePackageWindow():
|
||||
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')
|
||||
self.opt_vars.append(v)
|
||||
chk = Tkinter.Checkbutton(fr2, text=name, onvalue='yes', offvalue='no', variable=self.opt_vars[i])
|
||||
self.opt_chks.append(chk)
|
||||
chk.grid(column=i%5, row=i/5, sticky='NWS')
|
||||
if y_n == 'yes':
|
||||
chk.select()
|
||||
else:
|
||||
chk.deselect()
|
||||
|
||||
if self.group.selection == 'all':
|
||||
chk.configure(state='disable')
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
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())))
|
||||
@@ -293,5 +313,5 @@ class SoftwarePackageWindow():
|
||||
pass
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
win.wait_window()
|
||||
|
||||
@@ -7,6 +7,7 @@ import ri_data
|
||||
import sys
|
||||
import getopt
|
||||
from xml.dom import minidom
|
||||
import os.path
|
||||
|
||||
def print_usages():
|
||||
print 'Usages: %s [-b|--begin step_name] [interface_xml_file] [install_xml_file]' %sys.argv[0]
|
||||
@@ -34,8 +35,11 @@ else:
|
||||
|
||||
xmldoc = minidom.parse(itf_xml)
|
||||
ri_data.install_xml = ins_xml
|
||||
ri_data.init_from_xml()
|
||||
#ri_data.init()
|
||||
|
||||
if os.path.isfile(ins_xml):
|
||||
ri_data.init_from_xml()
|
||||
else:
|
||||
ri_data.init()
|
||||
|
||||
ri_widget.construct(xmldoc.firstChild)
|
||||
|
||||
@@ -49,7 +53,7 @@ main_sequence = ri_widget.Sequence.dict[main_sequence_name]
|
||||
if begin_step is None:
|
||||
begin_step = main_sequence.steps[0]
|
||||
else:
|
||||
main_sequence.set_step(begin_step)
|
||||
main_sequence.set_current_step(begin_step)
|
||||
|
||||
ri_widget.Widget.dict[begin_step].show()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user