report-copyright revision 12707
10139N/A#!/usr/perl5/bin/perl
10139N/A#
10139N/A# Generate report on copyright files
10139N/A#
10139N/A# CDDL HEADER START
10139N/A#
10139N/A# The contents of this file are subject to the terms of the
10139N/A# Common Development and Distribution License, Version 1.0 only
10139N/A# (the "License"). You may not use this file except in compliance
10139N/A# with the License.
10139N/A#
10139N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10139N/A# or http://www.opensolaris.org/os/licensing.
10139N/A# See the License for the specific language governing permissions
10139N/A# and limitations under the License.
10139N/A#
10139N/A# When distributing Covered Code, include this CDDL HEADER in each
10139N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10139N/A# If applicable, add the following below this CDDL HEADER, with the
10139N/A# fields enclosed by brackets "[]" replaced with your own identifying
10139N/A# information: Portions Copyright [yyyy] [name of copyright owner]
10139N/A#
10139N/A# CDDL HEADER END
10139N/A#
10139N/A#
10139N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
10139N/A# Use is subject to license terms.
10139N/A#
10139N/Ause strict;
10139N/Ause warnings;
10139N/Ause Cwd;
10139N/Ause Getopt::Long qw(:config gnu_compat no_auto_abbrev bundling pass_through);
10139N/Ause File::Basename;
10139N/A
10139N/Asub usage() {
10139N/A print "report-copyright [options] <spec files...>\n";
10139N/A print "\n";
10139N/A print "Options:\n";
10139N/A print " -b s, --branch=s\n";
10139N/A print " Use the s branch for links to copyright files, instead\n";
10139N/A print " of trunk\n";
10139N/A print " -h, --help\n";
10139N/A print " Print this usage information\n";
10139N/A}
10139N/A
10139N/Amy @specs;
10139N/Amy $branch = "trunk";
10139N/A
10139N/Asub process_args {
10139N/A my $arg = shift;
10139N/A
10139N/A if ($arg =~ /^-/) {
10139N/A print "Unknown option: $arg\n";
10139N/A print "Try --help for usage.\n";
10139N/A exit (1);
10139N/A }
10139N/A
10139N/A push (@specs, $arg);
10139N/A}
13931N/A
10139N/Asub process_options {
10139N/A
10139N/A Getopt::Long::Configure ("bundling");
10139N/A
10139N/A GetOptions ('h|help' => sub { usage (); exit (0); },
10139N/A 'b|branch=s' => sub { shift; $branch = shift; $branch = "branches/$branch"; },
10139N/A '<>' => \&process_args);
10139N/A}
13570N/A
10139N/Amy %owners;
10139N/Amy %copyright_files;
15942N/A
10139N/A# like uniq(1)
15942N/Asub uniq (@) {
14177N/A my @list = @_;
15942N/A my $prev;
15942N/A if (not @list) {
15942N/A return @list;
15942N/A }
15942N/A $prev = $list[0];
11965N/A my @uniq_list = ($prev);
16075N/A foreach my $str (@list) {
15942N/A next if $str eq $prev;
15942N/A push (@uniq_list, $str);
15942N/A $prev = $str;
10139N/A }
10139N/A return @uniq_list;
15942N/A}
10139N/A
10139N/Asub main() {
15942N/A process_options();
15942N/A
15942N/A foreach my $spec (@specs) {
15942N/A next if not defined ($spec);
11933N/A # find the owner from the comments
10139N/A my $RE = '^# [Oo]wner: *.[^ ]*[ ]*$';
10139N/A my $owner = `grep '$RE' $spec | head -1`;
15288N/A chomp ($owner);
10139N/A if ($owner eq '') {
10139N/A $owner = 'Unknown';
13760N/A }
10139N/A $owner =~ s/^#\s*[Oo]wner:\s*(\S+)/$1/;
10139N/A $owners{$spec} = $owner;
16309N/A
16309N/A # find the copyright file
16309N/A my $cpr = `spectool --with-sun-branding eval '%sunw_copyright' $spec 2>/dev/null`;
16309N/A chomp ($cpr);
16309N/A $copyright_files{$spec} = $cpr;
16309N/A }
16309N/A
16309N/A print << "_EOF";
10139N/A<html>
10139N/A <head>
15942N/A <title>JDS copyright file report for $branch</title>
10139N/A </head>
10139N/A <body>
10139N/A <font face="arial,sans">
10139N/A <b>JDS package copyright report for $branch</b><p>
10139N/A <table border=1 cellspacing=0>
10139N/A <tr><td><b>spec file</b></td><td><b>owner</b></td><td><b>copyright file</b></td></tr>
10139N/A_EOF
10139N/A
10139N/A my $missing = 0;
15942N/A foreach my $spec (sort @specs) {
10139N/A my $base = basename ($spec);
10139N/A print "<tr><td>$base</td>\n";
10139N/A print "<td><a href=\"http://www.opensolaris.org/viewProfile.jspa?username=$owners{$spec}\">$owners{$spec}</a></td>\n";
15942N/A $base =~ s/\.spec//;
10139N/A if ($copyright_files{$spec} ne "${base}.copyright") {
15942N/A print "<td bgcolor=#ffaaaa>$copyright_files{$spec}</td>\n";
10139N/A $missing ++;
10139N/A } else {
10139N/A print "<td bgcolor=#aaffaa><a href=\"http://src.opensolaris.org/source/xref/jds/spec-files/${branch}/copyright/${copyright_files{$spec}}\">$copyright_files{$spec}</a></td>\n";
10139N/A }
10139N/A print "</tr>\n";
10139N/A }
10139N/A
10139N/A my $total = $#specs + 1;
15942N/A my $date = `TZ=GMT date`;
10139N/A
15942N/A print << "_EOF";
10139N/A </table><p>
11925N/A $missing package(s) missing copyright file out of $total.
10139N/A <p>
15942N/A <b>Missing copyright files by owner:</b><small>
10139N/A <table border=1 cellspacing=0>
10139N/A <tr><td><b>owner</b></td><td><b>spec files</b></td></tr>
10139N/A_EOF
10139N/A foreach my $owner (uniq sort values %owners) {
15942N/A my $first_spec = 1;
10139N/A foreach my $spec (sort @specs) {
10139N/A next if $owners{$spec} ne $owner;
10139N/A my $base = basename ($spec);
10139N/A $base =~ s/\.spec//;
10139N/A if ($copyright_files{$spec} ne "${base}.copyright") {
10139N/A if ($first_spec) {
10139N/A print "<tr><td valign=top><a href=\"http://www.opensolaris.org/viewProfile.jspa?username=$owners{$spec}\">$owners{$spec}</a></td>\n";
10139N/A $first_spec = 0;
15942N/A print "<td>\n";
15942N/A }
15942N/A print "$base<br>\n";
15942N/A }
10139N/A }
15944N/A if (not $first_spec) {
15999N/A print "</td></tr>\n";
15942N/A }
13727N/A }
15942N/A print << "_EOF";
15942N/A </table>
15942N/A <p><i>report generated on $date</i></small>
15942N/A </font>
15942N/A </body>
15942N/A</html>
15942N/A_EOF
10139N/A}
15942N/A
15942N/Amain();
15942N/A