annotate treepkg/info/status.py @ 411:8dd64f8bf572 treepkg-status

fixed some small issues remember: run pychecker BEFORE the commit
author Bjoern Ricks <bricks@intevation.de>
date Thu, 22 Jul 2010 11:09:52 +0000
parents 5e8546444a8e
children 58ecf7c0ecba
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)
410
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
57 treepkgrootinfo = TreepkgRootInfo(group.name, group.treepkg_dir,
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
58 group.tracks_dir)
411
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
59 version = "1.0"
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
60 self.tpkgroot = TreepkgRoot(version, treepkgrootinfo)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
61 tracks = group.get_package_tracks()
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
62
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
63 for track in tracks:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
64 trackinfo = TreepkgTrackInfo(track.name)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
65 self.tpkgroot.add_track(trackinfo)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
66 self.add_revisions(track, trackinfo)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
67
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
68 def toxml(self):
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
69 return self.tpkgroot.toxml()
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
70
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
71 @staticmethod
409
ecc671a84a73 fixed small bugs
Bjoern Ricks <bricks@intevation.de>
parents: 407
diff changeset
72 def fromxml(xmlstr):
ecc671a84a73 fixed small bugs
Bjoern Ricks <bricks@intevation.de>
parents: 407
diff changeset
73 doc = xml.dom.minidom.parseString(xmlstr)
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
74 root = doc.documentElement
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
75 if not root.tagName == "treepkg":
409
ecc671a84a73 fixed small bugs
Bjoern Ricks <bricks@intevation.de>
parents: 407
diff changeset
76 print xmlstr
ecc671a84a73 fixed small bugs
Bjoern Ricks <bricks@intevation.de>
parents: 407
diff changeset
77 raise TreepkgInfoException("XML is not valid for treepkginfo")
410
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
78 return TreepkgRoot.fromxml(root)
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
79
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
80 def add_revisions(self, track, trackinfo):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
81 revisions = track.get_revisions()
400
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
82 revisions = sorted(revisions, key=lambda r: r.status.start,
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
83 reverse=True)
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
84 if self.numnewestrev > 0:
48aaffdc1a4f missed in last commit
Bjoern Ricks <bricks@intevation.de>
parents: 399
diff changeset
85 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
86
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
87 arch = None
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
88
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
89 for rev in revisions:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
90 revision = rev.revision
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
91 rules_revision = rev.rules_revision
398
09b7b7bf0b04 fixed status line for revision
Bjoern Ricks <bricks@intevation.de>
parents: 397
diff changeset
92 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
93
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
94 sources = rev.list_source_files()
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
95 binaries = rev.list_binary_files()
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
96
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
97 revinfo = TreepkgTrackRevisionInfo(revision, rules_revision,
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
98 status)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
99 logs = rev.get_log_files()
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
100 for (title, filename) in logs:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
101 loginfo = TreepkgLogInfo(title, filename)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
102 revinfo.add_log(loginfo)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
103 for source in sources:
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
104 self.add_package(revinfo, source, "source")
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
105 for binary in binaries:
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
106 binpackage = BinaryPackage(binary)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
107 arch = binpackage.get_architecture()
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
108 self.add_package(revinfo, binary, "binary", arch)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
109
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
110 trackinfo.add_revision(revinfo)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
111
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
112 def add_package(self, revision, file, type, arch=None):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
113 name = os.path.basename(file)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
114 checksum = md5sum(file)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
115 checksuminfo = TreepkgChecksumInfo(checksum, "md5")
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
116 pkginfo = TreepkgPackageInfo(name, file, type, arch)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
117 pkginfo.add_checksum(checksuminfo)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
118 revision.add_package(pkginfo)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
119
410
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
120 class TreepkgRoot:
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
121
411
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
122 def __init__(self, version, info):
410
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
123 self.version = version
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
124 self.info = info
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
125 self.tracks = []
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
126
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
127 def add_track(self, track):
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
128 self.tracks.append(track)
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
129
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
130 def toxml(self):
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
131 (doc, root) = createTpkgRoot("treepkg")
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
132 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "version", self.version)
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
133 if len(self.tracks) > 0:
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
134 tracksele = createTpkgElement(doc, "tracks")
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
135 for track in self.tracks:
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
136 tracksele.appendChild(track.toxml())
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
137 root.appendChild(tracksele)
411
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
138 root.appendChild(self.info.toxml())
410
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
139 return root
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
140
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
141 @staticmethod
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
142 def fromxml(node):
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
143 version = node.getAttribute("version")
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
144 trackseles = node.getElementsByTagName("tracks")
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
145 infoele = getChild(node, "info")
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
146 treepkgrootinfo = TreepkgRootInfo.fromxml(infoele)
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
147 treepkgroot = TreepkgRoot(version, treepkgrootinfo)
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
148 tracks = []
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
149 for trackele in trackseles:
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
150 tracks.append(TreepkgTrackInfo.fromxml(trackele))
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
151 treepkgroot.tracks = tracks
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
152 return treepkgroot
5e8546444a8e added a new root element which is called TreepkgRoot for Treepkg Info classes
Bjoern Ricks <bricks@intevation.de>
parents: 409
diff changeset
153
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
154 class TreepkgRootInfo:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
155
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
156 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
157 self.name = name
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
158 self.treepkgpath = treepkgpath
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
159 self.trackspath = trackspath
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
160 self.version = version
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
161
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
162 def toxml(self):
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
163 (doc, root) = createTpkgRoot("info")
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
164 # add <name>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
165 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
166 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
167 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
168 root.appendChild(nameele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
169 # add <treepkgpath>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
170 if self.treepkgpath:
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
171 treepkgpathele = createTpkgElement(doc, "treepkgpath")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
172 text = doc.createTextNode(self.treepkgpath)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
173 treepkgpathele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
174 root.appendChild(treepkgpathele)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
175 # add <trackspath>
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
176 if self.trackspath:
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
177 trackspathele = createTpkgElement(doc, "trackspath")
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
178 text = doc.createTextNode(self.trackspath)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
179 trackspathele.appendChild(text)
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
180 root.appendChild(trackspathele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
181 # add <version>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
182 if self.version:
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
183 versionele = createTpkgElement(doc, "version")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
184 text = doc.createTextNode(self.version)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
185 versionele.appendChild(text)
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
186 root.appendChild(versionele)
411
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
187 return root
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
188
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
189 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
190 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
191 version = node.getAttribute("version")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
192 infoele = getChild(node, "info", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
193 nameele = getChild(infoele, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
194 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
195 treepkgpathele = getChild(infoele, "treepkgpath")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
196 treepkgpath = getTextFromNode(treepkgpathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
197 trackspathele = getChild(infoele, "trackspath")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
198 trackspath = getTextFromNode(trackspathele)
411
8dd64f8bf572 fixed some small issues
Bjoern Ricks <bricks@intevation.de>
parents: 410
diff changeset
199 return TreepkgRootInfo(name, treepkgpath, trackspath, version)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
200
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
201 class TreepkgTrackInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
202
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
203 def __init__(self, name, os=None):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
204 self.name = name
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
205 self.os = os
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
206 self.revisions = []
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
207
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
208 def add_revision(self, revision):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
209 self.revisions.append(revision)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
210
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
211 def toxml(self):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
212 (doc, root) = createTpkgRoot("track")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
213 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
214 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
215 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
216 root.appendChild(nameele)
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
217 for rev in self.revisions:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
218 root.appendChild(rev.toxml())
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
219 if not self.os is None:
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
220 osele = createTpkgElement(doc, "os")
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
221 text = doc.createTextNode(self.os)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
222 osele.appendChild(text)
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
223 root.appendChild(osele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
224 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
225
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
226 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
227 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
228 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
229 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
230 osele = getChild(node, "os")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
231 os = getTextFromNode(osele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
232 treepkgtrackinfo = TreepkgTrackInfo(name, os)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
233 treepkgtrackinfo.revisions = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
234 revisioneles = node.getElementsByTagName("revision")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
235 for revele in revisioneles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
236 treepkgrevision = TreepkgTrackRevisionInfo.fromxml(revele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
237 treepkgtrackinfo.revisions.append(treepkgrevision)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
238 return treepkgtrackinfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
239
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
240
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
241 class TreepkgTrackRevisionInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
242
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
243 def __init__(self, number, rules, status):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
244 self.number = number
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
245 self.rules = rules
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
246 self.status = status
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
247 self.packages = []
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
248 self.logs = []
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
249
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
250 def add_package(self, package):
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
251 self.packages.append(package)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
252
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
253 def add_log(self, log):
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
254 self.logs.append(log)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
255
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
256 def toxml(self):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
257 (doc, root) = createTpkgRoot("revision")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
258 # add <number>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
259 numberele = createTpkgElement(doc, "number")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
260 text = doc.createTextNode(self.number)
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
261 numberele.appendChild(text)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
262 root.appendChild(numberele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
263 # add <rules>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
264 rulesele = createTpkgElement(doc, "rules")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
265 text = doc.createTextNode(self.rules)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
266 rulesele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
267 root.appendChild(rulesele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
268 # add <status><message></message></status>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
269 statusele = createTpkgElement(doc, "status")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
270 messageele = createTpkgElement(doc, "message")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
271 text = doc.createTextNode(self.status)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
272 messageele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
273 statusele.appendChild(messageele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
274 root.appendChild(statusele)
402
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
275 # add <packages>
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
276 packagesele = createTpkgElement(doc, "packages")
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
277 for package in self.packages:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
278 packagesele.appendChild(package.toxml())
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
279 root.appendChild(packagesele)
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
280 # add <logs>
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
281 logsele = createTpkgElement(doc, "logs")
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
282 for log in self.logs:
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
283 logsele.appendChild(log.toxml())
01c059298906 moved packages and logs to revision tag
Bjoern Ricks <bricks@intevation.de>
parents: 400
diff changeset
284 root.appendChild(logsele)
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
285 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
286
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
287 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
288 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
289 numberele = getChild(node, "number", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
290 number = getTextFromNode(numberele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
291 rulesele = getChild(node, "rules", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
292 rules = getTextFromNode(rulesele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
293 statusele = getChild(node, "status", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
294 messageele = getChild(statusele, "message")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
295 message = getTextFromNode(messageele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
296 treepkgrevisioninfo = TreepkgTrackRevisionInfo(number, rules, message)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
297 treepkgrevisioninfo.packages = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
298 treepkgrevisioninfo.logs = []
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
299 packageeles = getChild(node, "packages")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
300 for packageele in packageeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
301 treepkgrevisioninfo.packages.append(
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
302 TreepkgPackageInfo.fromxml(packageele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
303 logeles = getChild(node, "logs")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
304 for logele in logeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
305 treepkgrevisioninfo.logs.append(
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
306 TreepkgLogInfo.fromxml(logele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
307 return treepkgrevisioninfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
308
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
309 class TreepkgLogInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
310
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
311 def __init__(self, name, path):
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
312 self.name = name
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
313 self.path = path
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
314
388
1af04bfbb1d0 moved test file to test main dir
Bjoern Ricks <bricks@intevation.de>
parents: 387
diff changeset
315 def toxml(self):
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
316 (doc, root) = createTpkgRoot("log")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
317 # add <name>
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
318 nameele = createTpkgElement(doc, "name")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
319 text = doc.createTextNode(self.name)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
320 nameele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
321 root.appendChild(nameele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
322 # add path
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
323 pathele = createTpkgElement(doc, "path")
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
324 text = doc.createTextNode(self.path)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
325 pathele.appendChild(text)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
326 root.appendChild(pathele)
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
327 return root
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
328
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
329 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
330 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
331 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
332 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
333 pathele = getChild(node, "path", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
334 path = getTextFromNode(pathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
335 return TreepkgLogInfo(name, path)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
336
392
e2afbd3c2bf1 write first info about tracks
Bjoern Ricks <bricks@intevation.de>
parents: 388
diff changeset
337 class TreepkgPackageInfo:
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
338
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
339 def __init__(self, name, path, type, arch):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
340 self.name = name
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
341 self.path = path
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
342 self.type = type
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
343 self.arch = arch
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
344 self.checksums = []
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
345
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
346 def toxml(self):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
347 (doc, root) = createTpkgRoot("package")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
348 # add <name>
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
349 nameele = createTpkgElement(doc, "name")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
350 text = doc.createTextNode(self.name)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
351 nameele.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
352 root.appendChild(nameele)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
353 # add <path>
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
354 pathele = createTpkgElement(doc, "path")
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
355 text = doc.createTextNode(self.path)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
356 pathele.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
357 root.appendChild(pathele)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
358 # add <checksum>
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
359 for checksum in self.checksums:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
360 root.appendChild(checksum.toxml())
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
361 # add <type>
405
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
362 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
363 if not self.arch is None:
eaf04fc0f615 moved arch info to each package info
Bjoern Ricks <bricks@intevation.de>
parents: 402
diff changeset
364 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "arch", self.arch)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
365 return root
386
ffa86312ee81 added classed for treepkg status xml generation
Bjoern Ricks <bricks@intevation.de>
parents:
diff changeset
366
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
367 def add_checksum(self, checksum):
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
368 self.checksums.append(checksum)
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
369
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
370 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
371 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
372 nameele = getChild(node, "name", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
373 name = getTextFromNode(nameele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
374 pathele = getChild(node, "path", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
375 path = getTextFromNode(pathele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
376 ptype = node.getAttribute("type")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
377 arch = node.getAttribute("arch")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
378 packageinfo = TreepkgPackageInfo(name, path, ptype, arch)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
379 checksumeles = node.getElementsByTagName("checksum")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
380 for checksumele in checksumeles:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
381 packageinfo.checksums.append(TreepkgChecksumInfo.fromxml(checksumele))
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
382 return packageinfo
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
383
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
384 class TreepkgChecksumInfo:
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
385
397
a7bf4464bd60 fixed some typos
Bjoern Ricks <bricks@intevation.de>
parents: 396
diff changeset
386 def __init__(self, checksum, type="md5"):
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
387 self.checksum = checksum
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
388 self.type = type
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
389
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
390 def toxml(self):
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
391 (doc, root) = createTpkgRoot("checksum")
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
392 text = doc.createTextNode(self.checksum)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
393 root.appendChild(text)
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
394 # add attribute type
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
395 if type:
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
396 root.setAttributeNS(TREEPKG_NAMESPACE_URI, "type", self.type)
395
0ba451c4a856 implemented nearly all info
Bjoern Ricks <bricks@intevation.de>
parents: 392
diff changeset
397 return root
407
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
398
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
399 @staticmethod
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
400 def fromxml(node):
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
401 checksumele = getChild(node, "checksum", True)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
402 checksum = getTextFromNode(checksumele)
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
403 ctype = node.getAttribute("type")
fb473f67345b implemented parsing from xml string
Bjoern Ricks <bricks@intevation.de>
parents: 406
diff changeset
404 return TreepkgChecksumInfo(checksum, ctype)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)