Deneme için bir specfile modülü örneği...

Test programı aşağıdaki gibi kullanılabilir.

baris@pardus ~/svn/internal/trunk/pisi/src/tests $ ./getTextForNode ../../popt/popt.pspec PSPEC/Source/Packager/Email
hotmail@redhat.com
This commit is contained in:
Barış Metin
2005-06-08 14:59:11 +00:00
parent bdb6950b0a
commit e9fa02b9a3
2 changed files with 55 additions and 0 deletions
+35
View File
@@ -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!")
+20
View File
@@ -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"