spec dosyasından veri almak için daha iyi bir yöntem...
This commit is contained in:
+4
-6
@@ -19,15 +19,13 @@ class PisiBuild:
|
|||||||
def __init__(self, pspecfile):
|
def __init__(self, pspecfile):
|
||||||
self.pspecfile = pspecfile
|
self.pspecfile = pspecfile
|
||||||
pspec = SpecFile(pspecfile)
|
pspec = SpecFile(pspecfile)
|
||||||
pspec.read()
|
|
||||||
|
|
||||||
self.packageName = pspec.getFirstChildText("Source/Name")
|
self.packageName = pspec.getSourceName()
|
||||||
|
|
||||||
archiveNode = pspec.getFirstNode("Source/Archive")
|
self.archiveUri = pspec.getArchiveUri()
|
||||||
self.archiveUri = pspec.getNodeText(archiveNode).strip()
|
|
||||||
self.archiveName = basename(self.archiveUri)
|
self.archiveName = basename(self.archiveUri)
|
||||||
self.archiveType = pspec.getNodeAttribute(archiveNode, "archType")
|
self.archiveType = pspec.getArchiveType()
|
||||||
self.archiveHash = pspec.getNodeAttribute(archiveNode, "md5sum")
|
self.archiveHash = pspec.getArchiveHash()
|
||||||
|
|
||||||
self.pspec = pspec
|
self.pspec = pspec
|
||||||
|
|
||||||
|
|||||||
+44
-27
@@ -2,35 +2,18 @@
|
|||||||
|
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
class SpecFile:
|
class XmlFile(object):
|
||||||
"""SpecFile: A class for extracting specific information
|
"""A class for retrieving information from an XML file"""
|
||||||
from a PSPEC file"""
|
|
||||||
def __init__(self, specfile):
|
def __init__(self, specfile):
|
||||||
self.filename = specfile
|
self.dom = xml.dom.minidom.parse(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)
|
|
||||||
|
|
||||||
def getNodes(self, nodepath):
|
def getNodes(self, nodepath):
|
||||||
"""getNodes function return nodes for given path of the node.
|
"""getNodes function return nodes for given path of the node.
|
||||||
getNodes("Source/Name")
|
|
||||||
returns a list of nodes in PSPEC/Source"""
|
getNodes("PSPEC/Source/Name")
|
||||||
nodepath = "PSPEC/" + nodepath
|
returns an array of Name nodes in PSPEC/Source"""
|
||||||
|
|
||||||
nodeArray=nodepath.split('/')
|
nodeArray=nodepath.split('/')
|
||||||
|
|
||||||
# get DOM for top node
|
# get DOM for top node
|
||||||
@@ -42,7 +25,6 @@ from a PSPEC file"""
|
|||||||
return nodelist
|
return nodelist
|
||||||
|
|
||||||
def getFirstNode(self, nodepath):
|
def getFirstNode(self, nodepath):
|
||||||
nodepath = "PSPEC/" + nodepath
|
|
||||||
try:
|
try:
|
||||||
return self.getNodes(nodepath)[0]
|
return self.getNodes(nodepath)[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -59,7 +41,6 @@ from a PSPEC file"""
|
|||||||
return child.data
|
return child.data
|
||||||
|
|
||||||
def getFirstChildText(self, nodepath):
|
def getFirstChildText(self, nodepath):
|
||||||
nodepath = "PSPEC/" + nodepath
|
|
||||||
node = self.getFirstNode(nodepath)
|
node = self.getFirstNode(nodepath)
|
||||||
if not node:
|
if not node:
|
||||||
return None
|
return None
|
||||||
@@ -72,6 +53,42 @@ from a PSPEC file"""
|
|||||||
if attr.name == attrname:
|
if attr.name == attrname:
|
||||||
return attr.childNodes[0].data
|
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__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
sys.stderr.write("Not a callable module!")
|
sys.stderr.write("Not a callable module!")
|
||||||
|
|||||||
Reference in New Issue
Block a user