# HG changeset patch # User Bjoern Ricks # Date 1278517248 0 # Node ID ffa86312ee81dd2a55fc0f1488ad7f51896153bc # Parent d6fb7106f053b900134eca043fdb17972f792b02 added classed for treepkg status xml generation diff -r d6fb7106f053 -r ffa86312ee81 test/status/test_status.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/status/test_status.py Wed Jul 07 15:40:48 2010 +0000 @@ -0,0 +1,29 @@ +# Copyright (C) 2010 by Intevation GmbH +# Authors: +# Bjoern Ricks +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. + +"""Tests for treepkg.status.status""" + +import unittest +import os.path +import sys + +test_dir = os.path.dirname(__file__) +sys.path.append(os.path.join(test_dir, os.pardir, os.pardir)) + +from treepkg.status.status import TreepkgStatus + +class TreepkgStatusTest(unittest.TestCase): + + def test_toxml(self): + status = TreepkgStatus("testtreepkg") + dom = status.toxml() + xml = dom.toxml() + self.assertEquals("testtreepkg", xml) + +if __name__ == '__main__': + unittest.main() + diff -r d6fb7106f053 -r ffa86312ee81 treepkg/status/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/treepkg/status/__init__.py Wed Jul 07 15:40:48 2010 +0000 @@ -0,0 +1,6 @@ +# Copyright (C) 2007 by Intevation GmbH +# Authors: +# Bernhard Herzog +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. diff -r d6fb7106f053 -r ffa86312ee81 treepkg/status/status.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/treepkg/status/status.py Wed Jul 07 15:40:48 2010 +0000 @@ -0,0 +1,198 @@ +# Copyright (C) 2010 by Intevation GmbH +# Authors: +# Bjoern Ricks +# +# This program is free software under the GPL (>=v2) +# Read the file COPYING coming with the software for details. + +"""Build treepkg status information""" + +import xml.dom.minidom + +TREEPKG_NAMESPACE_URI = "http://wald.intevation.org/projects/treepkg/" +TREEPKG_NAMESPACE_PREFIX = "tpkg" + +def createTpkgElement(doc, name): + return doc.createElementNS(TREEPKG_NAMESPACE_URI, name) + +def createTpkgRoot(name): + domimpl = xml.dom.minidom.getDOMImplementation() + doc = domimpl.createDocument(TREEPKG_NAMESPACE_URI, name, None) + root = doc.documentElement + return (doc, root) + +class TreepkgStatus: + + def __init__(self, name, treepkgpath=None, millpath=None, version=None): + self.name = name + self.treepkgpath = treepkgpath + self.millpath = millpath + self.version = version + + def toxml(self): + (doc, root) = createTpkgRoot("status") + # add + nameele = createTpkgElement(doc, "name") + text = doc.createTextNode(self.name) + nameele.appendChild(text) + root.appendChild(nameele) + # add + if self.treepkgpath: + treepkgpathele = createTpkgElement(doc, "treepkgpath") + text = doc.createTextNode(self.treepkgpath) + treepkgpathele.appendChild(text) + root.appendChild(treepkgpathele) + # add + if self.millpath: + millpathele = createTpkgElement(doc, "millpath") + text = doc.createTextNode(self.millpath) + millpathele.appendChild(text) + root.appendChild(millpathele) + # add + if self.version: + versionele = createTpkgElement(doc, "version") + text = doc.createTextNode(self.version) + versionele.appendChild(text) + root.appendChild(version) + return root + +class TreepkgTrack: + + def __init__(self, name): + self.name = name + self.revisions = [] + + def add_revision(self, revision): + self.revisions.append(revision) + + def toxml(self): + (doc, root) = createTpkgRoot("track") + nameele = createTpkgElement(doc, "name") + text = doc.createTextNode(self.name) + nameele.appendChild(text) + root.appendChild(nameele) + for rev in self.revision: + root.appendChild(rev.toxml()) + return root + +class TreepkgTrackRevision: + + def __init__(self, number, rules, status, platform): + self.number = number + self.rules = rules + self.status = status + self.platform = platform + + def toxml(self): + (doc, root) = createTpkgRoot("revision") + # add + numberele = createTpkgElement(doc, "number") + text = doc.createTextNode(self.number) + numbverele.appendChild(text) + root.appendChild(numberele) + # add + rulesele = createTpkgElement(doc, "rules") + text = doc.createTextNode(self.rules) + rulesele.appendChild(text) + root.appendChild(rulesele) + # add + statusele = createTpkgElement(doc, "status") + messageele = createTpkgElement(doc, "message") + text = doc.createTextNode(self.status) + messageele.appendChild(text) + statusele.appendChild(messageele) + root.appendChild(statusele) + # add + root.appendChild(platform.toxml()) + return root + +class TreepkgPlatform: + + def __init__(self, os, arch): + self.os = os + self.arch = arch + self.packages = [] + self.logs = [] + + def add_package(self, package): + self.packages.append(package) + + def add_log(self, log): + self.logs.append(log) + + def toxml(self): + (doc, root) = createTpkgRoot("platform") + # add + osele = createTpkgElement(doc, "os") + text = doc.createTextNode(self.os) + osele.appendChild(text) + root.appendChild(osele) + # add + archele = createTpkgElement(doc, "arch") + text = doc.createTextNode(sef.arch) + archele.appendChild(text) + root.appendChild(archele) + # add + packagesele = createTpkgElement(doc, "packages") + for package in self.packages: + packagesele.appendChild(package.toxml()) + root.appendChild(packagesele) + # add + logsele = createTpkgElement(doc, "logs") + for log in self.logs: + losele.appendChild(log) + root.appendChild(logsele) + return root + +class TreepkgLog: + + def __init__(self, name, path): + self.name = name + self.path = path + + def toxml(self) + (doc, root) = createTpkgRoot("log") + # add + nameele = createTpkgElement(doc, "name") + text = doc.createTextNode(self.name) + nameele.appendChild(text) + root.appendChild(nameele) + # add path + pathele = createTpkgElement(doc, "path") + text = doc.createTextNode(self.path) + pathele.appendChild(text) + root.appendChild(pathele) + return root + +class TreepkgPackage: + + def __init__(self, name, path, type, checksum = None): + self.name = name + self.path = path + self.type = type + self.checksum = checksum + + def toxml(self): + (doc, root) = createTpkgRoot("package") + # add + nameele = createTpkgElement(doc, "name") + text = doc.createTextNode(self.name) + nameele.appendChild(text) + root.appendChild(nameele) + # add + pathele = createTpkgElement("path") + text = doc.createTextNode(self.path) + pathele.appendChild(text) + root.appendChild(pathele) + # add + if self.checksum: + checksumele = createTpkgElement(doc, "checksum") + text = doc.createTextNode(self.checksum) + checksumele.appendChild(text) + root.appendChild(checksumele) + # add + typeele = createTpkgElement(doc, "type") + text = doc.createTextNode(self.type) + typeele.appendChild(text) + root.appendChild(typeele) + diff -r d6fb7106f053 -r ffa86312ee81 treepkg/status/status.xsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/treepkg/status/status.xsd Wed Jul 07 15:40:48 2010 +0000 @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +