3979N/A#!/usr/bin/python2.7
1273N/A#
1273N/A# CDDL HEADER START
1273N/A#
1273N/A# The contents of this file are subject to the terms of the
1273N/A# Common Development and Distribution License (the "License").
1273N/A# You may not use this file except in compliance with the License.
1273N/A#
1273N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1273N/A# or http://www.opensolaris.org/os/licensing.
1273N/A# See the License for the specific language governing permissions
1273N/A# and limitations under the License.
1273N/A#
1273N/A# When distributing Covered Code, include this CDDL HEADER in each
1273N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1273N/A# If applicable, add the following below this CDDL HEADER, with the
1273N/A# fields enclosed by brackets "[]" replaced with your own identifying
1273N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1273N/A#
1273N/A# CDDL HEADER END
1273N/A#
3979N/A# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
1273N/A#
1273N/A#
1273N/A# gen_components
3662N/A# A simple script to generate (on stdout), the component.html web page
3662N/A# found at: http://userland.us.oracle.com/component-lists/s11-update.html
1273N/A#
1273N/A
1273N/Aimport getopt
1273N/Aimport os
1273N/Aimport sys
1273N/A
1273N/Adebug = False
1273N/A
1273N/A# Hashtable of RE's, RM's and Teams keyed by component path.
1273N/Aowners = {}
1273N/A
1273N/A# Initial HTML for the generated web page.
1273N/Apreamble = """
1273N/A<html>
1273N/A<head>
1273N/A <style type='text/css' media='screen'>
1273N/A @import '/css/demo_table.css';
1273N/A @import '/css/ColVis.css';
1273N/A @import '/css/ColReorder.css';
1273N/A
1273N/A tr.even:hover, tr.even:hover td.sorting_1 ,
1273N/A tr.odd:hover, tr.odd:hover td.sorting_1 {
1273N/A background-color: gold;
1273N/A }
1273N/A
1273N/A </style>
1273N/A <script type='text/javascript' src='js/jquery.js'></script>
1273N/A <script type='text/javascript' src='js/jquery.dataTables.js'></script>
1273N/A <script type='text/javascript' src='js/ColReorder.js'></script>
1273N/A <script type='text/javascript' src='js/ColVis.js'></script>
1273N/A
1273N/A <script>
1273N/A $(document).ready(function() {
1273N/A $('#components').dataTable({
1273N/A "sDom": 'C<"clear">Rlfrtip',
1273N/A bPaginate: true,
1273N/A bFilter: true,
1273N/A bSort: true,
1273N/A iDisplayLength: -1,
1273N/A aLengthMenu: [ [ 10, 50, -1], [ 10, 50, 'All'] ]
1273N/A });
1273N/A });
1273N/A </script>
1273N/A</head>
1273N/A<body>
1273N/A
1273N/A<h1>Userland Components</h1>
1273N/A<p>
1273N/A<table align='center' id='components'>
1273N/A<thead>
1273N/A<tr>
1273N/A <th>Component</th>
1273N/A <th>Version</th>
1273N/A <th>Gate Path</th>
1273N/A <th>Package(s)</th>
1273N/A <th>ARC Case(s)</th>
1273N/A <th>License(s)</th>
1273N/A <th>TPNO</th>
1273N/A <th>BugDB</th>
1273N/A <th>RE</th>
1273N/A <th>RM</th>
1273N/A <th>Team</th>
1273N/A</tr>
1273N/A</thead>
1273N/A<tbody>
1273N/A"""
1273N/A
1273N/A# Final HTML for the generated web page.
1273N/Apostamble = """
1273N/A</tr>
1273N/A</tbody>
1273N/A</table>
1273N/A</body>
1273N/A</html>
1273N/A"""
1273N/A
1273N/A# Return a hashtable of RE's, RM's and Teams keyed by component path.
1273N/Adef read_owners(owners_file):
1273N/A if debug:
1273N/A print >> sys.stderr, "Reading %s" % owners_file
1273N/A try:
1273N/A fin = open(owners_file, 'r')
1273N/A lines = fin.readlines()
1273N/A fin.close()
1273N/A except:
1273N/A if debug:
1273N/A print >> sys.stderr, "Unable to read owners file: %s" % owners_file
1273N/A
1273N/A owners = {}
1273N/A for line in lines:
1273N/A line = line[:-1]
1273N/A component, re, rm, team = line.split("|")
1273N/A owners[component] = [ re, rm, team ]
1273N/A
1273N/A return owners
1273N/A
1273N/A# Return a sorted list of the directories containing one or more .p5m files.
1273N/Adef find_p5m_dirs(workspace):
1273N/A p5m_dirs = []
1273N/A for dir, _, files in os.walk(workspace + "/components"):
1273N/A for file in files:
3662N/A if dir.endswith("meta-packages/history"):
3662N/A continue;
1273N/A if file.endswith(".p5m"):
1273N/A p5m_dirs.append(dir)
1273N/A
1273N/A return sorted(list(set(p5m_dirs)))
1273N/A
1273N/A# Write out the initial HTML for the components.html web page.
1273N/Adef write_preamble():
1273N/A print preamble
1273N/A
1273N/A# Return the RE, RM and Team for this component.
1273N/Adef get_owner(p5m_dir):
1273N/A result = [ "Unknown", "Unknown", "Unknown" ]
1273N/A component_path = ""
1273N/A started = False
1273N/A tokens = p5m_dir.split("/")
1273N/A for token in tokens:
1273N/A if started:
1273N/A component_path += token + "/"
1273N/A if token == "components":
1273N/A started = True
1273N/A component_path = component_path[:-1]
1273N/A if component_path in owners:
1273N/A result = owners[component_path]
1273N/A if debug:
1273N/A print >> sys.stderr, "Component path: ", component_path,
1273N/A print >> sys.stderr, "RE, RM, Team: ", result
1273N/A
1273N/A return result
1273N/A
1273N/A# Generate an HTML table entry for all the information for the component
1273N/A# in the given directory. This generates a file called 'component-report'
1273N/A# under the components build directory.
1273N/Adef gen_reports(workspace, component_dir):
1273N/A if debug:
1273N/A print >> sys.stderr, "Processing %s" % component_dir
1273N/A
1273N/A re, rm, team = get_owner(component_dir)
1273N/A makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace
1273N/A targets = "clean component-hook"
1273N/A template = "cd %s; "
1273N/A template += "RESPONSIBLE_ENGINEER='%s' "
1273N/A template += "RESPONSIBLE_MANAGER='%s' "
1273N/A template += "TEAM='%s' "
1273N/A template += "gmake COMPONENT_HOOK='gmake %s component-report' %s"
3662N/A cmd = template % (component_dir, re, rm, team, makefiles, targets)
1273N/A
1273N/A if debug:
1273N/A print >> sys.stderr, "gen_reports: command: `%s`" % cmd
1273N/A lines = os.popen(cmd).readlines()
1273N/A
1273N/A# Collect all the .../build/component-report files and write them to stdout.
1273N/Adef write_reports(p5m_dirs, owners_file):
1273N/A for p5m_dir in p5m_dirs:
1273N/A report = "%s/build/component-report" % p5m_dir
1273N/A if debug:
1273N/A print >> sys.stderr, "Reading %s" % report
1273N/A try:
1273N/A fin = open(report, 'r')
1273N/A lines = fin.readlines()
1273N/A fin.close()
1273N/A sys.stdout.writelines(lines)
1273N/A except:
1273N/A if debug:
1273N/A print >> sys.stderr, "Unable to read: %s" % report
1273N/A
1273N/A# Write out the final HTML for the components.html web page.
1273N/Adef write_postamble():
1273N/A print postamble
1273N/A
1273N/A# Write out a usage message showing valid options to this script.
1273N/Adef usage():
1273N/A print >> sys.stderr, \
1273N/A"""
1273N/AUsage:
1394N/A gen-components [OPTION...]
1273N/A
1273N/A-d, --debug
1273N/A Turn on debugging
1273N/A
1273N/A-o, --owners
1273N/A Location of a file containing a list of RE's /RM's per component
1273N/A
1273N/A-w --workspace
1273N/A Location of the Userland workspace
1273N/A"""
1273N/A
1273N/A sys.exit(1)
1273N/A
1273N/A
1273N/Aif __name__ == "__main__":
1273N/A workspace = os.getenv('WS_TOP')
1394N/A owners_file = "/net/userland.us.oracle.com/gates/private/RE-RM-list.txt"
1273N/A
1273N/A try:
1273N/A opts, args = getopt.getopt(sys.argv[1:], "do:w:",
1273N/A [ "debug", "owners=", "workspace=" ])
1273N/A except getopt.GetoptError, err:
1273N/A print str(err)
1273N/A usage()
1273N/A
1273N/A for opt, arg in opts:
1273N/A if opt in [ "-d", "--debug" ]:
1273N/A debug = True
1273N/A elif opt in [ "-o", "--owners" ]:
1273N/A owners_file = arg
1273N/A elif opt in [ "-w", "--workspace" ]:
1273N/A workspace = arg
1273N/A else:
1273N/A assert False, "unknown option"
1273N/A
1273N/A owners = read_owners(owners_file)
1273N/A write_preamble()
1273N/A p5m_dirs = find_p5m_dirs(workspace)
1273N/A for p5m_dir in p5m_dirs:
1273N/A gen_reports(workspace, p5m_dir)
1273N/A write_reports(p5m_dirs, owners_file)
1273N/A write_postamble()
1273N/A sys.exit(0)