modified: ri_data.py

modified:   ri_oper.py
    Unified tab
This commit is contained in:
fling
2010-10-15 10:57:30 +08:00
parent 400911c41a
commit 25270097e3
2 changed files with 277 additions and 278 deletions

View File

@@ -11,10 +11,10 @@ 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
doc - xml document
node - xml node
cls - python class/python instance
name - attribute name'''
doc - xml document
node - xml node
cls - python class/python instance
name - attribute name'''
attr = doc.createAttribute(name)
attr.value = getattr(cls, name)
node.setAttributeNode(attr)
@@ -30,8 +30,8 @@ class SerialNumber:
@staticmethod
def to_xml(doc, p_node):
''' write SerialNumber into xml
doc - xml document instance
p_node - xml node (parent node)'''
doc - xml document instance
p_node - xml node (parent node)'''
sn = doc.createElement('serial-number')
data = doc.createTextNode(SerialNumber.value)
sn.appendChild(data)
@@ -67,49 +67,49 @@ class Partition:
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:
ret = re.search(r".+([sh][a-zA-Z]+)\s*",s)
if ret:
if ret.group(1) in device_list:
continue
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():
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]
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+=['','','']
ret[2]=ret[2][:-len(Partition.unit)]
ret[3]=ret[3][:-len(Partition.unit)]
ret[4]=ret[4][:-len(Partition.unit)]
if "raid" in ret[6:] or "raid," in ret[6:]:
# 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+=['','','']
ret[2]=ret[2][:-len(Partition.unit)]
ret[3]=ret[3][:-len(Partition.unit)]
ret[4]=ret[4][:-len(Partition.unit)]
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[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')
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')
@staticmethod
def init_from_xml(node):
''' create Partition instances from xml node '''
@@ -129,8 +129,8 @@ class Partition:
@staticmethod
def to_xml(doc, p_node):
''' write all Partition instance into xml
doc - xml document instance
p_node - xml node (parent node)'''
doc - xml document instance
p_node - xml node (parent node)'''
pts = doc.createElement("partitions")
unit_attr = doc.createAttribute('unit')
unit_attr.value = Partition.unit
@@ -145,14 +145,14 @@ p_node - xml node (parent node)'''
size_attr = doc.createAttribute('size')
type_attr = doc.createAttribute('type')
fs_attr = doc.createAttribute('file-system')
israid_attr = doc.createAttribute('israid')
israid_attr = doc.createAttribute('israid')
from_attr = doc.createAttribute('from_os')
dev_attr.value = p.device
start_attr.value = p.start
size_attr.value = p.size
type_attr.value = p.type
fs_attr.value = p.filesystem
israid_attr.value = p.israid
israid_attr.value = p.israid
from_attr.value = p.from_os
pt.setAttributeNode(dev_attr)
pt.setAttributeNode(start_attr)
@@ -163,7 +163,7 @@ p_node - xml node (parent node)'''
pt.setAttributeNode(from_attr)
pts.appendChild(pt)
p_node.appendChild(pts)
# ri_tk_cmd.py use
# ri_tk_cmd.py use
@staticmethod
def get_size(dev):
for p in Partition.list:
@@ -341,8 +341,7 @@ class MountPoint:
if mp.device == dev:
mp.directory = dir
mp.filesystem = fs
mp.format = fm
mp.format = fm
def device(self):
return self.device