1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 import codecs
31 import xml.dom.minidom
32 import datetime
33 from os import popen
34 import traceback
35
36
37
38
40
41
42
43
44
48
49
50
51
53 self.__logger._print(self.__name, args)
54
55
56
57
59
60
61
63 self.__step = 1
64 self.__doc = xml.dom.minidom.Document()
65 self.__lognode = self.__doc.createElementNS("", "__log")
66 self.__header = self.__doc.createElementNS("", "__header")
67 self.__footer = self.__doc.createElementNS("", "__footer")
68 self.__summary = self.__doc.createElementNS("", "__summary")
69 self.__lognode.appendChild(self.__header)
70 self.__lognode.appendChild(self.__summary)
71 self.__lognode.appendChild(self.__footer)
72 self.__lognode.setAttributeNS("", "date", "%s" % datetime.datetime.now().ctime())
73 self.__footer.setAttributeNS("", "title", "")
74 self.__footer.setAttributeNS("", "subtitle", "")
75 self.__doc.appendChild(self.__lognode)
76 self.__build = self.__doc.createElementNS("", "build")
77 self.__lognode.appendChild(self.__build)
78 self.__current_node = self.__build
79 self.__stack = []
80 self.__verbose = True
81
82
83
84
86 self.__lognode.setAttributeNS("", "interface", url)
87
88
89
90
93
94
95
96
98 self.__header.setAttributeNS("", "title", title)
99
100
101
102
104 self.__header.setAttributeNS("", "subtitle", title)
105
106
107
108
110 self.__summary.setAttributeNS("", "title", title)
111
112
113
114
115
117 e = self.__doc.createElementNS("", "__elmt")
118 e.setAttributeNS("", "tag", tag)
119 e.setAttributeNS("", "val", value)
120 self.__summary.appendChild(e)
121
122
123
124
125
126 - def OpenMainContent(self, title=""):
127 self.__stack.append(self.__current_node)
128 n = self.__doc.createElementNS("", "task")
129 n.setAttributeNS("", "name", title)
130 n.setAttributeNS("", "type", "maincontent")
131 n.setAttributeNS("", "time", datetime.datetime.now().ctime())
132 self.__current_node.appendChild(n)
133 self.__current_node = n
134 if self.__verbose:
135 print ("---------------------------------------------------------------------")
136 print (" %s" % title)
137 print ("---------------------------------------------------------------------")
138
139
140
141
142
144 if self.__current_node.nodeName != "task" and not (self.__current_node.attributes.has_key('type') and self.__current_node.attributes['type']=="maincontent"):
145 raise Exception("not closing a 'maincontent' typed node")
146 self.__current_node = self.__stack.pop()
147
148
149
150
151
153 self.__stack.append(self.__current_node)
154 n = self.__doc.createElementNS("", "task")
155 n.setAttributeNS("", "name", title)
156 n.setAttributeNS("", "type", "event")
157 n.setAttributeNS("", "time", datetime.datetime.now().ctime())
158 self.__current_node.appendChild(n)
159 self.__current_node = n
160 if self.__verbose:
161 print ("---------------------------------------------------------------------")
162 print (" + %s" % title)
163
165 n = self.__doc.createElementNS("", "__customoutputer")
166 n.setAttributeNS("", "type", type)
167 n.setAttributeNS("", "module", classname)
168 if config != None:
169 n.appendChild(config)
170 self.__lognode.appendChild(n)
171
172
173
174
176 if self.__current_node.nodeName != "task" and (self.__current_node.attributes.has_key('type') and self.__current_node.attributes['type']=="event"):
177 raise Exception("not closing a 'event' typed node")
178 self.__current_node = self.__stack.pop()
179
180
181
182
188
189
190
191
192
193 - def _print(self, kind, *args):
194 output = u"".join(map(lambda x: u"%s" % x, list(*args)))
195 nodetype = kind.lower()
196 msgtype = ""
197 if nodetype != "print" and nodetype != "info" and nodetype != "debug":
198 msgtype = "%s:" % nodetype.upper()
199 if self.__verbose:
200 print "%s %s" % (msgtype, output.encode('utf-8'))
201
202
203 n = self.__doc.createElementNS("", "message")
204 n.setAttributeNS("", "priority", nodetype)
205
206 n.appendChild(self.__doc.createCDATASection(output))
207 self.__current_node.appendChild(n)
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
228
231
232 - def Die(self, title, subtitle, exception):
235
236
237
238
240 file_object = open(filename, "w")
241 file_object.write(codecs.BOM_UTF8)
242 file_object.write(self.__doc.toprettyxml(encoding = "utf-8"))
243 file_object.close()
244
245
246
247
248
250 return self.__doc.toprettyxml(encoding="utf-8")
251