* 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"?>
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
<!-- Project file for project pisi -->
<!-- Saved: 2005-11-05, 22:49:17 -->
<!-- Copyright (C) 2005 PiSi Development Team, pisi@uludag.org.tr -->
<!-- Saved: 2005-11-08, 17:43:53 -->
<!-- Copyright (C) 2005 PiSi Development Team, -->
<Project version="3.8">
<ProgLanguage mixed="0">Python</ProgLanguage>
<UIType>Qt</UIType>
<Description>The package management software of Pardus distribution.
</Description>
<VersIon></VersIon>
<Author>PiSi Development Team</Author>
<EmaIl>pisi@uludag.org.tr</EmaIl>
<Email></Email>
<Sources>
<Source>
<Dir>tools</Dir>
@@ -263,10 +262,6 @@
<Dir>pisi</Dir>
<Name>archive.py</Name>
</Source>
<Source>
<Dir>pisi</Dir>
<Name>xmlext.py</Name>
</Source>
<Source>
<Dir>pisi</Dir>
<Name>version.py</Name>
@@ -418,10 +413,10 @@
<VcsOtherData>{'standardLayout': 1}</VcsOtherData>
</Vcs>
<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="*.ui.h" type="FORMS" />
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
<FiletypeAssociation pattern="*.ui" type="FORMS" />
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
</FiletypeAssociations>
</Project>
+17 -28
View File
@@ -11,11 +11,13 @@
#
# Authors: Eray Ozkural <eray@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,
an old library
an 'old library'
note: this is a particularly inefficient implementation of xmlext.
"""
import gettext
@@ -28,17 +30,19 @@ class XmlError(pisi.Error):
"named this way because the class if mostly used with an import *"
pass
#FIXME: these Node's in the following routines seem redundant
def getNodeAttribute(node, attrname):
"""get named attribute from DOM node"""
if not node.hasAttribute(attrname):
return None
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):
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 = ""):
"""get the first child and expect it to be text!"""
@@ -63,10 +67,6 @@ def getChildText(node_s, tagpath):
return None
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):
"""returns the *first* matching node for given tag path."""
@@ -75,35 +75,24 @@ def getNode(node, tagpath):
assert len(tags)>0
# iterative code to search for the path
# get DOM for top node
nodeList = getTagByName(node, tags[0])
if len(nodeList) == 0:
return None # not found
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
for tag in tags:
for child in node.childNodes:
if child.nodeType == node.ELEMENT_NODE and child.tagName == tag:
return child
return None
def getAllNodes(node, tagPath):
"""retrieve all nodes that match a given tag path."""
#FIXME: better tag split
tags = tagPath.split('/')
if len(tags) == 0:
return []
nodeList = getTagByName(node, tags[0])
if len(nodeList) == 0:
return []
nodeList = [node] # basis case
for tag in tags[1:]:
for tag in tags:
results = map(lambda x: getTagByName(x, tag), nodeList)
nodeList = []
for x in results: