* 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:
@@ -1,2 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# installation database
|
# installation database
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# package database
|
# package database
|
||||||
# interface for update/query to local package repository
|
# interface for update/query to local package repository
|
||||||
|
|
||||||
|
import shelve
|
||||||
|
|
||||||
|
files_dir = archive_dir + "/files"
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -15,11 +15,14 @@ class SpecFile(XmlFile):
|
|||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Read PSPEC file"""
|
"""Read PSPEC file"""
|
||||||
self.readxml(filename)
|
self.readxml(filename)
|
||||||
self.archiveNode = self.getFirstNode("PSPEC/Source/Archive")
|
|
||||||
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
|
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
|
||||||
self.archiveUri = self.getNodeText(self.archiveNode).strip()
|
archiveNode = self.getFirstNode("PSPEC/Source/Archive")
|
||||||
self.archiveType = self.getNodeAttribute(self.archiveNode, "archType")
|
self.archiveUri = self.getNodeText(archiveNode).strip()
|
||||||
self.archiveHash = self.getNodeAttribute(self.archiveNode, "md5sum")
|
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):
|
def verify(self):
|
||||||
"""Verify PSPEC structures, are they what we want of them?"""
|
"""Verify PSPEC structures, are they what we want of them?"""
|
||||||
|
|||||||
+38
-12
@@ -1,5 +1,10 @@
|
|||||||
|
# some helper functions for using minidom
|
||||||
|
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
class XmlError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class XmlFile(object):
|
class XmlFile(object):
|
||||||
"""A class for retrieving information from an XML file"""
|
"""A class for retrieving information from an XML file"""
|
||||||
|
|
||||||
@@ -8,27 +13,48 @@ class XmlFile(object):
|
|||||||
|
|
||||||
def writexml(self, filenm):
|
def writexml(self, filenm):
|
||||||
f = file(filenm,'w')
|
f = file(filenm,'w')
|
||||||
dom.writetoxml(f)
|
self.dom.writexml(f)
|
||||||
|
|
||||||
def getNodes(self, nodepath):
|
def getChildren(self, tagpath):
|
||||||
"""getNodes function return nodes for given path of the node.
|
""" returns the children of the given path"""
|
||||||
|
return self.dom.getChildren()
|
||||||
|
|
||||||
getNodes("PSPEC/Source/Name")
|
def getNode(self, tagpath):
|
||||||
returns an array of Name nodes in PSPEC/Source"""
|
"""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
|
# get DOM for top node
|
||||||
nodelist = self.dom.getElementsByTagName(nodeArray[0])
|
nodelist = self.dom.getElementsByTagName(tags[0])
|
||||||
# iterate over
|
|
||||||
for nodename in nodeArray[1:]:
|
|
||||||
nodelist = nodelist[0].getElementsByTagName(nodename)
|
|
||||||
|
|
||||||
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):
|
def getFirstNode(self, nodepath):
|
||||||
try:
|
try:
|
||||||
return self.getNodes(nodepath)[0]
|
return self.getNode(nodepath)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user