Cross Reference: /solaris-userland/tools/gen-components
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
3770N/A#!/usr/bin/python2.7
1244N/A#
1244N/A# CDDL HEADER START
1244N/A#
1244N/A# The contents of this file are subject to the terms of the
1244N/A# Common Development and Distribution License (the "License").
1244N/A# You may not use this file except in compliance with the License.
1244N/A#
1244N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1244N/A# or http://www.opensolaris.org/os/licensing.
1244N/A# See the License for the specific language governing permissions
1244N/A# and limitations under the License.
1244N/A#
1244N/A# When distributing Covered Code, include this CDDL HEADER in each
1244N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1244N/A# If applicable, add the following below this CDDL HEADER, with the
1244N/A# fields enclosed by brackets "[]" replaced with your own identifying
1244N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1244N/A#
1244N/A# CDDL HEADER END
1244N/A#
5680N/A
5680N/A#
5404N/A# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
1244N/A#
1244N/A#
1267N/A# gen_components
3286N/A# A simple script to generate (on stdout), the component.html web page
3286N/A# found at: http://userland.us.oracle.com/component-lists/s12.html
1244N/A#
1244N/A
1244N/Aimport getopt
1244N/Aimport os
1244N/Aimport sys
1244N/A
5404N/Afrom subprocess import Popen, PIPE
5404N/A
1244N/Adebug = False
1244N/A
1269N/A# Hashtable of RE's, RM's and Teams keyed by component path.
1251N/Aowners = {}
1251N/A
1244N/A# Initial HTML for the generated web page.
1244N/Apreamble = """
1244N/A<html>
1244N/A<head>
1244N/A <style type='text/css' media='screen'>
1244N/A @import '/css/demo_table.css';
1244N/A @import '/css/ColVis.css';
1244N/A @import '/css/ColReorder.css';
1244N/A
1244N/A tr.even:hover, tr.even:hover td.sorting_1 ,
1244N/A tr.odd:hover, tr.odd:hover td.sorting_1 {
1244N/A background-color: gold;
1244N/A }
1244N/A
1244N/A </style>
1244N/A <script type='text/javascript' src='js/jquery.js'></script>
1244N/A <script type='text/javascript' src='js/jquery.dataTables.js'></script>
1244N/A <script type='text/javascript' src='js/ColReorder.js'></script>
1244N/A <script type='text/javascript' src='js/ColVis.js'></script>
1244N/A
1244N/A <script>
1244N/A $(document).ready(function() {
1244N/A $('#components').dataTable({
1244N/A "sDom": 'C<"clear">Rlfrtip',
1244N/A bPaginate: true,
1244N/A bFilter: true,
1244N/A bSort: true,
1244N/A iDisplayLength: -1,
1244N/A aLengthMenu: [ [ 10, 50, -1], [ 10, 50, 'All'] ]
1244N/A });
1244N/A });
1244N/A </script>
1244N/A</head>
1244N/A<body>
1244N/A
1244N/A<h1>Userland Components</h1>
1244N/A<p>
1244N/A<table align='center' id='components'>
1244N/A<thead>
1244N/A<tr>
1244N/A <th>Component</th>
1244N/A <th>Version</th>
1244N/A <th>Gate Path</th>
1244N/A <th>Package(s)</th>
1244N/A <th>ARC Case(s)</th>
1244N/A <th>License(s)</th>
1267N/A <th>TPNO</th>
1258N/A <th>BugDB</th>
1251N/A <th>RE</th>
1251N/A <th>RM</th>
1269N/A <th>Team</th>
1244N/A</tr>
1244N/A</thead>
1244N/A<tbody>
1244N/A"""
1244N/A
1244N/A# Final HTML for the generated web page.
1244N/Apostamble = """
1244N/A</tr>
1244N/A</tbody>
1244N/A</table>
1244N/A</body>
1244N/A</html>
1244N/A"""
1244N/A
5404N/A# Get a complete list of package names for the repo associated with this
5404N/A# Userland workspace.
5404N/Adef get_package_list(repo, build_version):
5404N/A names = []
5404N/A cmd = "pkgrepo list -H -s %s" % repo
5404N/A
5404N/A if debug:
5404N/A print >> sys.stderr, "get_package_list: command: `%s`" % cmd
5404N/A lines = os.popen(cmd).readlines()
5404N/A
5404N/A for line in lines:
5404N/A tokens = line.split()
5404N/A if tokens[2] != 'o' and tokens[2] != 'r':
5404N/A n = tokens[2].find(build_version)
5404N/A name = tokens[1] + "@" + tokens[2][:n]
5404N/A if debug:
5404N/A print >> sys.stderr, "get_package_list: name: ", name
5404N/A names.append(name)
5404N/A
5404N/A if debug:
5404N/A print >> sys.stderr, "get_package_list: names: ", names
5404N/A
5404N/A return names
5404N/A
1269N/A# Return a hashtable of RE's, RM's and Teams keyed by component path.
1251N/Adef read_owners(owners_file):
1251N/A if debug:
1251N/A print >> sys.stderr, "Reading %s" % owners_file
1251N/A try:
1251N/A fin = open(owners_file, 'r')
1251N/A lines = fin.readlines()
1251N/A fin.close()
1251N/A except:
1251N/A if debug:
1251N/A print >> sys.stderr, "Unable to read owners file: %s" % owners_file
1251N/A
1251N/A owners = {}
1251N/A for line in lines:
1251N/A line = line[:-1]
1269N/A component, re, rm, team = line.split("|")
1269N/A owners[component] = [ re, rm, team ]
1251N/A
1251N/A return owners
1251N/A
1244N/A# Return a sorted list of the directories containing one or more .p5m files.
1244N/Adef find_p5m_dirs(workspace):
1244N/A p5m_dirs = []
1244N/A for dir, _, files in os.walk(workspace + "/components"):
1244N/A for file in files:
5404N/A if dir.endswith("meta-packages/developer-opensolaris-userland"):
5404N/A continue;
3314N/A if dir.endswith("meta-packages/history"):
3314N/A continue;
1244N/A if file.endswith(".p5m"):
1244N/A p5m_dirs.append(dir)
1244N/A
1244N/A return sorted(list(set(p5m_dirs)))
1244N/A
1244N/A# Write out the initial HTML for the components.html web page.
1244N/Adef write_preamble():
1244N/A print preamble
1244N/A
1269N/A# Return the RE, RM and Team for this component.
1269N/Adef get_owner(p5m_dir):
1269N/A result = [ "Unknown", "Unknown", "Unknown" ]
1251N/A component_path = ""
1251N/A started = False
1251N/A tokens = p5m_dir.split("/")
1251N/A for token in tokens:
1251N/A if started:
1251N/A component_path += token + "/"
1251N/A if token == "components":
1251N/A started = True
1251N/A component_path = component_path[:-1]
1251N/A if component_path in owners:
1269N/A result = owners[component_path]
1251N/A if debug:
1251N/A print >> sys.stderr, "Component path: ", component_path,
1269N/A print >> sys.stderr, "RE, RM, Team: ", result
5404N/A
1269N/A return result
1251N/A
1244N/A# Generate an HTML table entry for all the information for the component
1244N/A# in the given directory. This generates a file called 'component-report'
1244N/A# under the components build directory.
1244N/Adef gen_reports(workspace, component_dir):
1244N/A if debug:
1244N/A print >> sys.stderr, "Processing %s" % component_dir
1244N/A
1269N/A re, rm, team = get_owner(component_dir)
1244N/A makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace
1244N/A targets = "clean component-hook"
1269N/A template = "cd %s; "
1269N/A template += "RESPONSIBLE_ENGINEER='%s' "
1269N/A template += "RESPONSIBLE_MANAGER='%s' "
1269N/A template += "TEAM='%s' "
1269N/A template += "gmake COMPONENT_HOOK='gmake %s component-report' %s"
3286N/A cmd = template % (component_dir, re, rm, team, makefiles, targets)
1244N/A
1251N/A if debug:
1251N/A print >> sys.stderr, "gen_reports: command: `%s`" % cmd
1244N/A lines = os.popen(cmd).readlines()
1244N/A
5404N/A# The package name(s) in the component-report files will be incorrectly
5404N/A# generated if there was a <whatever>VER.p5m file in the component
5404N/A# directory. For those components we've got to use the package names
5404N/A# from the repo associated with this Userland workspace.
5404N/Adef fix_reports(p5m_dirs, package_names):
5404N/A for p5m_dir in p5m_dirs:
5404N/A cmd = "ls %s/*VER.p5m" % p5m_dir
5404N/A p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE,
5404N/A close_fds=True)
5404N/A output = p.stdout.read()
5404N/A if output.find(".p5m") == -1:
5404N/A continue
5404N/A
5404N/A report = "%s/build/component-report" % p5m_dir
5404N/A with open(report, 'r') as fin:
5404N/A lines = fin.readlines()
5404N/A
5404N/A fixed = False
5404N/A td_count = 0
5404N/A report = "%s/build/component-report" % p5m_dir
5404N/A fout = open(report, 'w')
5404N/A for line in lines:
5404N/A if not fixed and td_count == 4 and line.startswith("</td>"):
5404N/A fixed = True
5404N/A elif not fixed and td_count == 4:
5404N/A n = line.rfind("-@")
5404N/A if n != -1:
5404N/A if debug:
5404N/A print >> sys.stderr, "FIX: %s" % line
5404N/A broken_pkg_name = line[:n]
5404N/A for package_name in package_names:
5404N/A if package_name.startswith(broken_pkg_name):
5404N/A line = "%s<br>\n" % package_name
5404N/A fout.write(line)
5404N/A else:
5404N/A fout.write(line)
5404N/A continue
5404N/A elif line.startswith("<td>"):
5404N/A td_count += 1
5404N/A fout.write(line)
5404N/A fout.close()
5404N/A
1244N/A# Collect all the .../build/component-report files and write them to stdout.
1251N/Adef write_reports(p5m_dirs, owners_file):
1244N/A for p5m_dir in p5m_dirs:
1244N/A report = "%s/build/component-report" % p5m_dir
1244N/A if debug:
1244N/A print >> sys.stderr, "Reading %s" % report
1244N/A try:
1244N/A fin = open(report, 'r')
1244N/A lines = fin.readlines()
1244N/A fin.close()
1244N/A sys.stdout.writelines(lines)
1244N/A except:
1244N/A if debug:
1244N/A print >> sys.stderr, "Unable to read: %s" % report
1244N/A
1244N/A# Write out the final HTML for the components.html web page.
1244N/Adef write_postamble():
1244N/A print postamble
1244N/A
1244N/A# Write out a usage message showing valid options to this script.
1244N/Adef usage():
1244N/A print >> sys.stderr, \
1244N/A"""
5404N/AUsage:
1393N/A gen-components [OPTION...]
1244N/A
5404N/A-b, --build-version
5404N/A Build version script to look for (and strip off) from package FMRIs.
5404N/A
1244N/A-d, --debug
1244N/A Turn on debugging
1244N/A
1251N/A-o, --owners
1251N/A Location of a file containing a list of RE's /RM's per component
1251N/A
5404N/A-r, --repo
5404N/A Repo containing the packages associated with this Userland workspace
5404N/A
1244N/A-w --workspace
1244N/A Location of the Userland workspace
1244N/A"""
1244N/A
1244N/A sys.exit(1)
1244N/A
1244N/A
1244N/Aif __name__ == "__main__":
1244N/A workspace = os.getenv('WS_TOP')
1393N/A owners_file = "/net/userland.us.oracle.com/gates/private/RE-RM-list.txt"
5404N/A repo = "http://userland.us.oracle.com:10004/"
5404N/A build_version = "-5.12.0.0.0"
1244N/A
1244N/A try:
5404N/A opts, args = getopt.getopt(sys.argv[1:], "b:do:r:w:",
5404N/A [ "build-version=", "debug", "owners=", "repo=", "workspace=" ])
1244N/A except getopt.GetoptError, err:
1244N/A print str(err)
1244N/A usage()
1244N/A
1244N/A for opt, arg in opts:
5404N/A if opt in [ "-b", "--build-version" ]:
5404N/A build_version = arg
5404N/A elif opt in [ "-d", "--debug" ]:
1251N/A debug = True
1251N/A elif opt in [ "-o", "--owners" ]:
1251N/A owners_file = arg
5404N/A elif opt in [ "-r", "--repo" ]:
5404N/A repo = arg
1251N/A elif opt in [ "-w", "--workspace" ]:
1244N/A workspace = arg
1244N/A else:
1244N/A assert False, "unknown option"
5404N/A
5404N/A package_names = get_package_list(repo, build_version)
1251N/A owners = read_owners(owners_file)
1244N/A write_preamble()
1244N/A p5m_dirs = find_p5m_dirs(workspace)
1244N/A for p5m_dir in p5m_dirs:
1244N/A gen_reports(workspace, p5m_dir)
5404N/A fix_reports(p5m_dirs, package_names)
1251N/A write_reports(p5m_dirs, owners_file)
1244N/A write_postamble()
1244N/A sys.exit(0)