|
1 #!/usr/bin/python |
|
2 # |
|
3 # CDDL HEADER START |
|
4 # |
|
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. |
|
8 # |
|
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. |
|
13 # |
|
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] |
|
19 # |
|
20 # CDDL HEADER END |
|
21 # |
|
22 # Copyright (c) 2012, Oracle and/or it's affiliates. All rights reserved. |
|
23 # |
|
24 # |
|
25 # gen_components.py |
|
26 # A simple program to generate (on stdout) the component.html web page |
|
27 # found at: http://userland.us.oracle.com/components.html |
|
28 # |
|
29 |
|
30 import getopt |
|
31 import os |
|
32 import sys |
|
33 |
|
34 debug = False |
|
35 |
|
36 # Initial HTML for the generated web page. |
|
37 preamble = """ |
|
38 <html> |
|
39 <head> |
|
40 <style type='text/css' media='screen'> |
|
41 @import '/css/demo_table.css'; |
|
42 @import '/css/ColVis.css'; |
|
43 @import '/css/ColReorder.css'; |
|
44 |
|
45 tr.even:hover, tr.even:hover td.sorting_1 , |
|
46 tr.odd:hover, tr.odd:hover td.sorting_1 { |
|
47 background-color: gold; |
|
48 } |
|
49 |
|
50 </style> |
|
51 <script type='text/javascript' src='js/jquery.js'></script> |
|
52 <script type='text/javascript' src='js/jquery.dataTables.js'></script> |
|
53 <script type='text/javascript' src='js/ColReorder.js'></script> |
|
54 <script type='text/javascript' src='js/ColVis.js'></script> |
|
55 |
|
56 <script> |
|
57 $(document).ready(function() { |
|
58 $('#components').dataTable({ |
|
59 "sDom": 'C<"clear">Rlfrtip', |
|
60 bPaginate: true, |
|
61 bFilter: true, |
|
62 bSort: true, |
|
63 iDisplayLength: -1, |
|
64 aLengthMenu: [ [ 10, 50, -1], [ 10, 50, 'All'] ] |
|
65 }); |
|
66 }); |
|
67 </script> |
|
68 </head> |
|
69 <body> |
|
70 |
|
71 <h1>Userland Components</h1> |
|
72 <p> |
|
73 <table align='center' id='components'> |
|
74 <thead> |
|
75 <tr> |
|
76 <th>Component</th> |
|
77 <th>Version</th> |
|
78 <th>Gate Path</th> |
|
79 <th>Package(s)</th> |
|
80 <th>ARC Case(s)</th> |
|
81 <th>License(s)</th> |
|
82 </tr> |
|
83 </thead> |
|
84 <tbody> |
|
85 """ |
|
86 |
|
87 # Final HTML for the generated web page. |
|
88 postamble = """ |
|
89 </tr> |
|
90 </tbody> |
|
91 </table> |
|
92 </body> |
|
93 </html> |
|
94 """ |
|
95 |
|
96 # Return a sorted list of the directories containing one or more .p5m files. |
|
97 def find_p5m_dirs(workspace): |
|
98 p5m_dirs = [] |
|
99 for dir, _, files in os.walk(workspace + "/components"): |
|
100 for file in files: |
|
101 if file.endswith(".p5m"): |
|
102 p5m_dirs.append(dir) |
|
103 |
|
104 return sorted(list(set(p5m_dirs))) |
|
105 |
|
106 # Write out the initial HTML for the components.html web page. |
|
107 def write_preamble(): |
|
108 print preamble |
|
109 |
|
110 # Generate an HTML table entry for all the information for the component |
|
111 # in the given directory. This generates a file called 'component-report' |
|
112 # under the components build directory. |
|
113 def gen_reports(workspace, component_dir): |
|
114 if debug: |
|
115 print >> sys.stderr, "Processing %s" % component_dir |
|
116 |
|
117 makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace |
|
118 targets = "clean component-hook" |
|
119 cmd = "cd %s; gmake COMPONENT_HOOK='gmake %s component-report' %s" % \ |
|
120 (component_dir, makefiles, targets) |
|
121 |
|
122 lines = os.popen(cmd).readlines() |
|
123 |
|
124 # Collect all the .../build/component-report files and write them to stdout. |
|
125 def write_reports(p5m_dirs): |
|
126 for p5m_dir in p5m_dirs: |
|
127 report = "%s/build/component-report" % p5m_dir |
|
128 if debug: |
|
129 print >> sys.stderr, "Reading %s" % report |
|
130 try: |
|
131 fin = open(report, 'r') |
|
132 lines = fin.readlines() |
|
133 fin.close() |
|
134 sys.stdout.writelines(lines) |
|
135 except: |
|
136 if debug: |
|
137 print >> sys.stderr, "Unable to read: %s" % report |
|
138 |
|
139 # Write out the final HTML for the components.html web page. |
|
140 def write_postamble(): |
|
141 print postamble |
|
142 |
|
143 # Write out a usage message showing valid options to this script. |
|
144 def usage(): |
|
145 print >> sys.stderr, \ |
|
146 """ |
|
147 Usage: |
|
148 update_man_pages.py [OPTION...] |
|
149 |
|
150 -d, --debug |
|
151 Turn on debugging |
|
152 |
|
153 -w --workspace |
|
154 Location of the Userland workspace |
|
155 """ |
|
156 |
|
157 sys.exit(1) |
|
158 |
|
159 |
|
160 if __name__ == "__main__": |
|
161 workspace = os.getenv('WS_TOP') |
|
162 |
|
163 try: |
|
164 opts, args = getopt.getopt(sys.argv[1:], "dw:", |
|
165 [ "debug", "workspace=" ]) |
|
166 except getopt.GetoptError, err: |
|
167 print str(err) |
|
168 usage() |
|
169 |
|
170 for opt, arg in opts: |
|
171 if opt in [ "-w", "--workspace" ]: |
|
172 workspace = arg |
|
173 elif opt in [ "-d", "--debug" ]: |
|
174 debug = True |
|
175 else: |
|
176 assert False, "unknown option" |
|
177 |
|
178 write_preamble() |
|
179 p5m_dirs = find_p5m_dirs(workspace) |
|
180 for p5m_dir in p5m_dirs: |
|
181 gen_reports(workspace, p5m_dir) |
|
182 write_reports(p5m_dirs) |
|
183 write_postamble() |
|
184 sys.exit(0) |