* simplify iterations, passes specfile tests...

This commit is contained in:
Eray Özkural
2005-11-08 16:04:39 +00:00
parent 6f1dbba95a
commit 46a1c25933
2 changed files with 24 additions and 40 deletions
+7 -12
View File
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-3.8.dtd"> <!DOCTYPE Project SYSTEM "Project-3.8.dtd">
<!-- Project file for project pisi --> <!-- Project file for project pisi -->
<!-- Saved: 2005-11-05, 22:49:17 --> <!-- Saved: 2005-11-08, 17:43:53 -->
<!-- Copyright (C) 2005 PiSi Development Team, pisi@uludag.org.tr --> <!-- Copyright (C) 2005 PiSi Development Team, -->
<Project version="3.8"> <Project version="3.8">
<ProgLanguage mixed="0">Python</ProgLanguage> <ProgLanguage mixed="0">Python</ProgLanguage>
<UIType>Qt</UIType> <UIType>Qt</UIType>
<Description>The package management software of Pardus distribution. <Description>The package management software of Pardus distribution.
</Description> </Description>
<VersIon></VersIon>
<Author>PiSi Development Team</Author> <Author>PiSi Development Team</Author>
<EmaIl>pisi@uludag.org.tr</EmaIl> <Email></Email>
<Sources> <Sources>
<Source> <Source>
<Dir>tools</Dir> <Dir>tools</Dir>
@@ -263,10 +262,6 @@
<Dir>pisi</Dir> <Dir>pisi</Dir>
<Name>archive.py</Name> <Name>archive.py</Name>
</Source> </Source>
<Source>
<Dir>pisi</Dir>
<Name>xmlext.py</Name>
</Source>
<Source> <Source>
<Dir>pisi</Dir> <Dir>pisi</Dir>
<Name>version.py</Name> <Name>version.py</Name>
@@ -418,10 +413,10 @@
<VcsOtherData>{'standardLayout': 1}</VcsOtherData> <VcsOtherData>{'standardLayout': 1}</VcsOtherData>
</Vcs> </Vcs>
<FiletypeAssociations> <FiletypeAssociations>
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
<FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
<FiletypeAssociation pattern="*.py" type="SOURCES" /> <FiletypeAssociation pattern="*.py" type="SOURCES" />
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
</FiletypeAssociations> </FiletypeAssociations>
</Project> </Project>
+17 -28
View File
@@ -11,11 +11,13 @@
# #
# Authors: Eray Ozkural <eray@uludag.org.tr> # Authors: Eray Ozkural <eray@uludag.org.tr>
# Baris Metin <baris@uludag.org.tr # Baris Metin <baris@uludag.org.tr
# Gurer Ozen <gurer@uludag.org.tr>
""" """
some helper functions for using minidom some helper functions implemented with minidom
function names are mixedCase for compatibility with minidom, function names are mixedCase for compatibility with minidom,
an old library an 'old library'
note: this is a particularly inefficient implementation of xmlext.
""" """
import gettext import gettext
@@ -28,17 +30,19 @@ class XmlError(pisi.Error):
"named this way because the class if mostly used with an import *" "named this way because the class if mostly used with an import *"
pass pass
#FIXME: these Node's in the following routines seem redundant
def getNodeAttribute(node, attrname): def getNodeAttribute(node, attrname):
"""get named attribute from DOM node""" """get named attribute from DOM node"""
if not node.hasAttribute(attrname): if not node.hasAttribute(attrname):
return None return None
return node.getAttribute(attrname) return node.getAttribute(attrname)
def getChildElts(node):
"""get only child elements"""
return filter(lambda x:x.nodeType == x.ELEMENT_NODE, node.childNodes)
def getTagByName(parent, childName): def getTagByName(parent, childName):
return [x for x in parent.childNodes return [x for x in parent.childNodes
if x.nodeType == x.ELEMENT_NODE if x.tagName == childName] if x.nodeType == x.ELEMENT_NODE and x.tagName == childName]
def getNodeText(node, tagpath = ""): def getNodeText(node, tagpath = ""):
"""get the first child and expect it to be text!""" """get the first child and expect it to be text!"""
@@ -63,10 +67,6 @@ def getChildText(node_s, tagpath):
return None return None
return getNodeText(node) return getNodeText(node)
def getChildElts(node):
"""get only child elements"""
return filter(lambda x:x.nodeType == x.ELEMENT_NODE, node.childNodes)
def getNode(node, tagpath): def getNode(node, tagpath):
"""returns the *first* matching node for given tag path.""" """returns the *first* matching node for given tag path."""
@@ -75,35 +75,24 @@ def getNode(node, tagpath):
assert len(tags)>0 assert len(tags)>0
# iterative code to search for the path # iterative code to search for the path
for tag in tags:
# get DOM for top node for child in node.childNodes:
nodeList = getTagByName(node, tags[0]) if child.nodeType == node.ELEMENT_NODE and child.tagName == tag:
if len(nodeList) == 0: return child
return None # not found return None
node = nodeList[0] # discard other matches
for tag in tags[1:]:
nodeList = getTagByName(node, tag)
if len(nodeList) == 0:
return None
else:
node = nodeList[0]
return node
def getAllNodes(node, tagPath): def getAllNodes(node, tagPath):
"""retrieve all nodes that match a given tag path.""" """retrieve all nodes that match a given tag path."""
#FIXME: better tag split
tags = tagPath.split('/') tags = tagPath.split('/')
if len(tags) == 0: if len(tags) == 0:
return [] return []
nodeList = getTagByName(node, tags[0]) nodeList = [node] # basis case
if len(nodeList) == 0:
return []
for tag in tags[1:]: for tag in tags:
results = map(lambda x: getTagByName(x, tag), nodeList) results = map(lambda x: getTagByName(x, tag), nodeList)
nodeList = [] nodeList = []
for x in results: for x in results: