* fix: replace getNodes with getNode, also remove getFirstNode

- still inefficient, must not use getElementsByTagName at all
     unless that is the purpose
   - need to simplify and optimize this further
* installdb: start writing
This commit is contained in:
Eray Özkural
2005-06-10 16:38:16 +00:00
parent da25ef0902
commit 56b1d9f201
4 changed files with 53 additions and 16 deletions
+3
View File
@@ -1,2 +1,5 @@
# -*- coding: utf-8 -*-
# installation database
+5
View File
@@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
# package database
# interface for update/query to local package repository
import shelve
files_dir = archive_dir + "/files"
+7 -4
View File
@@ -15,11 +15,14 @@ class SpecFile(XmlFile):
def read(self, filename):
"""Read PSPEC file"""
self.readxml(filename)
self.archiveNode = self.getFirstNode("PSPEC/Source/Archive")
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
self.archiveUri = self.getNodeText(self.archiveNode).strip()
self.archiveType = self.getNodeAttribute(self.archiveNode, "archType")
self.archiveHash = self.getNodeAttribute(self.archiveNode, "md5sum")
archiveNode = self.getFirstNode("PSPEC/Source/Archive")
self.archiveUri = self.getNodeText(archiveNode).strip()
self.archiveType = self.getNodeAttribute(archiveNode, "archType")
self.archiveHash = self.getNodeAttribute(archiveNode, "md5sum")
patches = self.getNode("PSPEC/Source/Patches")
#patches = self.dom.getElementsByTagName("PSPEC")
#for x in patc
def verify(self):
"""Verify PSPEC structures, are they what we want of them?"""
+38 -12
View File
@@ -1,5 +1,10 @@
# some helper functions for using minidom
import xml.dom.minidom
class XmlError(Exception):
pass
class XmlFile(object):
"""A class for retrieving information from an XML file"""
@@ -8,27 +13,48 @@ class XmlFile(object):
def writexml(self, filenm):
f = file(filenm,'w')
dom.writetoxml(f)
self.dom.writexml(f)
def getNodes(self, nodepath):
"""getNodes function return nodes for given path of the node.
def getChildren(self, tagpath):
""" returns the children of the given path"""
return self.dom.getChildren()
getNodes("PSPEC/Source/Name")
returns an array of Name nodes in PSPEC/Source"""
def getNode(self, tagpath):
"""returns the node for given *unique* path of the node.
nodeArray=nodepath.split('/')
getNode("PSPEC/Source")
returns the node with the tag path PSPEC/Source"""
tags=tagpath.split('/')
# code to search for the path
# get DOM for top node
nodelist = self.dom.getElementsByTagName(nodeArray[0])
# iterate over
for nodename in nodeArray[1:]:
nodelist = nodelist[0].getElementsByTagName(nodename)
nodelist = self.dom.getElementsByTagName(tags[0])
return nodelist
if len(nodelist)==0:
raise XmlError("Root tag for " % tagpath % " not found")
node = nodelist[0] # discard other matches
for nodename in tags[1:]:
nodelist = node.getElementsByTagName(nodename)
if len(nodelist)==0:
raise XmlError("Tag path " % tagpath % " broken")
else:
node = nodelist[0]
return node
def getAllNodes(self, nodepath):
"""returns all trees corresponding to given path.
getAllNodes("PSPEC/Source")
returns an array of nodes under PSPEC/Source"""
raise XmlError("Not implemented!")
def getFirstNode(self, nodepath):
try:
return self.getNodes(nodepath)[0]
return self.getNode(nodepath)
except IndexError:
return None