11#!/usr/bin/env python
22
3+ #you probably want to run the ctest script that calls this instead:
4+ # ctest -S ctest_matrix.cmake
5+
6+ #must be ran from scl/build_matrix
7+
38from xml .etree import ElementTree as ET
49import os
510from datetime import date
611import subprocess
712import codecs
13+ import io
814
915
1016#ctest xml file layout
2127#</Site>
2228
2329
24- #summary (aka 's') is a table at the top of the document
30+ #summary (aka 's') is a table near the top of the document
2531#body (aka 'b') contains the details for all schemas
2632
2733def main ():
28- #xml_file = os.path.abspath(__file__)
29- #xml_file = os.path.dirname(xml_file)
30- #xml_file = os.path.join(xml_file, "Test.xml")
31- xml_file = "Test.xml"
32- #output_path = "/opt/step/wiki-scl"
33- out_main = "Schema-build-matrix.md"
34- out = codecs .open (out_main ,encoding = 'utf-8' ,mode = 'w' )
34+ xml_file = find_xml ()
35+ wikipath , matrix = find_wiki ()
3536
36- #cleanup_wiki(output_path) #delete old files
37+ #codecs.open is deprecated but io.open doesn't seem to work, and open() complains of unicode
38+ out = codecs .open (matrix ,encoding = 'utf-8' ,mode = 'w' )
3739 out .write ( header () )
38- summary ,body = read_tests (xml_file )
39- out .write ( summary )
40- out .write ( body )
41-
40+ out .write ( read_tests (xml_file ) )
41+ out .close ()
42+ git_push (wikipath , matrix )
43+
44+
45+ def find_xml ():
46+ #find xml file
47+ i = 0
48+ for dirname in os .listdir ("Testing" ):
49+ if str (date .today ().year ) in dirname :
50+ i += 1
51+ if i > 1 :
52+ print "Too many directories, exiting"
53+ exit (1 )
54+ xml = os .path .join ("Testing" , dirname , "Test.xml" )
55+ return xml
56+
57+ def find_wiki ():
58+ #find wiki and matrix file, issue 'git pull'
59+ wikipath = os .path .abspath ("../../wiki-scl" )
60+ if not os .path .isdir (os .path .join (wikipath ,".git" )):
61+ print "Can't find wiki or not a git repo"
62+ exit (1 )
63+ p = subprocess .call (["git" , "pull" , "origin" ], cwd = wikipath )
64+ if not p == 0 :
65+ print "'git pull' exited with error"
66+ exit (1 )
67+ matrix = os .path .join (wikipath , "Schema-build-matrix.md" )
68+ if not os .path .isfile (matrix ):
69+ print "Matrix file doesn't exist or isn't a file"
70+ exit (1 )
71+ return wikipath ,matrix
72+
73+ def git_push (path ,f ):
74+ p = subprocess .call (["git" , "add" , f ], cwd = path )
75+ if not p == 0 :
76+ print "'git add' exited with error"
77+ exit (1 )
78+ msg = date .today ().__str__ () + " - schema matrix updated by update-matrix.py"
79+ p = subprocess .call (["git" , "commit" , "-m" , msg ], cwd = path )
80+ if not p == 0 :
81+ print "'git commit' exited with error"
82+ exit (1 )
83+ p = subprocess .call (["git" , "push" , "origin" ], cwd = path )
84+ if not p == 0 :
85+ print "'git push' exited with error"
86+ exit (1 )
87+
88+
4289def header ():
4390 h = "## Created " + date .today ().__str__ () + "\n " + "### Current as of commit "
4491 l = subprocess .check_output (["git" , "log" , """--pretty=format:%H Commit Summary: %s<br>Author: %aN<br>Date: %aD""" , "-n1" ])
@@ -48,7 +95,7 @@ def header():
4895 return h
4996
5097def read_tests (xml ):
51- # read all <Test>s in xml, create summary and body html/markdown
98+ # read all <Test>s in xml, create mixed html/markdown
5299 try :
53100 tree = ET .parse (xml )
54101 except Exception , inst :
@@ -58,7 +105,7 @@ def read_tests(xml):
58105 root = tree .getroot ()
59106 testing = root .find ("Testing" )
60107
61-
108+
62109 tests = testing .findall ("Test" )
63110 summary = ""
64111 body = ""
@@ -67,7 +114,7 @@ def read_tests(xml):
67114 summary += s
68115 body += b
69116 summary += "</table>\n \n "
70- return summary , body
117+ return summary + body
71118
72119
73120
@@ -96,7 +143,7 @@ def schema_info(test,tests):
96143 s += "----</td></tr>\n "
97144 b += "</table>\n "
98145 return s ,b
99-
146+
100147def test_table (ttype , test ):
101148 # populate the table for one test
102149 # returns: html & markdown formatted text to be added to 'body'
@@ -112,7 +159,6 @@ def test_table(ttype, test):
112159 trunc1 = ""
113160 trunc2 = ""
114161 if test .get ("Status" ) == "passed" :
115-
116162 #print summary in b
117163 b += " succeeded with " + trunc1 + w .__str__ () + " warnings " + trunc2
118164 if w == 0 : #nothing to print in the table, so skip it
@@ -169,17 +215,21 @@ def test_table(ttype, test):
169215 break
170216 b += "</table></td></tr>\n "
171217 return b
172-
218+
173219def test_status (test ):
220+ t = ""
221+ for m in test .find ("Results" ).findall ("NamedMeasurement" ):
222+ if m .get ("name" ) == "Execution Time" :
223+ t = " in " + m .find ("Value" ).text + "s"
224+ break
174225 if test .get ("Status" ) == "passed" :
175226 s = "<font color=green>PASS</font>"
176227 elif test .get ("Status" ) == "failed" :
177228 s = "<font color=red>FAIL</font>"
178229 else :
179230 s = "<font color=cyan>" + test .get ("Status" ) + "</font>"
180- return s
181-
231+ return s + t
232+
182233if __name__ == "__main__" :
183234 # Someone is launching this directly
184235 main ()
185-
0 commit comments