* metadata ve specfile icin testlere basla
* specfile ve metadata write'larini yazmaya basla * bunun icin xmlfile'a yazma destegi ekle * metadata'yi ayir
This commit is contained in:
@@ -57,5 +57,3 @@ class Files(XmlFile):
|
||||
for x in self.list:
|
||||
document.appendChild(x.elt(self.dom))
|
||||
self.writexml(filename)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
from xmlfile import *
|
||||
import specfile
|
||||
from specfile import SpecFile
|
||||
|
||||
class MetaData(SpecFile):
|
||||
"""This is a superset of the source spec definition"""
|
||||
|
||||
def read(self, filename):
|
||||
super(MetaData, self).read(filename)
|
||||
distribution = self.getNodeText("Source/Distribution")
|
||||
distributionRelease = self.getNodeText("Source/DistributionRelease")
|
||||
architecture = self.getNodeText("Source/Architecture")
|
||||
installedSize = int(self.getNodeText("Source/InstalledSize"))
|
||||
|
||||
def write(self, filename):
|
||||
ui.info("METADATA WRITE NOT IMPLEMENTED\n")
|
||||
pass
|
||||
|
||||
def verify():
|
||||
if len(packages) != 1:
|
||||
return False
|
||||
return True
|
||||
+1
-21
@@ -95,25 +95,5 @@ class SpecFile(XmlFile):
|
||||
def write(self, filename):
|
||||
"""Write PSPEC file"""
|
||||
self.newDOM()
|
||||
##TODO: write the good stuff here
|
||||
self.addNodeText("Source/Name", source.name)
|
||||
self.writexml(filename)
|
||||
|
||||
class MetaData(SpecFile):
|
||||
"""This is a superset of the source spec definition"""
|
||||
|
||||
def read(self, filename):
|
||||
super(MetaData, self).read(filename)
|
||||
distribution = self.getNodeText("Source/Distribution")
|
||||
distributionRelease = self.getNodeText("Source/DistributionRelease")
|
||||
architecture = self.getNodeText("Source/Architecture")
|
||||
installSize = int(self.getNodeText("Source/InstallSize"))
|
||||
|
||||
def write(self, filename):
|
||||
ui.info("METADATA WRITE NOT IMPLEMENTED\n")
|
||||
pass
|
||||
|
||||
def verify():
|
||||
if len(packages) != 1:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
+47
-7
@@ -9,13 +9,14 @@ class XmlError(Exception):
|
||||
# static functions
|
||||
|
||||
def getNodeAttribute(node, attrname):
|
||||
"""get named attribute from DOM node"""
|
||||
for i in range(node.attributes.length):
|
||||
attr = node.attributes.item(i)
|
||||
if attr.name == attrname:
|
||||
return attr.childNodes[0].data
|
||||
|
||||
def getNodeText(node):
|
||||
# get the first child
|
||||
"""get the first child and expect it to be text!"""
|
||||
try:
|
||||
child = node.childNodes[0]
|
||||
except IndexError:
|
||||
@@ -28,6 +29,7 @@ def getNodeText(node):
|
||||
raise XmlError("getNodeText: Expected text node, got something else!")
|
||||
|
||||
def getChildText(node_s, tagpath):
|
||||
"""get the text of a child at the end of a tag path"""
|
||||
node = getNode(node_s, tagpath)
|
||||
if not node:
|
||||
return None
|
||||
@@ -84,22 +86,29 @@ def getAllNodes(node, tagPath):
|
||||
return nodeList
|
||||
|
||||
|
||||
def appendTagPath(node, tagpath, child):
|
||||
"""append child at the end of a tag chain"""
|
||||
def appendTagPath(dom, node, tagpath, child):
|
||||
"""append child at the end of a tag chain starting from node"""
|
||||
for tag in tagpath[0:len(tagpath)-1]:
|
||||
node = node.appendChild(createElement())
|
||||
node = node.appendChild(dom.createElement(tag))
|
||||
node.appendChild(child)
|
||||
|
||||
def putNode(node, tagpath, newnode):
|
||||
def addNode(dom, node, tagpath, newnode):
|
||||
tags = tagpath.split('/')
|
||||
assert len(tags)>0
|
||||
|
||||
# iterative code to search for the path
|
||||
|
||||
# get DOM for top node
|
||||
nodeList = node.getElementsByTagName(tags[0])
|
||||
if len(nodeList) == 0:
|
||||
appendTagPath(node, tagpath, newnode)
|
||||
|
||||
print 'tags', tagpath
|
||||
print '****', nodeList
|
||||
|
||||
if len(nodeList) == 0:
|
||||
print 'SIFIR'
|
||||
appendTagPath(dom, node, tagpath, newnode)
|
||||
return
|
||||
|
||||
node = nodeList[0] # discard other matches
|
||||
tags.pop(0)
|
||||
while len(tags)>0:
|
||||
@@ -129,6 +138,7 @@ class XmlFile(object):
|
||||
self.dom = impl.createDocument(None, self.rootTag, None)
|
||||
|
||||
def unlink(self):
|
||||
"""deallocate DOM structure"""
|
||||
self.dom.unlink()
|
||||
|
||||
def readxml(self, fileName):
|
||||
@@ -142,11 +152,27 @@ class XmlFile(object):
|
||||
if self.dom.documentElement.tagName != self.rootTag:
|
||||
raise XmlError("Root tagname not " + self.rootTag + " as expected")
|
||||
|
||||
def newNode(self, tag):
|
||||
return self.dom.createElement(tag)
|
||||
|
||||
def newTextNode(self, text):
|
||||
return self.dom.createTextNode(text)
|
||||
|
||||
def newAttribute(self, name):
|
||||
return self.dom.createAttribute(name)
|
||||
|
||||
# read helpers
|
||||
|
||||
def getNode(self, tagPath):
|
||||
"""returns the *first* matching node for given tag path."""
|
||||
self.verifyRootTag()
|
||||
return getNode(self.dom.documentElement, tagPath)
|
||||
|
||||
def getNodeText(self, tagPath):
|
||||
"""returns the text of *first* matching node for given tag path."""
|
||||
self.verifyRootTag()
|
||||
return getNodeText(getNode(self.dom.documentElement, tagPath))
|
||||
|
||||
def getAllNodes(self, tagPath):
|
||||
"""returns all nodes matching a given tag path."""
|
||||
self.verifyRootTag()
|
||||
@@ -179,3 +205,17 @@ class XmlFile(object):
|
||||
return None
|
||||
return getNodeText(node)
|
||||
|
||||
# write helpers
|
||||
|
||||
def addNode(self, tagPath, newnode):
|
||||
self.verifyRootTag()
|
||||
return addNode(self.dom, self.dom.documentElement, tagPath, newnode)
|
||||
|
||||
def addText(self, node, text):
|
||||
node.appendChild(self.newTextNode(text))
|
||||
|
||||
def addNodeText(self, tagPath, text):
|
||||
node = self.addNode(tagPath, self.newTextNode(text))
|
||||
return node
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from pisi import metadata
|
||||
from pisi import util
|
||||
from pisi import context
|
||||
|
||||
class MetaDataTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def testReadWrite(self):
|
||||
md = metadata.MetaData()
|
||||
md.read('tests/sandbox/metadata.xml')
|
||||
|
||||
suite = unittest.makeSuite(MetaDataTestCase)
|
||||
+6
-3
@@ -9,6 +9,7 @@ runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x)
|
||||
def run_all():
|
||||
|
||||
import specfiletests
|
||||
import metadatatests
|
||||
import contexttests
|
||||
import fetchertests
|
||||
import archivetests
|
||||
@@ -18,12 +19,14 @@ def run_all():
|
||||
|
||||
alltests = unittest.TestSuite((
|
||||
specfiletests.suite,
|
||||
specfiletests.suite,
|
||||
metadatatests.suite,
|
||||
contexttests.suite,
|
||||
fetchertests.suite,
|
||||
archivetests.suite,
|
||||
installdbtests.suite,
|
||||
packagedbtests.suite,
|
||||
actionsapitests.suite
|
||||
installdbtests.suite,
|
||||
packagedbtests.suite,
|
||||
actionsapitests.suite
|
||||
))
|
||||
|
||||
runTestSuite(alltests)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
|
||||
<PSPEC>
|
||||
|
||||
<Source>
|
||||
<Name>sandbox</Name>
|
||||
<Homepage>http://cekirdek.uludag.org.tr/~meren/</Homepage>
|
||||
<Packager>
|
||||
<Name>Meral</Name>
|
||||
<Email>meren@uludag.org.tr</Email>
|
||||
</Packager>
|
||||
<License>As-Is</License>
|
||||
<Archive archType="zip" sha1sum="b1e61fe4a840fbe624a01136e33343cdd1b0bf06">
|
||||
http://cekirdek.uludag.org.tr/~meren/sandbox.zip
|
||||
</Archive>
|
||||
<History>
|
||||
<Update>
|
||||
<Date>06/15/2005</Date>
|
||||
<Version>0.1</Version>
|
||||
<Release>1</Release>
|
||||
</Update>
|
||||
</History>
|
||||
<Distribution>Pardus</Distribution>
|
||||
<DistributionRelease>0.1</DistributionRelease>
|
||||
</Source>
|
||||
|
||||
<Package>
|
||||
<Name>sandbox</Name>
|
||||
<Summary lang="tr">Bla</Summary>
|
||||
<Category>temprorary:zip</Category>
|
||||
<Architecture>x86</Architecture>
|
||||
<InstalledSize>40500</InstalledSize>
|
||||
</Package>
|
||||
|
||||
</PSPEC>
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from pisi import specfile
|
||||
|
||||
class SpecReadTestCase(unittest.TestCase):
|
||||
class SpecFileTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.spec = specfile.SpecFile()
|
||||
self.spec.read("samples/popt/popt.pspec")
|
||||
@@ -27,4 +28,8 @@ class SpecReadTestCase(unittest.TestCase):
|
||||
def testLenPackages(self):
|
||||
self.assertEqual(len(self.spec.packages), 1)
|
||||
|
||||
suite = unittest.makeSuite(SpecReadTestCase)
|
||||
def testCopy(self):
|
||||
self.spec.read("samples/popt/popt.pspec")
|
||||
self.spec.write(os.path.join(ctx.tmp_dir(), 'popt-copy.pspec'))
|
||||
|
||||
suite = unittest.makeSuite(SpecFileTestCase)
|
||||
|
||||
Reference in New Issue
Block a user