From e9fa02b9a379a6bedcad5bee22e9c65f68fe997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Wed, 8 Jun 2005 14:59:11 +0000 Subject: [PATCH] =?UTF-8?q?Deneme=20i=C3=A7in=20bir=20specfile=20mod=C3=BC?= =?UTF-8?q?l=C3=BC=20=C3=B6rne=C4=9Fi...=20Test=20program=C4=B1=20a=C5=9Fa?= =?UTF-8?q?=C4=9F=C4=B1daki=20gibi=20kullan=C4=B1labilir.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit baris@pardus ~/svn/internal/trunk/pisi/src/tests $ ./getTextForNode ../../popt/popt.pspec PSPEC/Source/Packager/Email hotmail@redhat.com --- src/specfile.py | 35 +++++++++++++++++++++++++++++++++++ src/tests/getTextForNode | 20 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/specfile.py create mode 100755 src/tests/getTextForNode diff --git a/src/specfile.py b/src/specfile.py new file mode 100644 index 00000000..792acecd --- /dev/null +++ b/src/specfile.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import xml.dom.minidom + +class SpecFile: + """SpecFile: A class for extracting specific information +from a PSPEC file""" + def __init__(self, specfile): + self.dom = xml.dom.minidom.parse(specfile) + + def getNodes(self, nodepath): + """getNodes function return nodes for given path of the node. + getNodes("PSPEC/Source/Name") + returns an array of Name tags in PSPEC/Source""" + nodeArray=nodepath.split('/') + + + # get DOM for top node + nodelist = self.dom.getElementsByTagName(nodeArray[0]) + # iterate over + for nodename in nodeArray[1:]: + nodelist = nodelist[0].getElementsByTagName(nodename) + + return nodelist + + def getText(self, nodepath): + pass + + def getAttribute(self, nodepath, attribute): + pass + +if __name__ == "__main__": + import sys + sys.stderr.write("Not a callable module!") diff --git a/src/tests/getTextForNode b/src/tests/getTextForNode new file mode 100755 index 00000000..cc0a8f32 --- /dev/null +++ b/src/tests/getTextForNode @@ -0,0 +1,20 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# ./getTextForNode ../../popt/popt.pspec PSPEC/Source/Name + +import sys +sys.path.append("..") +import specfile + +s = specfile.SpecFile(sys.argv[1]) +n=s.getNodes(sys.argv[2]) + +if not n: + sys.exit(1) + +for node in n[0].childNodes: + if node.nodeType == node.TEXT_NODE: + print node.data + else: + print "Verilen node için metin yok" +