libxml2: put 64-bit programs in /usr/bin
[unleashed-userland.git] / tools / gen-components
blobd30d4c0e7532ccdd41c9321c701e1c17845838a4
1 #!/usr/bin/python
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright (c) 2012, 2013, Oracle and/or it's affiliates. All rights reserved.
25 # gen_components
26 # A simple script to generate (on stdout), the component.html web page
27 # found at: http://userland.us.oracle.com/components.html
30 import getopt
31 import os
32 import sys
34 debug = False
36 # TPNO string to search for in each .p5m file.
37 TPNO_str = "com.oracle.info.tpno"
39 # Hashtable of components with TPNOs keyed by component name.
40 comp_TPNOs = {}
42 # Hashtable of RE's, RM's and Teams keyed by component path.
43 owners = {}
45 # Initial HTML for the generated web page.
46 preamble = """
47 <html>
48 <head>
49 <style type='text/css' media='screen'>
50 @import '/css/demo_table.css';
51 @import '/css/ColVis.css';
52 @import '/css/ColReorder.css';
54 tr.even:hover, tr.even:hover td.sorting_1 ,
55 tr.odd:hover, tr.odd:hover td.sorting_1 {
56 background-color: gold;
59 </style>
60 <script type='text/javascript' src='js/jquery.js'></script>
61 <script type='text/javascript' src='js/jquery.dataTables.js'></script>
62 <script type='text/javascript' src='js/ColReorder.js'></script>
63 <script type='text/javascript' src='js/ColVis.js'></script>
65 <script>
66 $(document).ready(function() {
67 $('#components').dataTable({
68 "sDom": 'C<"clear">Rlfrtip',
69 bPaginate: true,
70 bFilter: true,
71 bSort: true,
72 iDisplayLength: -1,
73 aLengthMenu: [ [ 10, 50, -1], [ 10, 50, 'All'] ]
74 });
75 });
76 </script>
77 </head>
78 <body>
80 <h1>Userland Components</h1>
81 <p>
82 <table align='center' id='components'>
83 <thead>
84 <tr>
85 <th>Component</th>
86 <th>Version</th>
87 <th>Gate Path</th>
88 <th>Package(s)</th>
89 <th>ARC Case(s)</th>
90 <th>License(s)</th>
91 <th>TPNO</th>
92 <th>BugDB</th>
93 <th>RE</th>
94 <th>RM</th>
95 <th>Team</th>
96 </tr>
97 </thead>
98 <tbody>
99 """
101 # Final HTML for the generated web page.
102 postamble = """
103 </tr>
104 </tbody>
105 </table>
106 </body>
107 </html>
110 # Return a hashtable of RE's, RM's and Teams keyed by component path.
111 def read_owners(owners_file):
112 if debug:
113 print >> sys.stderr, "Reading %s" % owners_file
114 try:
115 fin = open(owners_file, 'r')
116 lines = fin.readlines()
117 fin.close()
118 except:
119 if debug:
120 print >> sys.stderr, "Unable to read owners file: %s" % owners_file
122 owners = {}
123 for line in lines:
124 line = line[:-1]
125 component, re, rm, team = line.split("|")
126 owners[component] = [ re, rm, team ]
128 return owners
130 # Return a hashtable of components with TPNOs keyed by component name.
131 def find_TPNOs(workspace):
132 comp_TPNOs = {}
133 for directory, _, files in os.walk(workspace + "/components"):
134 for filename in files:
135 if filename.endswith(".p5m"):
136 pathname = os.path.join(directory, filename)
137 fin = open(pathname, 'r')
138 lines = fin.readlines()
139 fin.close()
141 for line in lines:
142 line = line.replace("\n", "")
143 n = line.find(TPNO_str)
144 if n != -1:
145 tpno_str = line[n:].split("=")[1]
146 try:
147 # Check that the TPNO is a valid number.
148 tpno = int(tpno_str)
149 if debug:
150 print >> sys.stderr, "TPNO: %s: %s" % \
151 (directory, tpno_str)
152 comp_TPNOs[directory] = tpno_str
153 except:
154 # Check to see if line end in a "\" character in
155 # which case, it's an attribute rather than an
156 # set name action, so extract it a different way.
157 try:
158 n += len(TPNO_str)+1
159 tpno_str = line[n:].split()[0]
160 # Check that the TPNO is a valid number.
161 tpno = int(tpno_str)
162 if debug:
163 print >> sys.stderr, "TPNO: %s: %s" % \
164 (directory, tpno_str)
166 # If it's an attribute, there might be more
167 # than one TPNO for this component.
168 if directory in comp_TPNOs:
169 entry = comp_TPNOs[directory]
170 tpno_str = "%s,%s" % (entry, tpno_str)
172 comp_TPNOs[directory] = tpno_str
173 except:
174 print >> sys.stderr, \
175 "Unable to read TPNO: %s" % pathname
177 return(comp_TPNOs)
179 # Return a sorted list of the directories containing one or more .p5m files.
180 def find_p5m_dirs(workspace):
181 p5m_dirs = []
182 for dir, _, files in os.walk(workspace + "/components"):
183 for file in files:
184 if file.endswith(".p5m"):
185 p5m_dirs.append(dir)
187 return sorted(list(set(p5m_dirs)))
189 # Write out the initial HTML for the components.html web page.
190 def write_preamble():
191 print preamble
193 # Return the RE, RM and Team for this component.
194 def get_owner(p5m_dir):
195 result = [ "Unknown", "Unknown", "Unknown" ]
196 component_path = ""
197 started = False
198 tokens = p5m_dir.split("/")
199 for token in tokens:
200 if started:
201 component_path += token + "/"
202 if token == "components":
203 started = True
204 component_path = component_path[:-1]
205 if component_path in owners:
206 result = owners[component_path]
207 if debug:
208 print >> sys.stderr, "Component path: ", component_path,
209 print >> sys.stderr, "RE, RM, Team: ", result
211 return result
213 # Generate an HTML table entry for all the information for the component
214 # in the given directory. This generates a file called 'component-report'
215 # under the components build directory.
216 def gen_reports(workspace, component_dir):
217 if debug:
218 print >> sys.stderr, "Processing %s" % component_dir
220 try:
221 tpno = comp_TPNOs[component_dir]
222 except:
223 tpno = ""
225 re, rm, team = get_owner(component_dir)
226 makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace
227 targets = "clean component-hook"
228 template = "cd %s; "
229 template += "TPNO='%s' "
230 template += "RESPONSIBLE_ENGINEER='%s' "
231 template += "RESPONSIBLE_MANAGER='%s' "
232 template += "TEAM='%s' "
233 template += "gmake COMPONENT_HOOK='gmake %s component-report' %s"
234 cmd = template % (component_dir, tpno, re, rm, team, makefiles, targets)
236 if debug:
237 print >> sys.stderr, "gen_reports: command: `%s`" % cmd
238 lines = os.popen(cmd).readlines()
240 # Collect all the .../build/component-report files and write them to stdout.
241 def write_reports(p5m_dirs, owners_file):
242 for p5m_dir in p5m_dirs:
243 report = "%s/build/component-report" % p5m_dir
244 if debug:
245 print >> sys.stderr, "Reading %s" % report
246 try:
247 fin = open(report, 'r')
248 lines = fin.readlines()
249 fin.close()
250 sys.stdout.writelines(lines)
251 except:
252 if debug:
253 print >> sys.stderr, "Unable to read: %s" % report
255 # Write out the final HTML for the components.html web page.
256 def write_postamble():
257 print postamble
259 # Write out a usage message showing valid options to this script.
260 def usage():
261 print >> sys.stderr, \
263 Usage:
264 gen-components [OPTION...]
266 -d, --debug
267 Turn on debugging
269 -o, --owners
270 Location of a file containing a list of RE's /RM's per component
272 -w --workspace
273 Location of the Userland workspace
276 sys.exit(1)
279 if __name__ == "__main__":
280 workspace = os.getenv('WS_TOP')
281 owners_file = "/net/userland.us.oracle.com/gates/private/RE-RM-list.txt"
283 try:
284 opts, args = getopt.getopt(sys.argv[1:], "do:w:",
285 [ "debug", "owners=", "workspace=" ])
286 except getopt.GetoptError, err:
287 print str(err)
288 usage()
290 for opt, arg in opts:
291 if opt in [ "-d", "--debug" ]:
292 debug = True
293 elif opt in [ "-o", "--owners" ]:
294 owners_file = arg
295 elif opt in [ "-w", "--workspace" ]:
296 workspace = arg
297 else:
298 assert False, "unknown option"
300 owners = read_owners(owners_file)
301 write_preamble()
302 comp_TPNOs = find_TPNOs(workspace)
303 p5m_dirs = find_p5m_dirs(workspace)
304 for p5m_dir in p5m_dirs:
305 gen_reports(workspace, p5m_dir)
306 write_reports(p5m_dirs, owners_file)
307 write_postamble()
308 sys.exit(0)