changeset 410:5e8546444a8e treepkg-status

added a new root element which is called TreepkgRoot for Treepkg Info classes
author Bjoern Ricks <bricks@intevation.de>
date Thu, 22 Jul 2010 11:02:36 +0000
parents ecc671a84a73
children 8dd64f8bf572
files treepkg/info/status.py
diffstat 1 files changed, 38 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/info/status.py	Thu Jul 22 10:26:40 2010 +0000
+++ b/treepkg/info/status.py	Thu Jul 22 11:02:36 2010 +0000
@@ -54,8 +54,9 @@
     def __init__(self, config, numnewestrev=-1):
         self.numnewestrev = numnewestrev
         group = get_packager_group(config)
-        self.tpkgroot = TreepkgRootInfo(group.name, group.treepkg_dir, 
+        treepkgrootinfo = TreepkgRootInfo(group.name, group.treepkg_dir, 
                                         group.tracks_dir)
+        self.tpgkroot = TreepkgRoot(version, treepkgrootinfo)
         tracks = group.get_package_tracks()
 
         for track in tracks:
@@ -73,7 +74,7 @@
         if not root.tagName == "treepkg":
             print xmlstr
             raise TreepkgInfoException("XML is not valid for treepkginfo")
-        return TreepkgRootInfo.fromxml(root)
+        return TreepkgRoot.fromxml(root)
 
     def add_revisions(self, track, trackinfo):
         revisions = track.get_revisions()
@@ -115,6 +116,40 @@
         pkginfo.add_checksum(checksuminfo)
         revision.add_package(pkginfo)
 
+class TreepkgRoot:
+    
+    def __init__(self, version, info)
+        self.version = version
+        self.info = info
+        self.tracks = []
+
+    def add_track(self, track):
+        self.tracks.append(track)
+
+    def toxml(self):
+        (doc, root) = createTpkgRoot("treepkg")
+        root.setAttributeNS(TREEPKG_NAMESPACE_URI, "version", self.version)
+        if len(self.tracks) > 0:
+            tracksele = createTpkgElement(doc, "tracks")
+            for track in self.tracks:
+                tracksele.appendChild(track.toxml())
+            root.appendChild(tracksele)
+        root.appendChild(info.toxml())
+        return root
+
+    @staticmethod
+    def fromxml(node):
+        version = node.getAttribute("version")
+        trackseles = node.getElementsByTagName("tracks")
+        infoele = getChild(node, "info")
+        treepkgrootinfo = TreepkgRootInfo.fromxml(infoele)
+        treepkgroot = TreepkgRoot(version, treepkgrootinfo)
+        tracks = []
+        for trackele in trackseles:
+            tracks.append(TreepkgTrackInfo.fromxml(trackele))
+        treepkgroot.tracks = tracks
+        return treepkgroot
+ 
 class TreepkgRootInfo:
 
     def __init__(self, name, treepkgpath=None, trackspath=None, version=None):
@@ -122,10 +157,6 @@
         self.treepkgpath = treepkgpath
         self.trackspath = trackspath
         self.version = version
-        self.tracks = []
-
-    def add_track(self, track):
-        self.tracks.append(track)
 
     def toxml(self):
         (doc, root) = createTpkgRoot("info")
@@ -152,12 +183,7 @@
             text = doc.createTextNode(self.version)
             versionele.appendChild(text)
             root.appendChild(versionele)
-        if len(self.tracks) > 0:
-            tracksele = createTpkgElement(doc, "tracks")
-            for track in self.tracks:
-                tracksele.appendChild(track.toxml())
-            root.appendChild(tracksele)
-        return root
+       return root
     
     @staticmethod
     def fromxml(node):
@@ -169,12 +195,7 @@
         treepkgpath = getTextFromNode(treepkgpathele)
         trackspathele = getChild(infoele, "trackspath")
         trackspath = getTextFromNode(trackspathele)
-        trackseles = node.getElementsByTagName("tracks")
-        tracks = []
-        for trackele in trackseles:
-            tracks.append(TreepkgTrackInfo.fromxml(trackele))
         trackinfo = TreepkgRootInfo(name, treepkgpath, trackspath, version)
-        trackinfo.tracks = tracks
         return trackinfo
 
 class TreepkgTrackInfo:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)