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:
@@ -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!")
|
||||||
Executable
+20
@@ -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"
|
||||||
|
|
||||||
Reference in New Issue
Block a user