revised patch from gaby
[official-gcc/constexpr.git] / libstdc++-v3 / scripts / make_graphs.py
blobe230e7a9983a7f320e372335ba954209a2c86a4b
1 #!/usr/bin/python
3 import sys
4 import commands
5 import re
6 from xml.dom import minidom
7 from BeautifulSoup import BeautifulSoup
8 import make_graph
10 class exception:
11 pass
13 res_div_re = re.compile('(.*?)_res_div')
14 settings_div_re = re.compile('(.*?)_settings_div')
17 gray_border_div_str = '<div style = "border-style: dotted; border-width: 1px; border-color: lightgray">'
18 space_div_str = '<div style = "width: 100%; height: 20px">'
22 def logical_build_from_build(build):
23 if build == 'gcc':
24 return 'g++'
25 if build == 'msvc':
26 return 'msvc++'
27 if build == 'local':
28 return 'local'
29 sys.stderr.write(build)
30 raise exception
33 def img_title_from_origs(label, title, base_build_ref, build_name, logical_build_name):
34 title = title.replace('_tt_', '<tt>')
35 title = title.replace('_455tt_', '</tt>')
36 title = title.replace('_b_', '<b>')
37 title = title.replace('_455b_', '</b>')
38 title = title.replace('_456', ',')
39 title = title.replace('_457', '[]')
40 title = title.replace('_', ' ')
41 return '%s: %s - <a href = "%s_performance_tests.html#%s">%s</a>' % (
42 label,
43 title,
44 base_build_ref,
45 build_name,
46 logical_build_name)
49 def make_png(src_dir, doc_dir, res_dir, tests_info_xml_f_name, build_name, test_name):
50 cmd_str = '%s/scripts/make_graph.py %s %s %s %s %s' % (
51 src_dir, doc_dir,
52 res_dir,
53 tests_info_xml_f_name,
54 test_name,
55 build_name)
56 # Must start a new process for pychart - otherwise pngs overlap.
57 so = commands.getstatusoutput(cmd_str)
58 if(so[0] != 0):
59 sys.stderr.write(cmd_str + '\n')
60 sys.stderr.write(so[1] + '\n')
61 sys.exit(-1)
64 def make_png_str(label, test_name, build):
65 ret = '<h6 class="c1">'
66 ret += '<a name="%s" id= "%s">' % (label, label)
67 ret += '<img src="%s" ' % (test_name + '_' + build + '.png')
68 ret += 'alt="no image" />'
69 ret += '</a></h6>'
70 return ret
72 def process_html(html_f_name, src_dir, build_dir, htmls_xml_f_name, tests_info_xml_f_name, build_name, compiler_name):
73 doc_dir = src_dir + "/doc/html/ext/pb_ds"
74 res_dir = build_dir
75 html_f = open(doc_dir + '/' + html_f_name)
76 soup = BeautifulSoup(html_f.read())
77 html_f.close()
78 platform_comp_re = re.compile('platform_comp_%s' % build_name)
79 for d in soup('div'):
80 try:
81 settings_m = settings_div_re.match(d['id'])
82 res_m = res_div_re.match(d['id'])
83 except:
84 settings_m = None
85 res_m = None
87 if settings_m:
88 build = settings_m.groups()[0]
89 if build == build_name:
90 logical_build_name = logical_build_from_build(build)
91 info = gray_border_div_str
92 info += '<h3><a name = "%s"><u>%s</u></a></h3>' % (build, logical_build_name)
93 info += make_graph.comp_platform_info(compiler_name)
94 info += '</div>%s</div>' % space_div_str
95 d.contents = info
96 elif res_m:
97 label = res_m.groups()[0]
98 d = d.divTag
100 build = d['id'].replace('%s_' % label, '')
102 if build == build_name:
103 logical_build_name = logical_build_from_build(build)
104 d = d.divTag
105 test_name = d['id'].replace('%s_' % label, '')
106 d = d.divTag
107 base_build_ref = d['id'].replace('%s_' % label, '')
108 d = d.divTag
109 title = d['id'].replace('%s_' % label, '')
110 img_title = img_title_from_origs(label, title, base_build_ref, build, logical_build_name)
112 make_png(src_dir, doc_dir, res_dir, tests_info_xml_f_name, build_name, test_name)
113 png_str = make_png_str(label, test_name, build)
114 content = gray_border_div_str
115 content += png_str
116 content += img_title
117 # content += make_graph.legend(doc_dir, res_dir, tests_info_xml_f_name, test_name, build_name)
118 content += '</div>%s</div>' % space_div_str
119 d.contents = content
121 return soup
125 if __name__ == "__main__":
127 Doc dir
128 This module takes 6 parameters from the command line:
129 Source directory
130 Build directory
131 HTMLs XML file name
132 Tests info XML file name
133 Build name
134 Compiler name
137 usg = "make_graph.py <src_dir> <build_dir> <htmls_xml_f_name> <tests_info_xml_f_name> <build_name> <compiler_name>\n"
139 if len(sys.argv) != 7:
140 sys.stderr.write(usg)
141 raise exception
143 src_dir = sys.argv[1]
144 build_dir = sys.argv[2]
145 htmls_xml_f_name = sys.argv[3]
146 tests_info_xml_f_name = sys.argv[4]
147 build_name = sys.argv[5]
148 compiler_name = sys.argv[6]
149 doc_dir = src_dir + "/doc/html/ext/pb_ds"
150 htmls_dat = minidom.parse(htmls_xml_f_name)
151 for html in htmls_dat.getElementsByTagName('html'):
152 html_f_name = html.attributes['name'].value
154 new_soup = process_html(html_f_name, src_dir, build_dir, htmls_xml_f_name, tests_info_xml_f_name, build_name, compiler_name)
156 html_f = open(doc_dir + '/' + html_f_name, 'w')
157 html_f.write(str(new_soup))
158 html_f.close()