diff --git a/interface/ri_data.py b/interface/ri_data.py
index ee64be3..eab7177 100644
--- a/interface/ri_data.py
+++ b/interface/ri_data.py
@@ -40,8 +40,7 @@ p_node - xml node (parent node)'''
class Partition:
''' disk partition '''
unit=''
- label=''
- list=[]
+ dict={}
def __init__(self, dev, st, sz, tp, fs, fg, fr):
''' Partition init function '''
self.device = dev
@@ -51,67 +50,84 @@ class Partition:
self.filesystem = fs
self.flags = fg
self.from_os = fr
- Partition.list.append(self)
+ Partition.dict[dev] = self
@staticmethod
def init_from_os():
''' create a Partition instance from hardware info'''
device_list=[]
Partition.unit='GB'
- p = re.compile(r"\s*")
cmd_cat = 'cat /proc/partitions'
- fs_list=["ext2","ext3","fat32","fat16","ntfs","reiserfs","xfs","jfs","linux-swap"]
st,o = commands.getstatusoutput(cmd_cat)
if st:
print "Error cat : command not found or /proc/partitions dosen't exsit"
return
- for s in o.splitlines():
- ret = re.search(r".+([sh][a-zA-Z]+)\s*",s)
- if ret:
- if ret.group(1) in device_list:
- continue
- device_list.append(ret.group(1))
- for d in device_list:
- st,o=commands.getstatusoutput('parted /dev/%s unit %s print'%(d,Partition.unit))
- if st:
- print "Error parted :command not found"
- return
- for s in o.splitlines():
- ret = p.split(s)
- if ret[0]=='Partition':
- Partition.label=ret[-1]
- if len(ret) > 1 and ret[1].isdigit():
- # ret[0] is ['']
- #Number start end size type file_system flags
- # 1 2.0B 33GB 1GB primary raid
- # 2 32GB 33GB 1GB primary raid, boot ...
- # 3 32GB 33GB 1GB primary boot, raid, lbx ...
- # 4 32GB 33GB 1GB primary exit2 raid
- # 5 32GB 33GB 1GB primary exit2 raid, boot ...
- # 6 3.2kB 33GB 1GB primary
- # 7 32GB 33GB 1GB primary linx-swap
- # 8 32GB 33GB 1GB primary boot, lbx ...
- # 9 32GB 33GB 1GB primary exit2 boot
- #ret[1] ret[2] ret[3] ret[4] ret[5] ret[6] ret[7]
- ret+=['','','']
- if "raid" in ret[6:] or "raid," in ret[6:]:
- ret[7]='yes'
- if ret[6][:3].lower()=='raid' or ret[6].lower() not in fs_list:
- ret[6]=''
- else:
- ret[7]='no'
- if ret[6].lower() not in fs_list:
- ret[6]=''
- Partition(d+ret[1],ret[2],ret[4],ret[5],ret[6][:10] == "linux-swap" and "swap" or ret[6] ,ret[7],'yes')
+ # an example of `cat /proc/partitions`
+ # major minor #blocks name
+ #
+ # 8 0 488386584 sda
+ # 8 1 97659103 sda1
+ # 8 2 1951897 sda2
+ # 8 3 97659135 sda3
+ # 8 4 291113865 sda4
+ # 8 16 244197527 sdb
+ # 8 17 62918541 sdb1
+ # 8 18 4200997 sdb2
+ # 8 19 1 sdb3
+ # 8 21 1238016 sdb5
+ # 9 0 803136 md0
+ l = [ s.split()[-1] for s in o.splitlines() if re.match(r'\s*\d+', s)]
+ # devices : 1) sda, sdb(first if ), or md0 (second if)
+ for d in [ i for i in l if not re.search(r'\d+', i)
+ or re.search(r'([a-zA-Z]+)', i).group(1) not in l]
+ st,o=commands.getstatusoutput('parted /dev/%s unit %s print'%(d,Partition.unit))
+ if st:
+ print "Error parted execute error"
+ return
+ # an example of o's content
+ # Model: ATA Hitachi HDS72105 (scsi)
+ # Disk /dev/sda: 500GB
+ # Sector size (logical/physical): 512B/512B
+ # Partition Table: msdos
+ #
+ # Number Start End Size Type File system Flags
+ # 1 0.00GB 100GB 100GB primary ext3 boot
+ # 2 100GB 102GB 2.00GB primary linux-swap(v1)
+ # 3 102GB 202GB 100GB primary ext3
+ # 4 202GB 500GB 298GB primary ext3
+
+ located = False
+ for s in o.splitlines():
+ # Only match number, start, end, and size, that's enough.
+ # And when in raid case, no type appears.
+ title_p = re.compile('Number\s+Start\s+End\s+Size\s')
+ if title_p.match(s):
+ nm_i = s.find('Number')
+ st_i = s.find('Start')
+ end_i = s.find('End')
+ sz_i = s.find('Size')
+ tp_i = s.find('Type')
+ fs_i = s.find('File system')
+ flg_i= s.find('Flags')
+ if tp_i < 0: tp_i=fs_i
+ located = True
+
+ if located:
+ Partition(d+s[nm_i:st_i].strip(), # device name
+ s[st_i:end_i].strip(), # start
+ s[sz_i:tp_i].strip().rstrip(Partition.unit), # size
+ s[tp_i:fs_i].strip(), # type
+ re.search('swap', s[fs_i:flg_i]) and 'swap' or s[fs_i:flg_i].strip(), # file system
+ s[flg_i:].strip() # flags
+ )
@staticmethod
def init_from_xml(node):
''' create Partition instances from xml node '''
Partition.unit = node.attributes['unit'].value.encode('ascii')
- Partition.label = node.attributes['label'].value.encode('ascii')
for p in node.childNodes:
if p.nodeType == node.ELEMENT_NODE and p.nodeName == 'partition':
Partition(p.attributes['device'].value.encode('ascii'),\
@@ -132,9 +148,6 @@ p_node - xml node (parent node)'''
unit_attr = doc.createAttribute('unit')
unit_attr.value = Partition.unit
pts.setAttributeNode(unit_attr)
- label_attr = doc.createAttribute('label')
- label_attr.value = Partition.label
- pts.setAttributeNode(label_attr)
for p in Partition.list:
pt = doc.createElement('partition')
dev_attr = doc.createAttribute('device')
@@ -163,41 +176,31 @@ p_node - xml node (parent node)'''
# ri_tk_cmd.py use
@staticmethod
def get_size(dev):
- for p in Partition.list:
- if p.device == dev:
- return p.size
+ return Partition.dict[dev].size
class Raid:
''' raid information '''
- list = []
- def __init__(self, dev, from_os, level, sz, a_devs, s_devs=[]):
+ dict = {}
+ def __init__(self, dev, from_os, level, a_devs, s_devs=[]):
''' Raid init function '''
self.device = dev
self.from_os = from_os
self.level = level
- self.size = sz
self.active_components = a_devs
self.spare_components = s_devs
- Raid.list.append(self)
+ Raid.dict[dev] = self
@staticmethod
def init_from_os():
cmd = 'cat /proc/mdstat'
st, o = commands.getstatusoutput(cmd)
- if st:
- return
+ if st: return
dev_p = re.compile(r'''
^(md\d+)\s*: # md device
\s*active\s* # "active"
(\w+)\s* # raid type
''', re.VERBOSE)
- size_p = re.compile(r'''
- ^\s*(\d+) # block number
- \s*blocks
- ''', re.VERBOSE)
-
-
for s in o.splitlines():
dev_res = dev_p.split(s)
if len(dev_res)>1: # matched
@@ -211,15 +214,8 @@ class Raid:
spr_cmpts.append(ss[:ss.index('[')])
else:
act_cmpts.append(ss[:ss.index('[')])
- size = size_p.match(s)
- if size is not None:
- raid_size = size.groups()[0]
- # if already detect a raid dev
- if raid_dev:
- Raid(raid_dev, "yes", raid_level, raid_size, act_cmpts, spr_cmpts)
- # clear raid dev
- raid_dev=''
+ Raid(raid_dev, "yes", raid_level, raid_size, act_cmpts, spr_cmpts)
@staticmethod
def add_component(node, l):
@@ -239,7 +235,6 @@ l - list
raid_dev = e.attributes['device'].value
raid_from = e.attributes['from_os'].value
raid_level = e.attributes['level'].value
- raid_size = e.attributes['size'].value
act_cmpts = []
spr_cmpts = []
for sub_e in e.childNodes:
@@ -249,7 +244,7 @@ l - list
elif sub_e.nodeName == 'spare':
Raid.add_component(sub_e, spr_cmpts)
- Raid(raid_dev, raid_from, raid_level, raid_size, act_cmpts, spr_cmpts)
+ Raid(raid_dev, raid_from, raid_level, act_cmpts, spr_cmpts)
@staticmethod
def to_xml(doc, p_node):
@@ -272,10 +267,6 @@ p_node - xml node (parent node) '''
rd_level_attr.value = r.level
rd.setAttributeNode(rd_level_attr)
- rd_size_attr = doc.createAttribute('size')
- rd_size_attr.value = r.size
- rd.setAttributeNode(rd_size_attr)
-
rd_act_elem = doc.createElement('active')
for act_c in r.active_components:
act_c_e = doc.createElement('component')
@@ -298,74 +289,66 @@ p_node - xml node (parent node) '''
#ri_tk_cmd.py use
@staticmethod
def get_size(dev):
- for r in Raid.list:
- if r.device == dev:
- return r.size
+ # need fill
+ pass
@staticmethod
def get_next_device():
''' get next available raid device name '''
num_p = re.compile(r'md(\d+)')
- numbers = [ int(num_p.match(r.device).groups()[0]) for r in Raid.list ]
+ numbers = [ int(num_p.match(r).groups()[0]) for r in Raid.dict.keys() ]
max = 0
for n in numbers:
if n > max: max = n
return 'md%d' %(max+1)
+ @staticmethod
+ def dev_in_raid():
+ """if the device in raid or not"""
+ devices_in_raid=set()
+ for r in Raid.list:
+ devices_in_raid.update(r.active_components)
+ devices_in_raid.update(r.spare_components)
+ return devices_in_raid
+
class MountPoint:
''' mount-points '''
- list=[]
- def __init__(self, dev, dir='', fs='', fm='no', sz='0'):
+ dict={}
+ def __init__(self, dev, dir='', fs='', fm='no'):
self.device = dev
self.directory = dir
self.filesystem = fs
self.format = fm
- self.size = sz
- MountPoint.list.append(self)
+ MountPoint.dict[dev]=self
@staticmethod
def change(dev, dir, fs, fm):
- for mp in MountPoint.list:
- if mp.device == dev:
- mp.directory = dir
- mp.filesystem = fs
- mp.format = fm
+ mp = MountPoint.dict[dev]
+ mp.directory = dir
+ mp.filesystem = fs
+ mp.format = fm
-
- def device(self):
- return self.device
-
@staticmethod
def init_from_internal():
''' init MountPoint from internal class Partition and class Raid '''
- # add raid device in dev_in_raid
- dev_in_raid = set()
- for r in Raid.list:
- dev_in_raid.update(r.active_components)
- dev_in_raid.update(r.spare_components)
+ # add raid device in dev_in_raid
+ dev_in_raid = Raid.dev_in_raid()
- devs = [ m.device for m in MountPoint.list ]
- for p in Partition.list:
- if p.device not in devs and p.device not in dev_in_raid :
- MountPoint(p.device,fs=p.filesystem,sz=p.size)
+ for dev in set(Partition.dict.keys()).difference(set(dev_in_raid)):
+ if MountPoint.dict.has_key(dev): continue
+ MountPoint(dev, fs=Partition.dict[dev].filesystem)
- for r in Raid.list:
- if r.device not in devs and r.from_os == 'yes':
- f_s = [p.filesystem for p in Partition.list if p.device == r.active_components[0]]
- MountPoint(r.device, fs=''.join(f_s),sz=r.size)
- elif r.device not in devs:
- MountPoint(r.device,sz=r.size)
+ for dev in Raid.dict.keys():
+ if MountPoint.dict.has_key(dev)
+ continue
+ MountPoint(dev)
# now process whether a partition or raid was removed
- s1 = set([ m.device for m in MountPoint.list ])
- s2 = set([ p.device for p in Partition.list ] + [ r.device for r in Raid.list])
+ s1 = set(MountPoint.dict.keys())
+ s2 = set(Partition.dict.keys() + Raid.dict.keys())
for dev in s1-s2:
- for i in range(len(MountPoint.list)):
- if dev == MountPoint.list[i].device:
- del MountPoint.list[i]
- break
- # sort
- MountPoint.list.sort(key=MountPoint.device)
+ del MountPoint.dict[dev]
+
@staticmethod
def init_from_xml(node):
@@ -375,8 +358,7 @@ class MountPoint:
MountPoint(m.attributes['device'].value.encode('ascii'), \
m.attributes['directory'].value.encode('ascii'), \
m.attributes['file-system'].value.encode('ascii'), \
- m.attributes['format'].value.encode('ascii'),\
- m.attributes['size'].value.encode('ascii'))
+ m.attributes['format'].value.encode('ascii'))
@staticmethod
def to_xml(doc, p_node):
@@ -390,17 +372,14 @@ p_node - xml node (parent node)'''
dir_attr = doc.createAttribute('directory')
fs_attr = doc.createAttribute('file-system')
fm_attr = doc.createAttribute('format')
- sz_attr = doc.createAttribute('size')
dev_attr.value = m.device
dir_attr.value = m.directory
fs_attr.value = m.filesystem
fm_attr.value = m.format
- sz_attr.value = m.size
mp.setAttributeNode(dev_attr)
mp.setAttributeNode(dir_attr)
mp.setAttributeNode(fs_attr)
mp.setAttributeNode(fm_attr)
- mp.setAttributeNode(sz_attr)
mps.appendChild(mp)
p_node.appendChild(mps)
diff --git a/interface/ri_seq.py b/interface/ri_seq.py
deleted file mode 100644
index 9b2428d..0000000
--- a/interface/ri_seq.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/python
-
-class Sequence:
- ''' implement sequence in interface xml'''
- dict={}
-
- def __init__(self, xml_node):
- self.steps = [ s.attributes["name"].value for s in xml_node.childNodes
- if s.nodeType == s.ELEMENT_NODE and s.nodeName == "widget" ]
- self.current_step = 0
-
- def set_current_step(self, st):
- ''' set current step based on input step name'''
- self.current_step = self.steps.index(st)
-
- @staticmethod
- def set_current_sequence(name):
- Sequence.current_sequence = Sequence.dict[name]
-
- @staticmethod
- def current():
- return (Sequence.current_sequence, Sequence.current_sequence.steps[Sequence.current_sequence.current_step])
-
- @staticmethod
- def previous():
- if Sequence.current_sequence.current_step:
- Sequence.current_sequence.current_step -= 1
- return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
-
- @staticmethod
- def next():
- if Sequence.current_sequence.current_step < len(Sequence.current_sequence.steps)-1:
- Sequence.current_sequence.current_step += 1
- return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
-
-def construct(xml_root):
- ''' construct Sequence's static members'''
- for s in xml_root.childNodes:
- if s.nodeType == s.ELEMENT_NODE and s.nodeName == "sequence":
- Sequence.dict[s.attributes["name"].value] = Sequence(s)
-
-
diff --git a/interface/ri_tk_cmd.py b/interface/ri_tk_cmd.py
index 7914c86..875eaa3 100644
--- a/interface/ri_tk_cmd.py
+++ b/interface/ri_tk_cmd.py
@@ -18,19 +18,14 @@ def serial_no_quit():
def mount_list_init():
''' initialize mount list '''
- dev_in_raid = set()
l = []
- for r in ri_data.Raid.list:
- dev_in_raid.update(r.active_components)
- dev_in_raid.update(r.spare_components)
ri_data.MountPoint.init_from_internal()
- for m in ri_data.MountPoint.list:
+ for d in ri_data.MountPoint.dict.keys().sort():
# get size from Partition info
- if m.device in dev_in_raid:
- continue
- sz = ri_data.Partition.get_size(m.device)
+ sz = ri_data.Partition.get_size(d)
if not sz:
- sz = ri_data.Raid.get_size(m.device)
+ sz = ri_data.Raid.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)
display.var_dict['mount.list'].set(value=tuple([str(i) for i in l]))
diff --git a/xml/install_ng.xml b/xml/install_ng.xml
index dd26ab0..7b9bbf2 100644
--- a/xml/install_ng.xml
+++ b/xml/install_ng.xml
@@ -60,7 +60,6 @@
5
-