1
2 -def export_to_html(results,templatefilename,sipiData,maxValueForVias,input_design_picture_filename):
3 import os
4 import string
5 from string import Template
6 import base64
7 import empro.toolkit.analysis
8
9 notes = sipiData.newSimulationData().notes
10
11 if not notes:
12 notes = "-------------Notes Empty--------------"
13
14 path = sipiData.simulationPath+"/project.log"
15 if os.path.exists(path):
16 log = open(path).readlines()
17 log = "<br>".join(log)
18 else:
19 log = "Log file not found, please check for simulation errors"
20
21 nfs = len(results.failedSinks)
22 nfv = len(results.failedVrms)
23
24 with open(empro.core.ApplicationInfo.rootPath() +"data/sipi_reporting/pictures/Valid.ico",'rb') as f:
25 validString = base64.b64encode(f.read())
26 with open(empro.core.ApplicationInfo.rootPath() +"data/sipi_reporting/pictures/Invalid.ico",'rb') as f:
27 invalidString = base64.b64encode(f.read())
28 with open(empro.core.ApplicationInfo.rootPath() +"data/sipi_reporting/pictures/Sipi.png",'rb') as f:
29 sipiString = base64.b64encode(f.read())
30
31 valid ="<img src= 'data:image/png;base64,%s' width=12 height = 12>"%validString
32 invalid ="<img src= 'data:image/png;base64,%s' width=12 height = 12>"%invalidString
33
34 sinksrow1 = ["Name", "Source Current", "VRM Voltage", "Input Voltage","Resistance", "Tolerance", "Margin" ,"Pass/Fail"]
35 row1_1 = "".join([" ".join("<th>%s</th>" % (x) for x in sinksrow1[:-1])]+[" ".join("<th colspan =2 >%s</th>" %(x) for x in sinksrow1[-1:])])
36 row1_1 = "<tr bgcolor='#D0D0D0'>"+row1_1+"</tr>"
37 sinksrows=[]
38 for sink in results.sinks:
39 sinksrow = [sink.name, str(sink.sourceCurrent)+" A", str(sink.vrmVoltage)+" V",str(sink.inputVoltage)+" V",str(sink.resistance)+" Ohm", sink.tolerance, str(sink.margin)+" V",sink.result]
40 if sink.margin < 0.0 :
41 x = [invalid]
42 else:
43 x = [valid]
44 sinksrow = sinksrow + x
45 if sinksrow[-1] == invalid:
46 sinksrow = "".join("<td>%s</td>"%x for x in sinksrow)
47 sinksrows.insert(0,sinksrow)
48 else:
49 sinksrow = "".join("<td>%s</td>"%x for x in sinksrow)
50 sinksrows.append(sinksrow)
51 sinksrows = "".join("<tr bgcolor='#E8E8E8'>%s</tr>"%x for x in sinksrows)
52 srows = sinksrows
53
54 vrmsrow1 = ["Name", "Source Voltage", "Output Voltage", "Output Current", "Tolerance", "Margin", "Pass/Fail"]
55 row2_1 = "".join([" ".join("<th>%s</th>" % (x) for x in vrmsrow1[:-1])]+[" ".join("<th colspan =2 >%s</th>" %(x) for x in vrmsrow1[-1:])])
56 row2_1 = "<tr bgcolor='#D0D0D0'>"+row2_1+"</tr>"
57 vrmsrows = []
58 for vrm in results.vrms:
59 vrmsrow = [vrm.name, str(vrm.sourceVoltage)+" V", str(vrm.outputVoltage)+" V" ,str(vrm.outputCurrent)+" A", vrm.tolerance, str(vrm.margin)+" V", vrm.result]
60 if vrm.margin < 0.0 :
61 x = [invalid]
62 else:
63 x = [valid]
64 vrmsrow = vrmsrow + x
65 if vrmsrow[-1] == invalid:
66 vrmsrow = "".join("<td>%s</td>"%x for x in vrmsrow)
67 vrmsrows.insert(0,vrmsrow)
68 else:
69 vrmsrow = "".join("<td>%s</td>"%x for x in vrmsrow)
70 vrmsrows.append(vrmsrow)
71 vrmsrows = "".join("<tr bgcolor='#E8E8E8' >%s</tr>"%x for x in vrmsrows)
72 vrows = vrmsrows
73
74 viasrow1 = ["Id", "Current"]
75 row3_1 = "".join(["".join("<th>%s</th>" % (x) for x in viasrow1[:-1])]+[" ".join("<th colspan =2 >%s</th>" %(x) for x in viasrow1[-1:])])
76 row3_1 = "<tr bgcolor='#D0D0D0'>"+row3_1+"</tr>"
77 viasrows = []
78 nvv = 0
79 for key, via in results.viaCurrents.iteritems():
80 viasrow = [str(key), str(via[0])+" A"]
81 if float(via[0])<maxValueForVias:
82 x = [valid]
83 else:
84 nvv += 1
85 x = [invalid]
86 viasrow = viasrow + x
87 if viasrow[-1] == invalid:
88 viasrow = "".join("<td>%s</td>"%x for x in viasrow)
89 viasrows.insert(0,viasrow)
90 else:
91 viasrow = "".join("<td>%s</td>"%x for x in viasrow)
92 viasrows.append(viasrow)
93 viasrows = "".join("<tr bgcolor='#E8E8E8'>%s</tr>"%x for x in viasrows)
94 virows = viasrows
95
96 with open(input_design_picture_filename, "rb") as image_file:
97 design_picture = base64.b64encode(image_file.read())
98
99 try:
100 templateFile = open(templatefilename)
101 template = Template(templateFile.read())
102
103 sub = dict(sinkstable = row1_1+srows,vrmstable = row2_1+vrows,viastable = row3_1+virows,nvv =str(nvv),nfv= str(nfv),nfs =str(nfs), depic = "'data:image/png;base64,%s'"%design_picture, sipi = "'data:image/png;base64,%s'"%sipiString , notes = notes, simulation_log = log)
104
105 ReportText = template.safe_substitute(sub)
106 except:
107 return "<html>Cannot Generate HTML</html>"
108 return ReportText
109
110
111 -def export_to_word(results,templatefilename,outputfilename,input_design_picture_filename,sipiData, maxValueForVias,tempdirectory):
112 import os
113 import sys
114 import zipfile
115 import shutil
116 import string
117 from string import Template
118 if outputfilename+".docx":
119
120 try:
121 os.remove(outputfilename+".docx")
122 except OSError:
123 pass
124
125 notes = sipiData.newSimulationData().notes
126 if not notes:
127 notes = "-------------Notes Empty--------------"
128 path = sipiData.simulationPath+"/project.log"
129 if os.path.exists(path):
130 log = open(path).readlines()
131 log ="<w:br/>".join(log)
132
133 else:
134 log = " Log file not found, please check for simulation errors"
135
136 nfs = len(results.failedSinks)
137 nfv = len(results.failedVrms)
138 valid = "<w:p w:rsidR='00475B81' w:rsidRDefault='00425212' w:rsidP='00425212'><w:r w:rsidRPr='00425212'><w:rPr><w:highlight w:val='green'/></w:rPr><w:t>Pass</w:t></w:r></w:p>"
139 invalid = "<w:p w:rsidR='00425212' w:rsidRPr='00425212' w:rsidRDefault='00425212' w:rsidP='00425212'><w:r w:rsidRPr='00425212'><w:rPr><w:highlight w:val='red'/></w:rPr><w:t>Fail</w:t></w:r></w:p>"
140
141 sinksrow1 = ["Name", "Source Current", "VRM Voltage", "Input Voltage", "Resistance", "Tolerance", "Margin" ,"Pass/Fail"]
142 row1_1 = "<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>"+" ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='000D0EAB' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r w:rsidRPr='000D0EAB'><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" % (str(x)) for x in sinksrow1)+"</w:tr>"
143 sinksrows=[]
144 for sink in results.sinks:
145 sinksrow = [sink.name, str(sink.sourceCurrent)+" A", str(sink.vrmVoltage)+" V",str(sink.inputVoltage)+" V", str(sink.resistance)+" Ohm", sink.tolerance, str(sink.margin)+" V"]
146 if sink.margin < 0.0 :
147 x = [invalid]
148 else:
149 x = [valid]
150 sinksrow = sinksrow + x
151
152 if sinksrow[-1] == invalid:
153 sinksrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in sinksrow[:])
154 sinksrows.insert(0,sinksrow)
155 else:
156 sinksrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in sinksrow[:])
157 sinksrows.append(sinksrow)
158 sinksrows = "".join("<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>%s</w:tr>"%x for x in sinksrows)
159 srows = sinksrows
160
161 vrmsrow1 = ["Name", "Source Voltage", "Output Voltage", "Output Current", "Tolerance", "Margin", "Pass/Fail"]
162 row2_1 = "<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>"+" ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='000D0EAB' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r w:rsidRPr='000D0EAB'><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t> %s</w:t></w:r></w:p></w:tc>" % (str(x)) for x in vrmsrow1)+"</w:tr>"
163 vrmsrows = []
164 for vrm in results.vrms:
165 vrmsrow = [vrm.name, str(vrm.sourceVoltage)+" V", str(vrm.outputVoltage)+" V" ,str(vrm.outputCurrent)+" A", vrm.tolerance, str(vrm.margin)+" V"]
166 if vrm.margin < 0.0 :
167 x = [invalid]
168 else:
169 x = [valid]
170 vrmsrow = vrmsrow + x
171 if vrmsrow[-1] == invalid:
172 vrmsrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in vrmsrow[:])
173 vrmsrows.insert(0,vrmsrow)
174 else:
175 vrmsrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in vrmsrow[:])
176 vrmsrows.append(vrmsrow)
177 vrmsrows = "".join("<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>%s</w:tr>"%x for x in vrmsrows)
178 vrows = vrmsrows
179
180 viasrow1 = ["Id", "Current","Pass/Fail"]
181 row3_1 = "<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>"+" ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='000D0EAB' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r w:rsidRPr='000D0EAB'><w:rPr><w:rStyle w:val='IntenseReference'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='002060'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t> %s</w:t></w:r></w:p></w:tc>" % (str(x)) for x in viasrow1)+"</w:tr>"
182 viasrows = []
183 nvv = 0
184 for key, via in results.viaCurrents.iteritems():
185 viasrow = [str(key), str(via[0])+" A"]
186 if float(via[0])<maxValueForVias:
187 x = [valid]
188 else:
189 nvv += 1
190 x = [invalid]
191 viasrow = viasrow + x
192 if viasrow[-1] == invalid:
193 viasrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in viasrow[:])
194 viasrows.insert(0,viasrow)
195 else:
196 viasrow = " ".join("<w:tc><w:tcPr><w:tcW w:w='1596' w:type='dxa'/></w:tcPr><w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00176979' w:rsidP='00475B81'><w:pPr><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr></w:pPr><w:r><w:rPr><w:rStyle w:val='IntenseReference'/><w:b w:val='0'/><w:bCs w:val='0'/><w:smallCaps w:val='0'/><w:color w:val='auto'/><w:spacing w:val='0'/><w:u w:val='none'/></w:rPr><w:t>%s</w:t></w:r></w:p></w:tc>" %str(x) for x in viasrow[:])
197 viasrows.append(viasrow)
198 viasrows = "".join("<w:tr w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidTr='00475B81'>%s</w:tr>"%x for x in viasrows)
199 virows = viasrows
200
201 templateDocx = zipfile.ZipFile(templatefilename)
202 templateDocx.extractall(tempdirectory)
203 design_picture = tempdirectory+"/word/media/image2.png"
204 if not os.path.exists(design_picture):
205 sys.stderr.write("\n Template Error: Wrong Template File Specified ")
206 shutil.copy(input_design_picture_filename, design_picture)
207 xml_document = tempdirectory+"/word/document.xml"
208 with open(xml_document) as templateXmlFile:
209 templateContents = templateXmlFile.read()
210
211 template = string.Template(templateContents)
212 sub = dict(failed_sinks="Number of Sinks Failed = "+str(nfs),
213 failed_vrms="Number of Vrms Failed = " +str(nfv),
214 failed_vias="Number of Violating Vias = "+str(nvv),
215 ref_current = "Reference Current = "+str(maxValueForVias) ,
216 notes = notes, simulation_log = log)
217
218 templateContents = template.safe_substitute(sub)
219 table_start_tag = "<w:p w:rsidR='00475B81' w:rsidRPr='00475B81' w:rsidRDefault='00475B81' w:rsidP='00475B81'><w:pPr><w:jc w:val='center'/><w:rPr><w:rStyle w:val='IntenseReference'/></w:rPr></w:pPr></w:p><w:tbl><w:tblPr><w:tblStyle w:val='TableGrid'/><w:tblW w:w='0' w:type='auto'/><w:tblLook w:val='04A0' w:firstRow='1' w:lastRow='0' w:firstColumn='1' w:lastColumn='0' w:noHBand='0' w:noVBand='1'/></w:tblPr><w:tblGrid><w:gridCol w:w='1596'/><w:gridCol w:w='1596'/><w:gridCol w:w='1596'/><w:gridCol w:w='1596'/><w:gridCol w:w='1596'/>\
220 <w:gridCol w:w='1596'/></w:tblGrid>"
221 sinkstable = table_start_tag+row1_1+srows+"</w:tbl> "
222 vrmstable = table_start_tag+row2_1+vrows+"</w:tbl>"
223 viastable =table_start_tag+row3_1+virows+"</w:tbl>"
224 tag ="$sinkstable"
225 t = templateContents.find(tag)
226 if tag in templateContents:
227 templateContents = templateContents[:t]+"</w:t></w:r></w:p>"+ sinkstable +templateContents[t+18+len(tag):]
228 tag ="$vrmstable"
229 t = templateContents.find(tag)
230 if tag in templateContents:
231 templateContents = templateContents[:t]+"</w:t></w:r></w:p>"+ vrmstable +templateContents[t+18+len(tag):]
232 tag ="$viastable"
233 t = templateContents.find(tag)
234 if tag in templateContents:
235 templateContents = templateContents[:t]+"</w:t></w:r></w:p>"+ viastable +templateContents[t+18+len(tag):]
236
237 with open(xml_document,"w") as outputFile:
238 outputFile.write(templateContents)
239
240 shutil.make_archive(outputfilename, "zip", tempdirectory)
241 thisFile = os.path.abspath(outputfilename)
242 os.rename(thisFile+".zip",thisFile + ".docx")
243 templateDocx.close()
244
245 -def export_to_odt(results,templatefilename,outputfilename,input_design_picture_filename,sipiData, maxValueForVias,tempdirectory):
246 import os
247 import sys
248 import zipfile
249 import shutil
250 import string
251 from string import Template
252 if outputfilename+".odt":
253
254 try:
255 os.remove(outputfilename+".odt")
256 except OSError:
257 pass
258
259 notes = sipiData.newSimulationData().notes
260 if not notes:
261 notes = "-------------Notes Empty--------------"
262 path = sipiData.simulationPath+"/project.log"
263 if os.path.exists(path):
264 log = open(path).readlines()
265 log ="</text:p><text:p text:style-name='TabContents'>".join(log)
266
267 else:
268 log = " Log file not found, please check for simulation errors"
269
270 nfs = len(results.failedSinks)
271 nfv = len(results.failedVrms)
272 valid = "<text:p text:style-name='Pass'>Pass"
273 invalid = "<text:p text:style-name='Fail'>Fail"
274
275 sinksrow1 = ["Name", "Source Current", "VRM Voltage", "Input Voltage", "Resistance", "Tolerance", "Margin","Pass/Fail"]
276 row1_1 = "<table:table-row>"+" ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabHeading'> %s</text:p></table:table-cell>" % (str(x)) for x in sinksrow1)+"</table:table-row>"
277 sinksrows=[]
278 for sink in results.sinks:
279 sinksrow = [sink.name, str(sink.sourceCurrent)+" A", str(sink.vrmVoltage)+" V",str(sink.inputVoltage)+" V", str(sink.resistance)+" Ohm", sink.tolerance, str(sink.margin)+" V"]
280
281 if sink.margin < 0.0 :
282 x = [invalid]
283 else:
284 x = [valid]
285 sinksrow = sinksrow + x
286 if sinksrow[-1] == invalid:
287 contents = " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in sinksrow[:-1])
288 sinksrow = contents + " ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in sinksrow[-1:])
289 sinksrows.insert(0,sinksrow)
290 else:
291 contents = " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in sinksrow[:-1])
292 sinksrow = contents +" ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in sinksrow[-1:])
293 sinksrows.append(sinksrow)
294 sinksrows = "".join("<table:table-row>%s</table:table-row>"%x for x in sinksrows)
295 srows = sinksrows
296
297 vrmsrow1 = ["Name", "Source Voltage", "Output Voltage", "Output Current", "Tolerance", "Margin", "Pass/Fail"]
298 row2_1 = "<table:table-row>"+" ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabHeading'> %s</text:p></table:table-cell>" % (str(x)) for x in vrmsrow1)+"</table:table-row>"
299 vrmsrows = []
300 for vrm in results.vrms:
301 vrmsrow = [vrm.name, str(vrm.sourceVoltage)+" V", str(vrm.outputVoltage)+" V" ,str(vrm.outputCurrent)+" A", vrm.tolerance, str(vrm.margin)+" V"]
302 if vrm.margin < 0.0 :
303 x = [invalid]
304 else:
305 x = [valid]
306 vrmsrow = vrmsrow + x
307 if vrmsrow[-1] == invalid:
308 contents = " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in vrmsrow[:-1])
309 vrmsrow = contents + " ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in vrmsrow[-1:])
310 vrmsrows.insert(0,vrmsrow)
311 else:
312 contents = " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in vrmsrow[:-1])
313 vrmsrow = contents + " ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in vrmsrow[-1:])
314 vrmsrows.append(vrmsrow)
315 vrmsrows = "".join("<table:table-row>%s</table:table-row>"%x for x in vrmsrows)
316 vrows = vrmsrows
317
318 viasrow1 = ["Id", "Current","Pass/Fail"]
319 row3_1 = "<table:table-row>"+" ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabHeading'> %s</text:p></table:table-cell>" % (str(x)) for x in viasrow1)+"</table:table-row>"
320 viasrows = []
321 nvv = 0
322 for key, via in results.viaCurrents.iteritems():
323 viasrow = [str(key), str(via[0])+" A"]
324 if float(via[0])<maxValueForVias:
325 x = [valid]
326 else:
327 nvv += 1
328 x = [invalid]
329 viasrow = viasrow + x
330 if viasrow[-1] == invalid:
331 contents= " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in viasrow[:-1])
332 viasrow = contents+" ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in viasrow[-1:])
333 viasrows.insert(0,viasrow)
334 else:
335 contents = " ".join("<table:table-cell office:value-type='string'><text:p text:style-name='TabContents'> %s</text:p></table:table-cell>" %str(x) for x in viasrow[:-1])
336 viasrow = contents +" ".join("<table:table-cell office:value-type='string'>%s</text:p></table:table-cell>" %str(x) for x in viasrow[-1:])
337 viasrows.append(viasrow)
338 viasrows = "".join("<table:table-row>%s</table:table-row>"%x for x in viasrows)
339 virows = viasrows
340
341 templateOdt = zipfile.ZipFile(templatefilename)
342 templateOdt.extractall(tempdirectory)
343 design_picture = tempdirectory+"/Pictures/10000000000003D6000003F9E8C134F9.png"
344 if not os.path.exists(design_picture):
345 sys.stderr.write("\n Template Error: Wrong Template File Specified ")
346 shutil.copy(input_design_picture_filename, design_picture)
347 xml_document = tempdirectory+"/content.xml"
348 with open(xml_document) as templateXmlFile:
349 templateContents = templateXmlFile.read()
350
351 template = string.Template(templateContents)
352 sub = dict(failed_sinks="Number of Sinks Failed = "+str(nfs),
353 failed_vrms="Number of Vrms Failed = " +str(nfv),
354 failed_vias="Number of Violating Vias = "+str(nvv),
355 ref_current = "Reference Current = "+str(maxValueForVias) ,
356 notes = notes, simulation_log = log)
357
358 templateContents = template.safe_substitute(sub)
359 sinkstable = "<table:table><table:table-column table:number-columns-repeated='"+str(len(sinksrow1))+"'/>"+row1_1+srows+"</table:table> "
360 vrmstable = "<table:table><table:table-column table:number-columns-repeated='"+str(len(vrmsrow1))+"'/>"+row2_1+vrows+"</table:table>"
361 viastable ="<table:table><table:table-column table:number-columns-repeated='"+str(len(viasrow1))+"'/>"+row3_1+virows+"</table:table>"
362 tag = "</office:automatic-styles>"
363 t = templateContents.find(tag)
364 passStyle = "<style:style style:name='Pass' style:family='paragraph' style:parent-style-name='Standard'><style:text-properties style:font-name='Times New Roman' fo:color='#000000' fo:font-size='7pt' fo:font-weight='normal' officeooo:rsid='000fe40f' officeooo:paragraph-rsid='000fe40f' fo:background-color='#66ff66' style:font-size-asian='7pt' style:font-weight-asian='normal' style:font-size-complex='7pt' style:font-weight-complex='normal'/></style:style>"
365 failStyle = "<style:style style:name='Fail' style:family='paragraph' style:parent-style-name='Standard'><style:text-properties style:font-name='Times New Roman' fo:color='#000000' fo:font-size='7pt' fo:font-weight='normal' officeooo:rsid='000fe40f' officeooo:paragraph-rsid='000fe40f' fo:background-color='#ff6666' style:font-size-asian='7pt' style:font-weight-asian='normal' style:font-size-complex='7pt' style:font-weight-complex='normal'/></style:style>"
366 TabHeadingStyle = "<style:style style:name='TabHeading' style:family='paragraph' style:parent-style-name='Standard'><style:text-properties style:font-name='Times New Roman' fo:color='#000066' fo:font-size='8pt' fo:font-weight='normal' officeooo:rsid='000fba34' officeooo:paragraph-rsid='000fba34' style:font-size-asian='8pt' style:font-weight-asian='normal' style:font-size-complex='8pt' style:font-weight-complex='normal'/></style:style>"
367 TabContentsStyle = "<style:style style:name='TabContents' style:family='paragraph' style:parent-style-name='Standard'><style:text-properties style:font-name='Times New Roman' fo:font-size='7pt' officeooo:rsid='001d4e92' officeooo:paragraph-rsid='001d4e92' style:font-size-asian='7pt' style:font-size-complex='7pt'/></style:style>"
368 if tag in templateContents:
369 templateContents = templateContents[:t]+passStyle+failStyle+TabHeadingStyle+TabContentsStyle+templateContents[t:]
370 tag ="$sinkstable"
371 t = templateContents.find(tag)
372 if tag in templateContents:
373 templateContents = templateContents[:t]+"</text:p>"+ sinkstable +templateContents[t+9+len(tag):]
374 tag ="$vrmstable"
375 t = templateContents.find(tag)
376 if tag in templateContents:
377 templateContents = templateContents[:t]+"</text:p>"+ vrmstable +templateContents[t+9+len(tag):]
378 tag ="$viastable"
379 t = templateContents.find(tag)
380 if tag in templateContents:
381 templateContents = templateContents[:t]+"</text:p>"+ viastable +templateContents[t+9+len(tag):]
382
383 with open(xml_document,"w") as outputFile:
384 outputFile.write(templateContents)
385
386 shutil.make_archive(outputfilename, "zip", tempdirectory)
387 thisFile = os.path.abspath(outputfilename)
388 os.rename(thisFile+".zip",thisFile + ".odt")
389 templateOdt.close()
390