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