gen-components revision 1267
1244N/A#!/usr/bin/python
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#
1244N/A# Copyright (c) 2012, Oracle and/or it's affiliates. All rights reserved.
1244N/A#
1244N/A#
1267N/A# gen_components
1267N/A# A simple script to generate (on stdout), the component.html web page
1244N/A# found at: http://userland.us.oracle.com/components.html
1244N/A#
1244N/A
1244N/Aimport getopt
1244N/Aimport os
1244N/Aimport sys
1244N/A
1244N/Adebug = False
1244N/A
1267N/A# Hashtable of components with TPNOs keyed by component name.
1267N/Acomp_TPNOs = {}
1267N/A
1251N/A# Hashtable of RE's / RM's 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>
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
1251N/A# Return a hashtable of RE's / RM's 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]
1251N/A component, re, rm = line.split("|")
1251N/A owners[component] = [ re, rm ]
1251N/A
1251N/A return owners
1251N/A
1267N/A# Return a hashtable of components with TPNOs keyed by component name.
1267N/Adef find_TPNOs(workspace):
1267N/A comp_TPNOs = {}
1267N/A for directory, _, files in os.walk(workspace + "/components"):
1267N/A for filename in files:
1267N/A if filename.endswith(".license") or filename.endswith(".copyright"):
1267N/A pathname = os.path.join(directory, filename)
1267N/A fin = open(pathname, 'r')
1267N/A lines = fin.readlines()
1267N/A fin.close()
1267N/A
1267N/A for line in lines:
1267N/A line = line.replace("\n", "")
1267N/A if line.startswith("Oracle Internal Tracking Number"):
1267N/A tpno_str = line.split()[-1]
1267N/A try:
1267N/A # Check that the TPNO is a valid number.
1267N/A tpno = int(tpno_str)
1267N/A if debug:
1267N/A print >> sys.stderr, "TPNO: %s: %s" % \
1267N/A (directory, tpno_str)
1267N/A comp_TPNOs[directory] = tpno_str
1267N/A except:
1267N/A print >> sys.stderr, "Unable to read TPNO: %s" % \
1267N/A pathname
1267N/A
1267N/A return(comp_TPNOs)
1267N/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:
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
1251N/A# Return the RE / RM for this component.
1251N/Adef get_re_and_rm(p5m_dir):
1251N/A re_and_rm = [ "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:
1251N/A re_and_rm = owners[component_path]
1251N/A if debug:
1251N/A print >> sys.stderr, "Component path: ", component_path,
1251N/A print >> sys.stderr, "RE / RM: ", re_and_rm
1251N/A
1251N/A return re_and_rm
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
1267N/A try:
1267N/A tpno = comp_TPNOs[component_dir]
1267N/A except:
1267N/A tpno = ""
1267N/A
1251N/A re, rm = get_re_and_rm(component_dir)
1244N/A makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace
1244N/A targets = "clean component-hook"
1267N/A cmd = "cd %s; TPNO='%s' RESPONSIBLE_ENGINEER='%s' RESPONSIBLE_MANAGER='%s' gmake COMPONENT_HOOK='gmake %s component-report' %s" % \
1267N/A (component_dir, tpno, re, rm, 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
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"""
1244N/AUsage:
1244N/A update_man_pages.py [OPTION...]
1244N/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
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')
1251N/A owners_file = "/net/userland.us.oracle.com/gates/private/RM-RE-list.txt"
1244N/A
1244N/A try:
1251N/A opts, args = getopt.getopt(sys.argv[1:], "do:w:",
1251N/A [ "debug", "owners=", "workspace=" ])
1244N/A except getopt.GetoptError, err:
1244N/A print str(err)
1244N/A usage()
1244N/A
1244N/A for opt, arg in opts:
1251N/A if opt in [ "-d", "--debug" ]:
1251N/A debug = True
1251N/A elif opt in [ "-o", "--owners" ]:
1251N/A owners_file = arg
1251N/A elif opt in [ "-w", "--workspace" ]:
1244N/A workspace = arg
1244N/A else:
1244N/A assert False, "unknown option"
1244N/A
1251N/A owners = read_owners(owners_file)
1244N/A write_preamble()
1267N/A comp_TPNOs = find_TPNOs(workspace)
1244N/A p5m_dirs = find_p5m_dirs(workspace)
1244N/A for p5m_dir in p5m_dirs:
1244N/A gen_reports(workspace, p5m_dir)
1251N/A write_reports(p5m_dirs, owners_file)
1244N/A write_postamble()
1244N/A sys.exit(0)