annotate treepkg/info/status.py @ 407:fb473f67345b treepkg-status

implemented parsing from xml string
author Bjoern Ricks <bricks@intevation.de>
date Wed, 21 Jul 2010 15:52:15 +0000
parents 52e3c3976e53
children ecc671a84a73
rev   line source
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2010 by Intevation GmbH
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
2 # Authors:
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
3 # Bjoern Ricks <bjoern.ricks@intevation.de>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
4 #
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
7
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
8 """Build treepkg status information"""
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
9
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
10 import os.path
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
11 import xml.dom.minidom
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
12
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
13 from treepkg.report import get_packager_group
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
14 from treepkg.util import md5sum
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
15 from treepkg.info.package import BinaryPackage
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
16
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
17 TREEPKG_NAMESPACE_URI = "http://wald.intevation.org/projects/treepkg/"
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
18 TREEPKG_NAMESPACE_PREFIX = "tpkg"
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
19
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
20 def createTpkgElement(doc, name):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
21 return doc.createElementNS(TREEPKG_NAMESPACE_URI, name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
22
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
23 def createTpkgRoot(name):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
24 domimpl = xml.dom.minidom.getDOMImplementation()
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
25 doc = domimpl.createDocument(TREEPKG_NAMESPACE_URI, name, None)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
26 root = doc.documentElement
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
27 return (doc, root)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
28
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
29 def getTextFromNode(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
30 if not node:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
31 return None
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
32 textnode = node.firstChild
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
33 if not textnode or textnode.nodeType != node.TEXT_NODE:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
34 return None
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
35 return textnode.data
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
36
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
37 def getChild(node, name, required=False):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
38 if not node:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
39 if required:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
40 raise TreepkgInfoException("")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
41 return None
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
42 childs = node.getElementsByTagName(name)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
43 if not childs:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
44 if required:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
45 raise TreepkgInfoException("")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
46 return None
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
47 return childs[0]
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
48
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
49 class TreepkgInfoException(Exception):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
50 """ Exception class for TreepkgInfo """
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
51
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents: 387
diff changeset
52 class TreepkgInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
53
399
04310ad0063e let the user specify num revisions that should be shown in the info
Bjoern Ricks <bricks@intevation.de>
parents: 398
diff changeset
54 def __init__(self, config, numnewestrev=-1):
04310ad0063e let the user specify num revisions that should be shown in the info
Bjoern Ricks <bricks@intevation.de>
parents: 398
diff changeset
55 self.numnewestrev = numnewestrev
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
56 group = get_packager_group(config)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
57 self.tpkgroot = TreepkgRootInfo(group.name, group.treepkg_dir,
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
58 group.tracks_dir)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
59 tracks = group.get_package_tracks()
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
60
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
61 for track in tracks:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
62 trackinfo = TreepkgTrackInfo(track.name)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
63 self.tpkgroot.add_track(trackinfo)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
64 self.add_revisions(track, trackinfo)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
65
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
66 def toxml(self):
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
67 return self.tpkgroot.toxml()
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
68
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
69 @staticmethod
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
70 def fromxml(xml):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
71 doc = xml.dom.minidom.parseString(xml)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
72 root = doc.documentElement
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
73 if not root.tagName == "treepkg":
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
74 raise TreepkgInfoException("XML is not valid for treepkfinfo")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
75 return TreepkgRootInfo.fromxml(root) # FIXME
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
76
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
77 def add_revisions(self, track, trackinfo):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
78 revisions = track.get_revisions()
400
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
79 revisions = sorted(revisions, key=lambda r: r.status.start,
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
80 reverse=True)
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
81 if self.numnewestrev > 0:
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
82 revisions = revisions[:self.numnewestrev]
399
04310ad0063e let the user specify num revisions that should be shown in the info
Bjoern Ricks <bricks@intevation.de>
parents: 398
diff changeset
83
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
84 arch = None
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
85
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
86 for rev in revisions:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
87 revision = rev.revision
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
88 rules_revision = rev.rules_revision
398
09b7b7bf0b04 fixed status line for revision
Bjoern Ricks <bricks@intevation.de>
parents: 397
diff changeset
89 status = rev.status.status.description # extend status
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
90
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
91 sources = rev.list_source_files()
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
92 binaries = rev.list_binary_files()
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
93
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
94 revinfo = TreepkgTrackRevisionInfo(revision, rules_revision,
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
95 status)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
96 logs = rev.get_log_files()
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
97 for (title, filename) in logs:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
98 loginfo = TreepkgLogInfo(title, filename)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
99 revinfo.add_log(loginfo)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
100 for source in sources:
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
101 self.add_package(revinfo, source, "source")
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
102 for binary in binaries:
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
103 binpackage = BinaryPackage(binary)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
104 arch = binpackage.get_architecture()
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
105 self.add_package(revinfo, binary, "binary", arch)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
106
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
107 trackinfo.add_revision(revinfo)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
108
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
109 def add_package(self, revision, file, type, arch=None):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
110 name = os.path.basename(file)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
111 checksum = md5sum(file)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
112 checksuminfo = TreepkgChecksumInfo(checksum, "md5")
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
113 pkginfo = TreepkgPackageInfo(name, file, type, arch)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
114 pkginfo.add_checksum(checksuminfo)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
115 revision.add_package(pkginfo)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
116
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
117 class TreepkgRootInfo:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
118
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
119 def __init__(self, name, treepkgpath=None, trackspath=None, version=None):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
120 self.name = name
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
121 self.treepkgpath = treepkgpath
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
122 self.trackspath = trackspath
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
123 self.version = version
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
124 self.tracks = []
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
125
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
126 def add_track(self, track):
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
127 self.tracks.append(track)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
128
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
129 def toxml(self):
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
130 (doc, root) = createTpkgRoot("info")
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
131 # add <name>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
132 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
133 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
134 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
135 root.appendChild(nameele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
136 # add <treepkgpath>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
137 if self.treepkgpath:
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
138 treepkgpathele = createTpkgElement(doc, "treepkgpath")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
139 text = doc.createTextNode(self.treepkgpath)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
140 treepkgpathele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
141 root.appendChild(treepkgpathele)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
142 # add <trackspath>
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
143 if self.trackspath:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
144 trackspathele = createTpkgElement(doc, "trackspath")
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
145 text = doc.createTextNode(self.trackspath)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
146 trackspathele.appendChild(text)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
147 root.appendChild(trackspathele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
148 # add <version>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
149 if self.version:
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
150 versionele = createTpkgElement(doc, "version")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
151 text = doc.createTextNode(self.version)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
152 versionele.appendChild(text)
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
153 root.appendChild(versionele)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
154 if len(self.tracks) > 0:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
155 tracksele = createTpkgElement(doc, "tracks")
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
156 for track in self.tracks:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
157 tracksele.appendChild(track.toxml())
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
158 root.appendChild(tracksele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
159 return root
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
160
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
161 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
162 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
163 version = node.getAttribute("version")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
164 infoele = getChild(node, "info", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
165 nameele = getChild(infoele, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
166 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
167 treepkgpathele = getChild(infoele, "treepkgpath")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
168 treepkgpath = getTextFromNode(treepkgpathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
169 trackspathele = getChild(infoele, "trackspath")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
170 trackspath = getTextFromNode(trackspathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
171 trackseles = node.getElementsByTagName("tracks")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
172 tracks = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
173 for trackele in trackseles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
174 tracks.append(TreepkgTrackInfo.fromxml(trackele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
175 trackinfo = TreepkgRootInfo(name, treepkgpath, trackspath, version)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
176 trackinfo.tracks = tracks
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
177 return trackinfo
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
178
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
179 class TreepkgTrackInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
180
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
181 def __init__(self, name, os=None):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
182 self.name = name
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
183 self.os = os
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
184 self.revisions = []
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
185
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
186 def add_revision(self, revision):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
187 self.revisions.append(revision)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
188
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
189 def toxml(self):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
190 (doc, root) = createTpkgRoot("track")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
191 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
192 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
193 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
194 root.appendChild(nameele)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
195 for rev in self.revisions:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
196 root.appendChild(rev.toxml())
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
197 if not self.os is None:
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
198 osele = createTpkgElement(doc, "os")
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
199 text = doc.createTextNode(self.os)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
200 osele.appendChild(text)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
201 root.appendChild(osele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
202 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
203
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
204 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
205 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
206 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
207 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
208 osele = getChild(node, "os")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
209 os = getTextFromNode(osele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
210 treepkgtrackinfo = TreepkgTrackInfo(name, os)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
211 treepkgtrackinfo.revisions = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
212 revisioneles = node.getElementsByTagName("revision")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
213 for revele in revisioneles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
214 treepkgrevision = TreepkgTrackRevisionInfo.fromxml(revele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
215 treepkgtrackinfo.revisions.append(treepkgrevision)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
216 return treepkgtrackinfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
217
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
218
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
219 class TreepkgTrackRevisionInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
220
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
221 def __init__(self, number, rules, status):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
222 self.number = number
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
223 self.rules = rules
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
224 self.status = status
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
225 self.packages = []
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
226 self.logs = []
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
227
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
228 def add_package(self, package):
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
229 self.packages.append(package)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
230
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
231 def add_log(self, log):
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
232 self.logs.append(log)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
233
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
234 def toxml(self):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
235 (doc, root) = createTpkgRoot("revision")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
236 # add <number>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
237 numberele = createTpkgElement(doc, "number")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
238 text = doc.createTextNode(self.number)
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
239 numberele.appendChild(text)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
240 root.appendChild(numberele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
241 # add <rules>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
242 rulesele = createTpkgElement(doc, "rules")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
243 text = doc.createTextNode(self.rules)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
244 rulesele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
245 root.appendChild(rulesele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
246 # add <status><message></message></status>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
247 statusele = createTpkgElement(doc, "status")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
248 messageele = createTpkgElement(doc, "message")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
249 text = doc.createTextNode(self.status)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
250 messageele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
251 statusele.appendChild(messageele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
252 root.appendChild(statusele)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
253 # add <packages>
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
254 packagesele = createTpkgElement(doc, "packages")
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
255 for package in self.packages:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
256 packagesele.appendChild(package.toxml())
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
257 root.appendChild(packagesele)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
258 # add <logs>
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
259 logsele = createTpkgElement(doc, "logs")
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
260 for log in self.logs:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
261 logsele.appendChild(log.toxml())
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
262 root.appendChild(logsele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
263 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
264
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
265 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
266 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
267 numberele = getChild(node, "number", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
268 number = getTextFromNode(numberele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
269 rulesele = getChild(node, "rules", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
270 rules = getTextFromNode(rulesele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
271 statusele = getChild(node, "status", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
272 messageele = getChild(statusele, "message")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
273 message = getTextFromNode(messageele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
274 treepkgrevisioninfo = TreepkgTrackRevisionInfo(number, rules, message)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
275 treepkgrevisioninfo.packages = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
276 treepkgrevisioninfo.logs = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
277 packageeles = getChild(node, "packages")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
278 for packageele in packageeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
279 treepkgrevisioninfo.packages.append(
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
280 TreepkgPackageInfo.fromxml(packageele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
281 logeles = getChild(node, "logs")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
282 for logele in logeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
283 treepkgrevisioninfo.logs.append(
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
284 TreepkgLogInfo.fromxml(logele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
285 return treepkgrevisioninfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
286
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
287 class TreepkgLogInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
288
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
289 def __init__(self, name, path):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
290 self.name = name
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
291 self.path = path
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
292
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents: 387
diff changeset
293 def toxml(self):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
294 (doc, root) = createTpkgRoot("log")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
295 # add <name>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
296 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
297 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
298 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
299 root.appendChild(nameele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
300 # add path
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
301 pathele = createTpkgElement(doc, "path")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
302 text = doc.createTextNode(self.path)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
303 pathele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
304 root.appendChild(pathele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
305 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
306
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
307 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
308 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
309 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
310 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
311 pathele = getChild(node, "path", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
312 path = getTextFromNode(pathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
313 return TreepkgLogInfo(name, path)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
314
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
315 class TreepkgPackageInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
316
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
317 def __init__(self, name, path, type, arch):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
318 self.name = name
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
319 self.path = path
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
320 self.type = type
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
321 self.arch = arch
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
322 self.checksums = []
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
323
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
324 def toxml(self):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
325 (doc, root) = createTpkgRoot("package")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
326 # add <name>
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
327 nameele = createTpkgElement(doc, "name")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
328 text = doc.createTextNode(self.name)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
329 nameele.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
330 root.appendChild(nameele)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
331 # add <path>
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
332 pathele = createTpkgElement(doc, "path")
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
333 text = doc.createTextNode(self.path)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
334 pathele.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
335 root.appendChild(pathele)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
336 # add <checksum>
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
337 for checksum in self.checksums:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
338 root.appendChild(checksum.toxml())
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
339 # add <type>
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
340 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "type", self.type)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
341 if not self.arch is None:
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
342 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "arch", self.arch)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
343 return root
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
344
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
345 def add_checksum(self, checksum):
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
346 self.checksums.append(checksum)
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
347
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
348 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
349 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
350 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
351 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
352 pathele = getChild(node, "path", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
353 path = getTextFromNode(pathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
354 ptype = node.getAttribute("type")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
355 arch = node.getAttribute("arch")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
356 packageinfo = TreepkgPackageInfo(name, path, ptype, arch)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
357 checksumeles = node.getElementsByTagName("checksum")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
358 for checksumele in checksumeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
359 packageinfo.checksums.append(TreepkgChecksumInfo.fromxml(checksumele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
360 return packageinfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
361
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
362 class TreepkgChecksumInfo:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
363
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
364 def __init__(self, checksum, type="md5"):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
365 self.checksum = checksum
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
366 self.type = type
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
367
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
368 def toxml(self):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
369 (doc, root) = createTpkgRoot("checksum")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
370 text = doc.createTextNode(self.checksum)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
371 root.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
372 # add attribute type
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
373 if type:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
374 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "type", self.type)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
375 return root
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
376
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
377 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
378 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
379 checksumele = getChild(node, "checksum", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
380 checksum = getTextFromNode(checksumele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
381 ctype = node.getAttribute("type")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
382 return TreepkgChecksumInfo(checksum, ctype)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)