From f25f9a854e778db0a1983217276dcc77996f9305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Thu, 9 Jun 2005 18:00:29 +0000 Subject: [PATCH] =?UTF-8?q?spec=20dosyas=C4=B1ndan=20veri=20almak=20i?= =?UTF-8?q?=C3=A7in=20daha=20iyi=20bir=20y=C3=B6ntem...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pisi-build.py | 12 +++----- src/specfile.py | 77 +++++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/pisi-build.py b/src/pisi-build.py index 384d2422..1c824cfe 100644 --- a/src/pisi-build.py +++ b/src/pisi-build.py @@ -19,16 +19,14 @@ class PisiBuild: def __init__(self, pspecfile): self.pspecfile = pspecfile pspec = SpecFile(pspecfile) - pspec.read() - self.packageName = pspec.getFirstChildText("Source/Name") + self.packageName = pspec.getSourceName() - archiveNode = pspec.getFirstNode("Source/Archive") - self.archiveUri = pspec.getNodeText(archiveNode).strip() + self.archiveUri = pspec.getArchiveUri() self.archiveName = basename(self.archiveUri) - self.archiveType = pspec.getNodeAttribute(archiveNode, "archType") - self.archiveHash = pspec.getNodeAttribute(archiveNode, "md5sum") - + self.archiveType = pspec.getArchiveType() + self.archiveHash = pspec.getArchiveHash() + self.pspec = pspec def fetchArchive(self): diff --git a/src/specfile.py b/src/specfile.py index 4dce678c..44145aec 100644 --- a/src/specfile.py +++ b/src/specfile.py @@ -2,35 +2,18 @@ import xml.dom.minidom -class SpecFile: - """SpecFile: A class for extracting specific information -from a PSPEC file""" +class XmlFile(object): + """A class for retrieving information from an XML file""" + def __init__(self, specfile): - self.filename = specfile - - def read(): - self.dom = xml.dom.minidom.parse(filename) - # fill in fields - - self.packageName = pspec.getFirstChildText("Source/Name") - - archiveNode = pspec.getFirstNode("Source/Archive") - self.archiveUri = pspec.getNodeText(archiveNode).strip() - self.archiveName = basename(self.archiveUri) - self.archiveType = pspec.getNodeAttribute(archiveNode, "archType") - self.archiveHash = pspec.getNodeAttribute(archiveNode, - "md5sum") - patchesnode = pspec.getFirstNode("Source/Patches") - - def write(outfn): - f = file(outfn, 'w') - xml.dom.minidom.writexml(f) + self.dom = xml.dom.minidom.parse(specfile) def getNodes(self, nodepath): """getNodes function return nodes for given path of the node. - getNodes("Source/Name") - returns a list of nodes in PSPEC/Source""" - nodepath = "PSPEC/" + nodepath + + getNodes("PSPEC/Source/Name") + returns an array of Name nodes in PSPEC/Source""" + nodeArray=nodepath.split('/') # get DOM for top node @@ -38,16 +21,15 @@ from a PSPEC file""" # iterate over for nodename in nodeArray[1:]: nodelist = nodelist[0].getElementsByTagName(nodename) - + return nodelist def getFirstNode(self, nodepath): - nodepath = "PSPEC/" + nodepath try: return self.getNodes(nodepath)[0] except IndexError: return None - + def getNodeText(self, node): # get the first child try: @@ -59,19 +41,54 @@ from a PSPEC file""" return child.data def getFirstChildText(self, nodepath): - nodepath = "PSPEC/" + nodepath node = self.getFirstNode(nodepath) if not node: return None return self.getNodeText(node) - + def getNodeAttribute(self, node, attrname): for i in range(node.attributes.length): attr = node.attributes.item(i) if attr.name == attrname: return attr.childNodes[0].data + +class SpecFile(XmlFile): + """A class for retrieving specific information from a + PSPEC (PISI SPEC) file. + + Information retrieved from PSPEC file is cached (where possible) + once accessed, for further usage. + """ + + def __init__(self, specfile): + super(SpecFile, self).__init__(specfile) + + self.archiveNode = self.getFirstNode("PSPEC/Source/Archive") + + def getSourceName(self): + try: + return self.sourceName + except AttributeError: + print "buraya yalnızca bir defa gelebilirsin..." + self.sourceName = self.getFirstChildText("PSPEC/Source/Name") + return self.sourceName + + def getArchiveUri(self): + try: + return self.archiveUri + except AttributeError: + self.archiveUri = self.getNodeText(self.archiveNode).strip() + return self.archiveUri + + def getArchiveType(self): + return self.getNodeAttribute(self.archiveNode, "archType") + + def getArchiveHash(self): + return self.getNodeAttribute(self.archiveNode, "md5sum") + + if __name__ == "__main__": import sys sys.stderr.write("Not a callable module!")