* metadata'yi iki section'a bol source ve package

* butun xml reader/writer'lari elden gecir temizle
* eksik bir suru tag'i implement et
* ornekleri, testleri update et
* ornekleri insan-okur hale cevir
* actionsapitests: condition'i daha genel amacli hale getir
This commit is contained in:
Eray Özkural
2005-06-24 00:05:05 +00:00
parent 4f8735a723
commit 7342fdc124
9 changed files with 161 additions and 148 deletions
+5 -57
View File
@@ -113,70 +113,18 @@ class PisiBuild:
locals[func]() locals[func]()
def genMetaDataXml(self, package): def genMetaDataXml(self, package):
metadata = MetaData() metadata = MetaData.fromSpec(self.spec.source, package)
metadata.package.distribution = const.distribution
metadata.package.distributionRelease = const.distributionRelease
metadata.package.architecture = "Any"
def createElt(tagName, text=None):
createElement = metadata.dom.createElement
createTextNode = metadata.dom.createTextNode
elt = createElement(tagName)
if text:
elt.appendChild(createTextNode(text))
return elt
metadata.appendElement(createElt("Name",
package.name))
metadata.appendElement(createElt("Summary",
package.summary))
metadata.appendElement(createElt("Description",
package.description))
metadata.appendElement(createElt("Category",
package.category))
elt = createElt("InstallDependencies")
for idep in package.installDeps:
d = createElt("Depencency", idep.package)
# we should also have versionTo and version
# attributes. But specfile/DepInfo doesn't defines
# them. So we don't here
if idep.versionFrom:
d.setAttribute("versionFrom", idep.versionFrom)
elt.appendChild(d)
metadata.appendElement(elt)
elt = createElt("RuntimeDependencies")
for rdep in package.runtimeDeps:
d = createElt("Depencency", rdep.package)
if rdep.versionFrom:
d.setAttribute("versionFrom", rdep.versionFrom)
elt.appendChild(d)
metadata.appendElement(elt)
metadata.appendElement(createElt("License",
self.spec.source.license))
metadata.appendElement(createElt("Distribution",
const.distribution))
metadata.appendElement(createElt("DistributionRelease",
const.distributionRelease))
metadata.appendElement(createElt("Architecture",
"Any")) # FIXME
# FIXME: Bu hatalı. installsize'ı almak için tüm # FIXME: Bu hatalı. installsize'ı almak için tüm
# pkg_install_dir()'ın boyutunu hesaplayamayız. Bir source # pkg_install_dir()'ın boyutunu hesaplayamayız. Bir source
# birden fazla kaynak üretebilir. package.paths ile # birden fazla kaynak üretebilir. package.paths ile
# karşılaştırarak file listesinden boyutları hesaplatmalıyız. # karşılaştırarak file listesinden boyutları hesaplatmalıyız.
d = self.ctx.pkg_install_dir() d = self.ctx.pkg_install_dir()
size = util.dir_size(d) size = util.dir_size(d)
metadata.appendElement(createElt("InstalledSize", metadata.package.installedSize = str(size)
str(size)))
elt = createElt("History")
for history in self.spec.source.history:
update = createElt("Update")
update.appendChild(createElt("Date", history.date))
update.appendChild(createElt("Version", history.version))
update.appendChild(createElt("Release", history.release))
elt.appendChild(update)
metadata.appendElement(elt)
metadata.write(os.path.join(self.ctx.pkg_dir(), const.metadata_xml)) metadata.write(os.path.join(self.ctx.pkg_dir(), const.metadata_xml))
def genFilesXml(self, package): def genFilesXml(self, package):
+44 -29
View File
@@ -2,49 +2,64 @@
from ui import ui from ui import ui
from xmlfile import * from xmlfile import *
from specfile import * import specfile
class SourceInfo:
def __init__(self, node):
self.name = getNodeText(node, "Name")
self.homepage = getNodeText(node, "HomePage")
self.packager = specfile.PackagerInfo(getNode(node, "Packager"))
def elt(self, xml):
node = xml.newNode("Source")
xml.addTextNodeUnder(node, "Name", self.name)
if self.homepage:
xml.addTextNodeUnder(node, "Homepage", self.homepage)
xml.addNodeUnder(node, "", self.packager.elt(xml))
return node
class PackageInfo(specfile.PackageInfo):
def __init__(self, node):
specfile.PackageInfo.__init__(self, node)
self.distribution = getNodeText(node, "Distribution")
self.distributionRelease = getNodeText(node, "DistributionRelease")
self.architecture = getNodeText(node, "Architecture")
istext = getNodeText(node, "InstalledSize")
if istext:
self.installedSize = int(istext)
class MetaData(XmlFile): class MetaData(XmlFile):
"""Package metadata. Metadata is composed of Specfile and various """Package metadata. Metadata is composed of Specfile and various
other information.""" other information."""
def __init__(self): def __init__(self):
XmlFile.__init__(self,"PISI") XmlFile.__init__(self,"PISI")
self.eltList = []
def fromSpec(src, pkg):
self.source.name = src.source.name
self.source.homepage = src.source.homepage
self.source.packager = src.source.packager
self.package = src.package
self.package.history = self.source.history # FIXME
def read(self, filename): def read(self, filename):
self.readxml(filename) self.readxml(filename)
self.source = SourceInfo(self.getNode("Source"))
getNodeText = self.getNodeText self.package = PackageInfo(self.getNode("Package"))
self.package.version = self.package.history[0].version
self.name = getNodeText("Name") self.package.release = self.package.history[0].release
# self.summary # birden fazla olabilir (tr, en) SummaryInfo
# icerisine almakta yarar var. SpecFile'da da
# bu sekilde bir duzenleme gerekiyor.
self.homepage = getNodeText("Homepage")
self.license = getNodeText("License")
historyElts = self.getAllNodes("History/Update")
self.history = [UpdateInfo(x) for x in historyElts]
self.version = self.history[0].version
self.release = self.history[0].release
self.distribution = getNodeText("Distribution")
self.distributionRelease = getNodeText("DistributionRelease")
self.architecture = getNodeText("Architecture")
size = self.getNodeText("InstalledSize")
if size:
self.installedSize = int(size)
def appendElement(self, elt):
self.eltList.append(elt)
def write(self, filename): def write(self, filename):
self.newDOM() self.newDOM()
document = self.dom.documentElement self.addNode("", self.source.elt(self))
for elt in self.eltList: self.addNode("", self.package.elt(self))
document.appendChild(elt)
self.writexml(filename) self.writexml(filename)
def verify(self): def verify(self):
assert self.getAllNodes("Package")==1
assert self.source.name != None
assert self.source.homepage != None
assert self.source.packager != None
return True return True
+75 -39
View File
@@ -7,6 +7,17 @@ from xmlfile import XmlFile
from os.path import basename from os.path import basename
from ui import ui from ui import ui
class PackagerInfo:
def __init__(self, node):
self.name = getNodeText(getNode(node, "Name"))
self.email = getNodeText(getNode(node, "Email"))
def elt(self, xml):
node = xml.newNode("Update")
xml.addTextNodeUnder(node, "Name", self.name)
xml.addTextNodeUnder(node, "Email", self.email)
return node
class PatchInfo: class PatchInfo:
def __init__(self, filenm, ctype): def __init__(self, filenm, ctype):
self.filename = filenm self.filename = filenm
@@ -16,11 +27,12 @@ class PatchInfo:
self.filename = getNodeText(node) self.filename = getNodeText(node)
self.compressionType = getNodeAttribute(node, "compressionType") self.compressionType = getNodeAttribute(node, "compressionType")
def addNode(self, xml): def elt(self, xml):
node = xml.addNode("Source/Patches/Patch") node = xml.newNode("Patch")
node.setAttribute("filename", self.filename) node.setAttribute("filename", self.filename)
if self.compressionType: if self.compressionType:
node.setAttribute("compressionType", self.compressionType) node.setAttribute("compressionType", self.compressionType)
return node
class DepInfo: class DepInfo:
def __init__(self, node): def __init__(self, node):
@@ -61,34 +73,80 @@ class PathInfo:
node.setAttribute("fileType", self.fileType) node.setAttribute("fileType", self.fileType)
return node return node
# a structure to hold source information
class SourceInfo: class SourceInfo:
pass "a structure to hold source information"
def __init__(self, node):
self.name = getNodeText(node, "Name")
self.homepage = getNodeText(node, "HomePage")
self.packager = PackagerInfo(getNode(node, "Packager"))
self.license = getNodeText(node, "License")
self.isa = getNodeText(node, "IsA")
self.partof = getNodeText(node, "PartOf")
archiveNode = getNode(node, "Archive")
self.archiveUri = getNodeText(archiveNode).strip()
self.archiveName = basename(self.archiveUri)
self.archiveType = getNodeAttribute(archiveNode, "archType")
self.archiveSHA1 = getNodeAttribute(archiveNode, "sha1sum")
patchElts = getAllNodes(node, "Patches/Patch")
self.patches = [PatchInfo(p) for p in patchElts]
buildDepElts = getAllNodes(node, "BuildDependencies/Dependency")
self.buildDeps = [DepInfo(d) for d in buildDepElts]
historyElts = getAllNodes(node, "History/Update")
self.history = [UpdateInfo(x) for x in historyElts]
def elt(self, xml):
node = xml.newNode("Source")
xml.addTextNodeUnder(node, "Name", self.name)
if self.homepage:
xml.addTextNodeUnder(node, "Homepage", self.homepage)
xml.addNodeUnder(node, "", self.packager.elt(xml))
xml.addTextNodeUnder(node, "License", self.license)
xml.addTextNodeUnder(node, "IsA", self.isa)
xml.addTextNodeUnder(node, "PartOf", self.partof)
archiveNode = xml.addNodeUnder(node, "Archive")
archiveNode.setAttribute("archType", self.archiveType)
archiveNode.setAttribute("sha1sum", self.archiveSHA1)
for patch in self.patches:
xml.addNodeUnder(node, "Patches", patch.elt(xml))
for dep in self.buildDeps:
xml.addNodeUnder(node, "BuildDependencies", dep.elt(xml))
for update in self.history:
xml.addNodeUnder(node, "History", update.elt(xml))
return node
class PackageInfo: class PackageInfo:
def __init__(self, node): def __init__(self, node):
self.name = getNodeText(getNode(node, "Name")) self.name = getNodeText(node, "Name")
self.summary = getNodeText(getNode(node, "Summary")) self.summary = getNodeText(node, "Summary")
self.description = getNodeText(getNode(node, "Description")) self.description = getNodeText(node, "Description")
self.category = getNodeText(getNode(node, "Category")) self.isa = getNodeText(node, "IsA")
self.partof = getNodeText(node, "PartOf")
self.license = getNodeText(node, "License")
iDepElts = getAllNodes(node, "InstallDependencies/Dependency") iDepElts = getAllNodes(node, "InstallDependencies/Dependency")
self.installDeps = [DepInfo(x) for x in iDepElts] self.installDeps = [DepInfo(x) for x in iDepElts]
rtDepElts = getAllNodes(node, "RuntimeDependencies/Dependency") rtDepElts = getAllNodes(node, "RuntimeDependencies/Dependency")
self.runtimeDeps = [DepInfo(x) for x in rtDepElts] self.runtimeDeps = [DepInfo(x) for x in rtDepElts]
self.paths = [PathInfo(x) for x in getAllNodes(node, "Files/Path")] self.paths = [PathInfo(x) for x in getAllNodes(node, "Files/Path")]
historyElts = getAllNodes(node, "History/Update")
self.history = [UpdateInfo(x) for x in historyElts]
def elt(self, xml): def elt(self, xml):
node = xml.newNode("Package") node = xml.newNode("Package")
xml.addTextNodeUnder(node, "Name", self.name) xml.addTextNodeUnder(node, "Name", self.name)
xml.addTextNodeUnder(node, "Summary", self.summary) xml.addTextNodeUnder(node, "Summary", self.summary)
xml.addTextNodeUnder(node, "Description", self.description) xml.addTextNodeUnder(node, "Description", self.description)
xml.addTextNodeUnder(node, "Category", self.category) if self.isa:
for dep in map(lambda x : x.elt(xml), self.installDeps): xml.addTextNodeUnder(node, "IsA", self.isa)
xml.addNode("Source/InstallDependencies", dep) if self.partof:
for dep in map(lambda x : x.elt(xml), self.runtimeDeps): xml.addTextNodeUnder(node, "PartOf", self.partof)
xml.addNode("Source/RuntimeDependencies", dep) for dep in self.installDeps:
for path in map(lambda x : x.elt(xml), self.paths): xml.addNodeUnder(node, "InstallDependencies", dep.elt(xml))
xml.addNode("Files", dep) for dep in self.runtimeDeps:
xml.addNodeUnder(node, "RuntimeDependencies", dep.elt(xml))
for path in self.paths:
xml.addNodeUnder(node, "Files", path.elt(xml))
for update in self.history:
xml.addNodeUnder(node, "History", update.elt(xml))
return node return node
class SpecFile(XmlFile): class SpecFile(XmlFile):
@@ -102,20 +160,7 @@ class SpecFile(XmlFile):
self.readxml(filename) self.readxml(filename)
self.source = SourceInfo() self.source = SourceInfo(self.getNode("Source"))
self.source.name = self.getChildText("Source/Name")
self.source.license = self.getChildText("Source/License")
archiveNode = self.getNode("Source/Archive")
self.source.archiveUri = getNodeText(archiveNode).strip()
self.source.archiveName = basename(self.source.archiveUri)
self.source.archiveType = getNodeAttribute(archiveNode, "archType")
self.source.archiveSHA1 = getNodeAttribute(archiveNode, "sha1sum")
patchElts = self.getAllNodes("Source/Patches/Patch")
self.source.patches = [PatchInfo(p) for p in patchElts]
buildDepElts = self.getAllNodes("Source/BuildDependencies/Dependency")
self.source.buildDeps = [DepInfo(d) for d in buildDepElts]
historyElts = self.getAllNodes("History/Update")
self.source.history = [UpdateInfo(x) for x in historyElts]
# As we have no Source/Version tag we need to get # As we have no Source/Version tag we need to get
# the last version and release information # the last version and release information
@@ -136,16 +181,7 @@ class SpecFile(XmlFile):
def write(self, filename): def write(self, filename):
"""Write PSPEC file""" """Write PSPEC file"""
self.newDOM() self.newDOM()
self.addTextNode("Source/Name", self.source.name) self.addNode("", self.source.elt(self))
archiveNode = self.addNode("Source/Archive")
archiveNode.setAttribute("archType", self.source.archiveType)
archiveNode.setAttribute("sha1sum", self.source.archiveSHA1)
for patch in self.source.patches:
patch.addNode(self)
for dep in map(lambda x : x.elt(self), self.source.buildDeps):
self.addNode("Source/BuildDependencies", dep)
for update in map(lambda x : x.elt(self), self.source.history):
self.addNode("Source/History", dep)
for pkg in map(lambda x : x.elt(self), self.packages): for pkg in map(lambda x : x.elt(self), self.packages):
self.addNode("", pkg) self.addNode("", pkg)
self.writexml(filename) self.writexml(filename)
+3 -1
View File
@@ -13,8 +13,10 @@ def getNodeAttribute(node, attrname):
if attr.name == attrname: if attr.name == attrname:
return attr.childNodes[0].data return attr.childNodes[0].data
def getNodeText(node): def getNodeText(node, tagpath = ""):
"""get the first child and expect it to be text!""" """get the first child and expect it to be text!"""
if tagpath!="":
node = getNode(node, tagpath)
try: try:
child = node.childNodes[0] child = node.childNodes[0]
except IndexError: except IndexError:
+6 -8
View File
@@ -37,6 +37,8 @@ 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")
# construction helpers
def newNode(self, tag): def newNode(self, tag):
return self.dom.createElement(tag) return self.dom.createElement(tag)
@@ -55,8 +57,10 @@ class XmlFile(object):
def getNodeText(self, tagPath): def getNodeText(self, tagPath):
"""returns the text of *first* matching node for given tag path.""" """returns the text of *first* matching node for given tag path."""
self.verifyRootTag() node = self.getNode(tagpath)
return getNodeText(getNode(self.dom.documentElement, tagPath)) if not node:
return None
return getNodeText(node)
def getAllNodes(self, tagPath): def getAllNodes(self, tagPath):
"""returns all nodes matching a given tag path.""" """returns all nodes matching a given tag path."""
@@ -84,12 +88,6 @@ class XmlFile(object):
except AttributeError: except AttributeError:
return None return None
def getChildText(self, tagpath):
node = self.getNode(tagpath)
if not node:
return None
return getNodeText(node)
# write helpers # write helpers
def addNode(self, tagPath, newnode = None): def addNode(self, tagPath, newnode = None):
+9
View File
@@ -13,6 +13,8 @@
<Email>hotmail@redhat.com</Email> <Email>hotmail@redhat.com</Email>
</Packager> </Packager>
<License>As-Is</License> <License>As-Is</License>
<IsA>library:util</IsA>
<PartOf>rpm:archive</PartOf>
<Archive archType="targz" sha1sum="66f3c77b87a160951b180447f4a6dce68ad2f71b"> <Archive archType="targz" sha1sum="66f3c77b87a160951b180447f4a6dce68ad2f71b">
ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/popt-1.7.tar.gz ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/popt-1.7.tar.gz
</Archive> </Archive>
@@ -66,5 +68,12 @@
<Path fileType="localedata">/usr/share/locale</Path> <Path fileType="localedata">/usr/share/locale</Path>
<Path fileType="header">/usr/include/popt.h</Path> <Path fileType="header">/usr/include/popt.h</Path>
</Files> </Files>
<History>
<Update>
<Date>06/14/2005</Date>
<Version>1.7</Version>
<Release>2</Release>
</Update>
</History>
</Package> </Package>
</PISI> </PISI>
+1 -1
View File
@@ -7,6 +7,6 @@ class gnuConfigTestCase(unittest.TestCase):
self.gnuconfig = gnuconfig.gnuconfig_findnewest() self.gnuconfig = gnuconfig.gnuconfig_findnewest()
def testFindNewest(self): def testFindNewest(self):
self.assertEqual(self.gnuconfig, '/usr/share/automake-1.4') self.assert_ (self.gnuconfig > '/usr/share/automake-1.4')
suite = unittest.makeSuite(gnuConfigTestCase) suite = unittest.makeSuite(gnuConfigTestCase)
+8 -5
View File
@@ -4,7 +4,7 @@ import os
from pisi import metadata from pisi import metadata
from pisi import util from pisi import util
from pisi import context from pisi.config import config
class MetaDataTestCase(unittest.TestCase): class MetaDataTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
@@ -14,13 +14,16 @@ class MetaDataTestCase(unittest.TestCase):
md = metadata.MetaData() md = metadata.MetaData()
md.read('tests/sandbox/metadata.xml') md.read('tests/sandbox/metadata.xml')
self.assertEqual(md.license, "As-Is") self.assertEqual(md.package.license, "As-Is")
self.assertEqual(md.version, "1.7") self.assertEqual(md.package.version, "1.7")
self.assertEqual(md.installedSize, 546542) self.assertEqual(md.package.installedSize, 546542)
return md
def testWrite(self): def testWrite(self):
pass md = self.testRead()
md.write(os.path.join(config.tmp_dir(),'metadata-test.xml' ))
suite = unittest.makeSuite(MetaDataTestCase) suite = unittest.makeSuite(MetaDataTestCase)
+7 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<METADATA> <PISI>
<Source> <Source>
<Name>sandbox</Name> <Name>sandbox</Name>
@@ -13,20 +13,22 @@
<Package> <Package>
<Name>sandbox</Name> <Name>sandbox</Name>
<Summary lang="tr">Bla</Summary> <Summary lang="tr">Bla</Summary>
<Description>Life sucks then you die</Description>
<Homepage>http://cekirdek.uludag.org.tr/~meren/</Homepage> <Homepage>http://cekirdek.uludag.org.tr/~meren/</Homepage>
<IsA>temprorary:zip</IsA>
<PartOf>tools:archive</PartOf>
<License>As-Is</License> <License>As-Is</License>
<Category>temprorary:zip</Category>
<History> <History>
<Update> <Update>
<Date>06/15/2005</Date> <Date>06/15/2005</Date>
<Version>0.1</Version> <Version>1.7</Version>
<Release>1</Release> <Release>1</Release>
</Update> </Update>
</History> </History>
<Distribution>Pardus</Distribution> <Distribution>Pardus</Distribution>
<DistributionRelease>0.1</DistributionRelease> <DistributionRelease>0.1</DistributionRelease>
<Architecture>x86</Architecture> <Architecture>x86</Architecture>
<InstalledSize>40500</InstalledSize> <InstalledSize>546542</InstalledSize>
</Package> </Package>
</METADATA> </PISI>