* yuksek-seviyeli yazici fonksiyonlarini gosterelim
This commit is contained in:
@@ -97,4 +97,6 @@ class SpecFile(XmlFile):
|
|||||||
self.newDOM()
|
self.newDOM()
|
||||||
self.addNodeText("Source/Name", self.source.name)
|
self.addNodeText("Source/Name", self.source.name)
|
||||||
archiveNode = self.addNode("Source/Archive")
|
archiveNode = self.addNode("Source/Archive")
|
||||||
|
archiveNode.setAttribute("archType", self.source.archiveType)
|
||||||
|
archiveNode.setAttribute("sha1sum", self.source.archiveSHA1)
|
||||||
self.writexml(filename)
|
self.writexml(filename)
|
||||||
|
|||||||
+26
-18
@@ -87,43 +87,51 @@ def getAllNodes(node, tagPath):
|
|||||||
return nodeList
|
return nodeList
|
||||||
|
|
||||||
|
|
||||||
def appendTagPath(dom, node, tagpath, child = None):
|
def createTagPath(dom, node, tags):
|
||||||
"""append child at the end of a tag chain starting from node"""
|
"""create new child at the end of a tag chain starting from node
|
||||||
for tag in tagpath[0:len(tagpath)-1]:
|
no matter what"""
|
||||||
|
if len(tags)==0:
|
||||||
|
return node
|
||||||
|
for tag in tags:
|
||||||
node = node.appendChild(dom.createElement(tag))
|
node = node.appendChild(dom.createElement(tag))
|
||||||
if child:
|
return node
|
||||||
return node.appendChild(child)
|
|
||||||
|
def addTagPath(dom, node, tags, newnode=None):
|
||||||
|
"""add newnode at the end of a tag chain, smart one"""
|
||||||
|
if newnode: # node to add specified
|
||||||
|
last = len(newnode)-1
|
||||||
|
if last >= 0:
|
||||||
|
node = createTagPath(dom, node, tags[0:last])
|
||||||
|
node.appendChild(newnode)
|
||||||
|
else:
|
||||||
|
raise XmlError("addNodePath: not enough tags")
|
||||||
else:
|
else:
|
||||||
return node.appendChild(dom.createElement(tag))
|
return createTagPath(dom, node, tags)
|
||||||
|
|
||||||
def addNode(dom, node, tagpath, newnode = None):
|
def addNode(dom, node, tagpath, newnode = None):
|
||||||
"""add a new node at the end of the tree"""
|
"""add a new node at the end of the tree"""
|
||||||
|
|
||||||
tags = tagpath.split('/')
|
tags = tagpath.split('/') # tag chain
|
||||||
assert len(tags)>0
|
assert len(tags)>0 # we want a chain
|
||||||
|
|
||||||
# iterative code to search for the path
|
# iterative code to search for the path
|
||||||
|
|
||||||
# get DOM for top node
|
# get DOM for top node
|
||||||
nodeList = node.getElementsByTagName(tags[0])
|
nodeList = node.getElementsByTagName(tags[0])
|
||||||
|
|
||||||
print 'tags', tagpath
|
|
||||||
print '****', nodeList
|
|
||||||
|
|
||||||
if len(nodeList) == 0:
|
if len(nodeList) == 0:
|
||||||
print 'SIFIR'
|
return addTagPath(dom, node, tags, newnode)
|
||||||
return appendTagPath(dom, node, tagpath, newnode)
|
|
||||||
|
|
||||||
node = nodeList[0] # discard other matches
|
node = nodeList[len(nodeList)-1] # discard other matches
|
||||||
tags.pop(0)
|
tags.pop(0)
|
||||||
while len(tags)>0:
|
while len(tags)>0:
|
||||||
tag = tags.pop(0)
|
tag = tags.pop(0)
|
||||||
nodeList = node.getElementsByTagName(tag)
|
nodeList = node.getElementsByTagName(tag)
|
||||||
if len(nodeList) == 0:
|
if len(nodeList) == 0: # couldn't find
|
||||||
tags = tag.insert(0)
|
tags.insert(0, tag) # put it back in
|
||||||
return appendTagPath(node, tags, newnode)
|
return addTagPath(dom, node, tags, newnode)
|
||||||
else:
|
else:
|
||||||
node = nodeList[0]
|
node = nodeList[len(nodeList)-1]
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user