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