254 lines
9.9 KiB
Python
254 lines
9.9 KiB
Python
#!/usr/bin/python
|
|
''' handle gui commands '''
|
|
import ri_tk as display
|
|
import ri_widget
|
|
import ri_data
|
|
import ri_dep
|
|
|
|
import re
|
|
import copy
|
|
import sys
|
|
|
|
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 GroupButton(object):
|
|
''' A function class called whenever the group button is clicked '''
|
|
dict={}
|
|
def __init__(self, g):
|
|
self.name = g.name
|
|
GroupButton.dict[g.name] = self
|
|
display.SoftwarePackageWindow(g)
|
|
|
|
def __call__(self):
|
|
print self.name
|
|
display.SoftwarePackageWindow.dict[self.name].show()
|
|
|
|
class GroupCheck(GroupButton):
|
|
''' A function class called whenever the group check button is checked '''
|
|
def __init__(self, g, v):
|
|
self.variable = v
|
|
GroupButton.__init__(self, g)
|
|
|
|
def __call__(self):
|
|
v = display.var_dict[self.variable]
|
|
if v.get() == 'yes':
|
|
display.SoftwarePackageWindow.dict[self.name].show()
|
|
|
|
def software_group_mandatory_construct(w):
|
|
''' construct widgets based actual data
|
|
w - Widget instance '''
|
|
mdt = [ m for m in ri_data.Group.dict.values() if m.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)
|
|
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 = GroupButton(i)
|
|
setattr(sys.modules['ri_cmd'], vn, gc)
|
|
wi.attr['command'] = vn
|
|
w.add_sub_widget(wi)
|
|
|
|
def software_group_optional_construct(w):
|
|
''' construct widgets based actual data
|
|
w - Widget instance '''
|
|
opt = [ o for o in ri_data.Group.dict.values() if o.install != 'mandatory' ]
|
|
wit = w.widgets.pop()
|
|
for i in opt:
|
|
wi = copy.deepcopy(wit)
|
|
wi.attr['text'] = i.name
|
|
vn = "software_group_%s" %(i.name)
|
|
idx = opt.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, vn)
|
|
setattr(sys.modules['ri_cmd'], vn, gc)
|
|
wi.attr['command'] = vn
|
|
wi.attr['variable'] = vn
|
|
wi.variables = [(vn, 'StringVar', i.install),]
|
|
w.add_sub_widget(wi)
|
|
|
|
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 '''
|
|
ri_dep.construct_depending()
|
|
ri_dep.resolve_recursive_depending()
|
|
ri_dep.construct_depended()
|
|
dep_dict = ri_dep.get_extra_depending()
|
|
l = [ k.ljust(20) + ': ' + ' '.join(dep_dict[k]) for k in dep_dict.keys()]
|
|
display.var_dict['dependency.list'].set(value=tuple(l))
|
|
|
|
def service_construct(w):
|
|
''' construct service widget based on actual data
|
|
w - Widget instance '''
|
|
|
|
# first refresh service state
|
|
ri_data.Service.change_state()
|
|
wit = w.widgets.pop()
|
|
for i in ri_data.Service.list:
|
|
wi = copy.deepcopy(wit)
|
|
wi.attr['text'] = i.name
|
|
vn = "service_%s" %(i.name)
|
|
wi.attr['variable'] = vn
|
|
wi.variables = [(vn, 'StringVar', i.start=='yes' and 'yes' or 'no')]
|
|
if i.start == 'disable':
|
|
wi.attr['state'] = 'disable'
|
|
idx = ri_data.Service.list.index(i)
|
|
wi.grid_location.dict['column'] = idx % int(w.grid_management.columns)
|
|
wi.grid_location.dict['row'] = idx / int(w.grid_management.columns)
|
|
w.add_sub_widget(wi)
|
|
|
|
def service_quit():
|
|
''' record service state '''
|
|
for i in ri_data.Service.list:
|
|
if i.start != 'disable':
|
|
vn = "service_%s" %(i.name)
|
|
i.start = display.var_dict[vn].get()
|
|
|
|
def raid_raw_init():
|
|
''' initialize raid raw devices (parttion with id 'fd' '''
|
|
raw_devs = [ p.device for p in ri_data.Partition.list if p.id == 'fd' ]
|
|
display.var_dict['raid_raw_devs'].set(value=tuple(raw_devs))
|
|
|
|
def raid_raw_to_active():
|
|
''' move device from raw to active '''
|
|
raw_win = ri_widget.Widget.dict['raid_raw.list'].tk_widget
|
|
idxs = raw_win.curselection()
|
|
if len(idxs) == 1:
|
|
idx = int(idxs[0])
|
|
raw_list = list(eval(display.var_dict['raid_raw_devs'].get()))
|
|
raw_item = raw_list[idx]
|
|
del raw_list[idx]
|
|
print raw_list
|
|
display.var_dict['raid_raw_devs'].set(value=tuple(raw_list))
|
|
active_list = list(eval(display.var_dict['raid_active_devs'].get()))
|
|
active_list.append(raw_item)
|
|
display.var_dict['raid_active_devs'].set(value=tuple(active_list))
|
|
|
|
def raid_device_init():
|
|
''' initialize raid device list '''
|
|
raid_devs = [ r.device for r in ri_data.Raid.list if r.from_os == 'no' ]
|
|
display.var_dict['raid_dev.list'].set(value=tuple(raid_devs))
|