add ri_data mountpoint partition

modified:   di_dialog.py
This commit is contained in:
fling
2011-08-29 19:04:44 +08:00
parent 40e37daeb6
commit fabb293298

View File

@@ -1,79 +1,157 @@
import sys
import re
import commands
import dialog
sys.path.append('../interface/')
import ri_data
from xml.dom import minidom
from xml.dom.ext import PrettyPrint
#import ../interface/ri_data
#d=dialog.Dialog()
#d.setBackgroundTitle("Rocky 4.2 install")
install_xml='/var/install/install.xml'
class Dialog:
dialog
status=''
dict={}
def __init__(self,text='Rocky 4.2 install'):
def __init__(self,name='dialog',text='Rocky 4.2 install'):
Dialog.dialog=dialog.Dialog()
Dialog.dialog.setBackgroundTitle(text)
Dialog.dict[name] = self
def check(self):
return
def to_xml(self):
return
class SerialNumber(Dialog):
tuple=()
def __init__(self,height=10, width=30,text='plase input a serial number'):
Dialog.__init__(self)
class Welcome(Dialog):
def __init__(self,height=10,width=30,text='Welcome!\n\nThis script will guide you through the installation of RSS packages.\n\nIf you want to install the system, then please continue, else abort the installation and come back later.\n\nAre you really sure you want to continue?'):
Dialog.__init__(self,name='welcome')
self.text=text
self.height=height
self.width=width
def get_welcome(self):
Dialog.status=Dialog.dialog.yesno(self.text,self.height,self.width,title='welcome')
class SerialNumber(Dialog):
number=''
def __init__(self,height=10, width=30,text='plase input a serial number'):
Dialog.__init__(self,name='serialnumber')
self.text=text
self.height=height
self.width=width
Dialog.dict['serialnumber'] = self
def get_number(self):
SerialNumber.tuple=Dialog.dialog.inputbox(self.text,self.height,self.width)
def check_nubmer(self):
if SerialNumber.tuple[0] == 0 :
if len(SerialNumber.tuple[1]) == 12 or SerialNumber.tuple[1] == '' :
return True
return False
def to_xml(self,doc,p_node,data):
sn = doc.createElement('serial-number')
data = doc.createTextNode(data)
sn.appendChild(data)
p_node.appendChild(sn)
s,SerialNumber.number=Dialog.dialog.inputbox(self.text,self.height,self.width,title='serial number',extra_button='edit')
print s
if s == 0 or s == 1 :
return
else:
SerialNumber.get_number(self)
def show(self):
print SerialNumber.tuple
def bigen(self,xmldoc,root):
SerialNumber.get_number(self)
while not SerialNumber.check_nubmer(self):
Dialog.dialog.msgbox('serial number must be 12 length or none',10,30)
SerialNumber.get_number(self)
SerialNumber.to_xml(self,xmldoc,root,SerialNumber.tuple[1])
class MountPoint(Dialog):
fs=''
dict={}
def __init__(self,height=15,width=24,text='Please input the mounting point of your partition:'):
Dialog.__init__(self,name='mountpoint')
self.text=text
self.height=height
self.width=width
def choice_fstype(self,device):
#device is sdaX
#mp is mount point
list=[('ext2','Ext2 is the traditional Linux file system.'),\
('ext3','Ext3 is the journaling version of the Ext2 file system.'),\
('reiserfs','ReiserFS is a journaling file system.'),\
('xfs',"XFS is SGI's jounaling filesystem that originated on IRIX."),\
('jfs',"JFS is IBM's journaled filesystem."),\
('swap','SWAP is a swap')]
# menu return "(status,choice)"
s,fs= Dialog.dialog.menu(self.text,self.height,self.width,choices=list,title='mount point',default_item='ext3')
if s == 0:
ri_data.MountPoint.dict[device].filesystem=fs
return s
def mount_point(self,device):
s,mp=Dialog.dialog.inputbox(text='plase input mount point',height=10,width=30,init='/')
if s == 0:
ri_data.MountPoint.dict[device].directory=mp
return s
def is_format(self,device):
s = Dialog.dialog.yesno(text='format the device',title='Format')
if s == 0 :
ri_data.MountPoint.dict[device].format='yes'
else:
ri_data.MountPoint.dict[device].format='no'
return s
def choice_device(self):
while True:
list=[]
keys=ri_data.MountPoint.dict.keys()
keys.sort()
for d in keys:
list.append((ri_data.MountPoint.dict[d].device,ri_data.MountPoint.dict[d].directory.ljust(10)+ri_data.MountPoint.dict[d].filesystem.ljust(5)+ri_data.MountPoint.dict[d].format.ljust(5)+ri_data.Partition.dict[d].size+ri_data.Partition.unit))
s,d=Dialog.dialog.menu(text='device map',height=self.height,width=self.width,menu_height=self.height/5*4,choices=list,title='MountPoint')
if s == 0:
count=0
function_list=[self.choice_fstype,self.mount_point,self.is_format]
while True:
ret = function_list[count](d)
if ret == 1:
count = count - 1
elif ret == 0 :
count = count + 1
if count <0 or count >2 :
break
elif s == 1 :
break
else:
print "error"
class Partition(Dialog):
list=[]
def __init__(self,heigth=15,width=54,text='Partitions'):
Dialog.__init__(self)
self.heigth=heigth
self.width=width
self.text=text
def init(self):
count=0
list=[self.choice_device,self.mount_point,self.is_format]
while True:
list[count](self)
def get_number(self):
Dialog.dialog.menu(self.text,self.heigth,self.width,Partitions.list)
# s,fs=self.choice_fstype(d)
# if s == 0:
# ri_data.MountPoint.dict[d].filesystem=fs
# s,mp=self.mount_point()
# if s == 0 :
# ri_data.MountPoint.dict[d].directory=mp
f = file(install_xml, 'w')
xmldoc = minidom.Document()
root = xmldoc.createElement('install')
xmldoc.appendChild(root)
# if status == 1:
# break
S=SerialNumber(10,50)
S.bigen(xmldoc,root)
S.show()
#Welcome(15,50)
#Dialog.dict['welcome'].get_welcome()
#print Dialog.status
ri_data.Partition.init_from_os()
print ri_data.Partition.dict.keys()
ri_data.MountPoint.init_from_internal()
print ri_data.MountPoint.dict.keys()
MountPoint(20,75)
#Dialog.dict['mountpoint'].init_data()
Dialog.dict['mountpoint'].choice_device()
#Dialog.dict['mountpoint'].is_format()
#Dialog.dict['mountpoint'].choice_fstype()
#Dialog.dict['mountpoint'].check_list()
#SerialNumber(10,50)
#Dialog.dict['serialnumber'].get_number()
PrettyPrint(xmldoc, f)
f.close()