[Treepkg-commits] r346 - in branches/treepkg-status: test test/status treepkg treepkg/status

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jul 7 17:40:48 CEST 2010


Author: bricks
Date: 2010-07-07 17:40:48 +0200 (Wed, 07 Jul 2010)
New Revision: 346

Added:
   branches/treepkg-status/test/status/
   branches/treepkg-status/test/status/test_status.py
   branches/treepkg-status/treepkg/status/
   branches/treepkg-status/treepkg/status/__init__.py
   branches/treepkg-status/treepkg/status/status.py
   branches/treepkg-status/treepkg/status/status.xsd
Log:
added classed for treepkg status xml generation


Added: branches/treepkg-status/test/status/test_status.py
===================================================================
--- branches/treepkg-status/test/status/test_status.py	2010-07-07 13:32:28 UTC (rev 345)
+++ branches/treepkg-status/test/status/test_status.py	2010-07-07 15:40:48 UTC (rev 346)
@@ -0,0 +1,29 @@
+# Copyright (C) 2010 by Intevation GmbH
+# Authors:
+# Bjoern Ricks <bjoern.ricks at intevation.de>
+#
+# 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("<status><name>testtreepkg</name></status>", xml)
+
+if __name__ == '__main__':
+    unittest.main()
+

Added: branches/treepkg-status/treepkg/status/__init__.py
===================================================================
--- branches/treepkg-status/treepkg/status/__init__.py	2010-07-07 13:32:28 UTC (rev 345)
+++ branches/treepkg-status/treepkg/status/__init__.py	2010-07-07 15:40:48 UTC (rev 346)
@@ -0,0 +1,6 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.

Added: branches/treepkg-status/treepkg/status/status.py
===================================================================
--- branches/treepkg-status/treepkg/status/status.py	2010-07-07 13:32:28 UTC (rev 345)
+++ branches/treepkg-status/treepkg/status/status.py	2010-07-07 15:40:48 UTC (rev 346)
@@ -0,0 +1,198 @@
+# Copyright (C) 2010 by Intevation GmbH
+# Authors:
+# Bjoern Ricks <bjoern.ricks at intevation.de>
+#
+# 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 <name>
+        nameele = createTpkgElement(doc, "name")
+        text = doc.createTextNode(self.name)
+        nameele.appendChild(text)
+        root.appendChild(nameele)
+        # add <treepkgpath>
+        if self.treepkgpath:
+            treepkgpathele = createTpkgElement(doc, "treepkgpath")
+            text = doc.createTextNode(self.treepkgpath)
+            treepkgpathele.appendChild(text)
+            root.appendChild(treepkgpathele)
+        # add <millpath>
+        if self.millpath:
+            millpathele = createTpkgElement(doc, "millpath")
+            text = doc.createTextNode(self.millpath)
+            millpathele.appendChild(text)
+            root.appendChild(millpathele)
+        # add <version>
+        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 <number>
+        numberele = createTpkgElement(doc, "number")
+        text = doc.createTextNode(self.number)
+        numbverele.appendChild(text)
+        root.appendChild(numberele)
+        # add <rules>
+        rulesele = createTpkgElement(doc, "rules")
+        text = doc.createTextNode(self.rules)
+        rulesele.appendChild(text)
+        root.appendChild(rulesele)
+        # add <status><message></message></status>
+        statusele = createTpkgElement(doc, "status")
+        messageele = createTpkgElement(doc, "message")
+        text = doc.createTextNode(self.status)
+        messageele.appendChild(text)
+        statusele.appendChild(messageele)
+        root.appendChild(statusele)
+        # add <platform>
+        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 <os>
+        osele = createTpkgElement(doc, "os")
+        text = doc.createTextNode(self.os)
+        osele.appendChild(text)
+        root.appendChild(osele)
+        # add <arch>
+        archele = createTpkgElement(doc, "arch")
+        text = doc.createTextNode(sef.arch)
+        archele.appendChild(text)
+        root.appendChild(archele)
+        # add <packages>
+        packagesele = createTpkgElement(doc, "packages")
+        for package in self.packages:
+            packagesele.appendChild(package.toxml())
+        root.appendChild(packagesele)
+        # add <logs>
+        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 <name>
+        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 <name>
+            nameele = createTpkgElement(doc, "name")
+            text = doc.createTextNode(self.name)
+            nameele.appendChild(text)
+            root.appendChild(nameele)
+            # add <path>
+            pathele = createTpkgElement("path")
+            text = doc.createTextNode(self.path)
+            pathele.appendChild(text)
+            root.appendChild(pathele)
+            # add <checksum>
+            if self.checksum:
+                checksumele = createTpkgElement(doc, "checksum")
+                text = doc.createTextNode(self.checksum)
+                checksumele.appendChild(text)
+                root.appendChild(checksumele)
+            # add <type>
+            typeele = createTpkgElement(doc, "type")
+            text = doc.createTextNode(self.type)
+            typeele.appendChild(text)
+            root.appendChild(typeele)
+

Added: branches/treepkg-status/treepkg/status/status.xsd
===================================================================
--- branches/treepkg-status/treepkg/status/status.xsd	2010-07-07 13:32:28 UTC (rev 345)
+++ branches/treepkg-status/treepkg/status/status.xsd	2010-07-07 15:40:48 UTC (rev 346)
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            xmlns:tpkg="http://wald.intevation.org/projects/treepkg/"
+            targetNamespace="http://wald.intevation.org/projects/treepkg/">
+
+    <xsd:element name="treepkg">
+        <xsd:complexType>
+            <xsd:sequence>
+                <xsd:element name="tracks" type="tpkg:tracks"/>
+                <xsd:element name="info" type="tpkg:info" minOccurs="1"/>
+            </xsd:sequence>
+            <!-- xml schema version -->
+            <xsd:attribute name="version" type="xsd:string"/>
+        </xsd:complexType>
+    </xsd:element>
+
+    <xsd:complexType name="info">
+        <xsd:sequence>
+            <xsd:element name="name" type="xsd:string" minOccurs="1"/>
+            <xsd:element name="treepkgpath" type="xsd:string"/>
+            <xsd:element name="millpath" type="xsd:string"/>
+            <!-- treepkg version e.g. svn revision  -->
+            <xsd:element name="version" type="xsd:string"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="tracks">
+        <xsd:sequence>
+            <xsd:element name="track" type="tpkg:track" maxOccurs="unbounded"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="track">
+        <xsd:sequence>
+            <xsd:element name="name" type="xsd:string" minOccurs="1"/>
+            <xsd:element name="revision" type="tpkg:revision"
+            maxOccurs="unbounded"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="revision">
+        <xsd:sequence>
+            <xsd:element name="number" type="xsd:string" minOccurs="1"/>
+            <xsd:element name="rules" type="xsd:string" minOccurs="1"/>
+            <xsd:element name="status" type="tpkg:revisionstatus" minOccurs="1"/>
+            <xsd:element name="platform" type="tpkg:platform" minOccurs="1"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="revisionstatus">
+        <xsd:sequence>
+            <xsd:element name="message" type="xsd:string"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="platform">
+        <xsd:sequence>
+            <xsd:element name="os" type="xsd:string"/>
+            <xsd:element name="arch" type="xsd:string"/>
+            <xsd:element name="packages" type="tpkg:packages"/>
+            <xsd:element name="logs" type="tpkg:logs"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="logs">
+        <xsd:sequence>
+            <xsd:element name="log" type="tpkg:log"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType nam="log">
+        <xsd:sequence>
+            <xsd:element name="name" type="xsd:string"/>
+            <xsd:element name="path" type="xsd:string"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+
+    <xsd:complexType name="packages">
+        <xsd:sequence>
+            <xsd:element name="package" type="tpkg:package"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:complexType name="package">
+        <xsd:sequence>
+            <xsd:element name="name" type="xsd:string" minOccurs="1"/>
+            <xsd:element name="path" type="xsd:string" minOccurs="1">
+            <xsd:element name="checksum" type="xsd:string"/>
+            <xsd:element name="type" type="tpkg:pkgtype" minOccurs="1"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:simpleType name="pkgtype">
+        <xsd:restriction base="xsd:string">
+            <xsd:enumeration value="binary"/>
+            <xsd:enumeration value="source"/>
+        </xsd:restriction>
+    </xsd:simpleType>
+</xsd:schema>



More information about the Treepkg-commits mailing list