* 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:
|
for x in self.list:
|
||||||
document.appendChild(x.elt(self.dom))
|
document.appendChild(x.elt(self.dom))
|
||||||
self.writexml(filename)
|
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):
|
def write(self, filename):
|
||||||
"""Write PSPEC file"""
|
"""Write PSPEC file"""
|
||||||
self.newDOM()
|
self.newDOM()
|
||||||
##TODO: write the good stuff here
|
self.addNodeText("Source/Name", source.name)
|
||||||
self.writexml(filename)
|
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
|
|
||||||
|
|
||||||
|
|||||||
+46
-6
@@ -9,13 +9,14 @@ class XmlError(Exception):
|
|||||||
# static functions
|
# static functions
|
||||||
|
|
||||||
def getNodeAttribute(node, attrname):
|
def getNodeAttribute(node, attrname):
|
||||||
|
"""get named attribute from DOM node"""
|
||||||
for i in range(node.attributes.length):
|
for i in range(node.attributes.length):
|
||||||
attr = node.attributes.item(i)
|
attr = node.attributes.item(i)
|
||||||
if attr.name == attrname:
|
if attr.name == attrname:
|
||||||
return attr.childNodes[0].data
|
return attr.childNodes[0].data
|
||||||
|
|
||||||
def getNodeText(node):
|
def getNodeText(node):
|
||||||
# get the first child
|
"""get the first child and expect it to be text!"""
|
||||||
try:
|
try:
|
||||||
child = node.childNodes[0]
|
child = node.childNodes[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -28,6 +29,7 @@ def getNodeText(node):
|
|||||||
raise XmlError("getNodeText: Expected text node, got something else!")
|
raise XmlError("getNodeText: Expected text node, got something else!")
|
||||||
|
|
||||||
def getChildText(node_s, tagpath):
|
def getChildText(node_s, tagpath):
|
||||||
|
"""get the text of a child at the end of a tag path"""
|
||||||
node = getNode(node_s, tagpath)
|
node = getNode(node_s, tagpath)
|
||||||
if not node:
|
if not node:
|
||||||
return None
|
return None
|
||||||
@@ -84,21 +86,28 @@ def getAllNodes(node, tagPath):
|
|||||||
return nodeList
|
return nodeList
|
||||||
|
|
||||||
|
|
||||||
def appendTagPath(node, tagpath, child):
|
def appendTagPath(dom, node, tagpath, child):
|
||||||
"""append child at the end of a tag chain"""
|
"""append child at the end of a tag chain starting from node"""
|
||||||
for tag in tagpath[0:len(tagpath)-1]:
|
for tag in tagpath[0:len(tagpath)-1]:
|
||||||
node = node.appendChild(createElement())
|
node = node.appendChild(dom.createElement(tag))
|
||||||
node.appendChild(child)
|
node.appendChild(child)
|
||||||
|
|
||||||
def putNode(node, tagpath, newnode):
|
def addNode(dom, node, tagpath, newnode):
|
||||||
tags = tagpath.split('/')
|
tags = tagpath.split('/')
|
||||||
|
assert len(tags)>0
|
||||||
|
|
||||||
# iterative code to search for the path
|
# iterative code to search for the path
|
||||||
|
|
||||||
# get DOM for top node
|
# get DOM for top node
|
||||||
nodeList = node.getElementsByTagName(tags[0])
|
nodeList = node.getElementsByTagName(tags[0])
|
||||||
|
|
||||||
|
print 'tags', tagpath
|
||||||
|
print '****', nodeList
|
||||||
|
|
||||||
if len(nodeList) == 0:
|
if len(nodeList) == 0:
|
||||||
appendTagPath(node, tagpath, newnode)
|
print 'SIFIR'
|
||||||
|
appendTagPath(dom, node, tagpath, newnode)
|
||||||
|
return
|
||||||
|
|
||||||
node = nodeList[0] # discard other matches
|
node = nodeList[0] # discard other matches
|
||||||
tags.pop(0)
|
tags.pop(0)
|
||||||
@@ -129,6 +138,7 @@ class XmlFile(object):
|
|||||||
self.dom = impl.createDocument(None, self.rootTag, None)
|
self.dom = impl.createDocument(None, self.rootTag, None)
|
||||||
|
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
|
"""deallocate DOM structure"""
|
||||||
self.dom.unlink()
|
self.dom.unlink()
|
||||||
|
|
||||||
def readxml(self, fileName):
|
def readxml(self, fileName):
|
||||||
@@ -142,11 +152,27 @@ class XmlFile(object):
|
|||||||
if self.dom.documentElement.tagName != self.rootTag:
|
if self.dom.documentElement.tagName != self.rootTag:
|
||||||
raise XmlError("Root tagname not " + self.rootTag + " as expected")
|
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):
|
def getNode(self, tagPath):
|
||||||
"""returns the *first* matching node for given tag path."""
|
"""returns the *first* matching node for given tag path."""
|
||||||
self.verifyRootTag()
|
self.verifyRootTag()
|
||||||
return getNode(self.dom.documentElement, tagPath)
|
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):
|
def getAllNodes(self, tagPath):
|
||||||
"""returns all nodes matching a given tag path."""
|
"""returns all nodes matching a given tag path."""
|
||||||
self.verifyRootTag()
|
self.verifyRootTag()
|
||||||
@@ -179,3 +205,17 @@ class XmlFile(object):
|
|||||||
return None
|
return None
|
||||||
return getNodeText(node)
|
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)
|
||||||
@@ -9,6 +9,7 @@ runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x)
|
|||||||
def run_all():
|
def run_all():
|
||||||
|
|
||||||
import specfiletests
|
import specfiletests
|
||||||
|
import metadatatests
|
||||||
import contexttests
|
import contexttests
|
||||||
import fetchertests
|
import fetchertests
|
||||||
import archivetests
|
import archivetests
|
||||||
@@ -18,6 +19,8 @@ def run_all():
|
|||||||
|
|
||||||
alltests = unittest.TestSuite((
|
alltests = unittest.TestSuite((
|
||||||
specfiletests.suite,
|
specfiletests.suite,
|
||||||
|
specfiletests.suite,
|
||||||
|
metadatatests.suite,
|
||||||
contexttests.suite,
|
contexttests.suite,
|
||||||
fetchertests.suite,
|
fetchertests.suite,
|
||||||
archivetests.suite,
|
archivetests.suite,
|
||||||
|
|||||||
@@ -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 unittest
|
||||||
|
import os
|
||||||
|
|
||||||
from pisi import specfile
|
from pisi import specfile
|
||||||
|
|
||||||
class SpecReadTestCase(unittest.TestCase):
|
class SpecFileTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.spec = specfile.SpecFile()
|
self.spec = specfile.SpecFile()
|
||||||
self.spec.read("samples/popt/popt.pspec")
|
self.spec.read("samples/popt/popt.pspec")
|
||||||
@@ -27,4 +28,8 @@ class SpecReadTestCase(unittest.TestCase):
|
|||||||
def testLenPackages(self):
|
def testLenPackages(self):
|
||||||
self.assertEqual(len(self.spec.packages), 1)
|
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