spec dosyasından veri almak için daha iyi bir yöntem...
This commit is contained in:
+5
-7
@@ -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):
|
||||
|
||||
+47
-30
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user