rev 11969 - in people/modax/copyright-helper/trunk: . licenses parsers
Modestas Vainius
modax-guest at alioth.debian.org
Thu Aug 21 22:25:28 UTC 2008
Author: modax-guest
Date: 2008-08-21 22:25:28 +0000 (Thu, 21 Aug 2008)
New Revision: 11969
Modified:
people/modax/copyright-helper/trunk/CHCore.pm
people/modax/copyright-helper/trunk/CHLicenses.pm
people/modax/copyright-helper/trunk/copyright-helper.pl
people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
people/modax/copyright-helper/trunk/parsers/c_cpp.pm
Log:
* Support basic wildcarding.
* More improvements to license report generation.
Modified: people/modax/copyright-helper/trunk/CHCore.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHCore.pm 2008-08-21 20:50:27 UTC (rev 11968)
+++ people/modax/copyright-helper/trunk/CHCore.pm 2008-08-21 22:25:28 UTC (rev 11969)
@@ -434,10 +434,78 @@
return $count;
}
+sub CHCore::Directory::substract {
+ my $self = shift;
+ my $files = shift;
+ my $only_scanned = shift;
+ my %files;
+ my @left;
+ my @all;
+
+ for my $f (@{$self->getFiles()}) {
+ if (!$only_scanned || $f->isScanned()) {
+ $files{$f->getFilename()} = $f;
+ }
+ }
+
+ for my $f (@$files) {
+ if ($f->getDirectory() == $self && (!$only_scanned || $f->isScanned())) {
+ push @all, $f;
+ $files{$f->getFilename()} = undef;
+ }
+ }
+ for my $name (sort(keys %files)) {
+ push @left, $files{$name} if ($files{$name});
+ }
+ return (\@left, \@all);
+}
+
+sub CHCore::Directory::wildcardize {
+ my $print_routine = shift;
+ my $files = shift;
+ my $only_scanned = shift;
+ my %dirs;
+
+ for my $f (@$files) {
+ my $dir = $f->getDirectory();
+ if ($dir) {
+ $dir = $dir->getPathWithoutRoot();
+ } else {
+ $dir = "/";
+ }
+ push @{$dirs{$dir}}, $f;
+ }
+ for my $dirname (sort(keys %dirs)) {
+ my $dir = $dirs{$dirname}->[0]->getDirectory();
+ my $files;
+ my $action;
+
+ if ($dir) {
+ my ($left, $all) = $dir->substract($dirs{$dirname}, $only_scanned);
+ if (scalar(@$all) <= scalar(@$left)) {
+ # It is not worth to wildcard it
+ $files = $all;
+ } else {
+ # print $dirname, " -- ", scalar(@$all), " -- ", scalar(@$left), "\n";
+ &$print_routine((scalar(@$left)) ? "*-" : "*", $dir);
+ $files = $left;
+ }
+
+ $action = ($files == $all) ? "" : "-";
+ } else {
+ $files = $dirs{$dirname};
+ $action = "";
+ }
+
+ for my $f (@$files) {
+ &$print_routine($action, $f);
+ }
+ }
+}
+
sub CHCore::Directory::printAll($) {
my $self = shift;
-
CHCore::File::printAll($self) unless($self->isInherited("license"));
for my $f (@{$self->getFiles()}) {
@@ -790,12 +858,28 @@
my $files = $self->getFiles();
my $str = "";
+ my $print_routine = sub {
+ my ($action, $f) = @_;
+ $str .= $findent;
+ if ($action =~ /^\*/) {
+ # Wildcard
+ $str .= $f->getPathWithoutRoot();
+ $str .= "/" if ($f->getDirectory());
+ $str .= "*";
+ $str .= " excluding:" if ($action eq "*-");
+ $str .= "\n";
+ } else {
+ $str .= $action;
+ $str .= " " if ($action ne "");
+ $str .= $f->getPathWithoutRoot() . "\n";
+ }
+ };
if (scalar(@$files) > 1) {
$str .= $dindent . sprintf("Copyrighted-Files-Count: %d\n", scalar(@$files));
}
$str .= $dindent . "Copyrighted-Files:\n";
- $str .= $findent . join ("\n$findent", map $_->getPathWithoutRoot(), @$files);
+ CHCore::Directory::wildcardize($print_routine, $files, 1);
return $str;
}
@@ -884,6 +968,7 @@
return 0;
}
+
sub CHCore::LicenseSummary::addFiles($\@) {
my ($self, $files) = @_;
@@ -897,30 +982,43 @@
}
sub CHCore::LicenseSummary::__toStringLicense($$) {
- my ($self, $lic, $files, $i_lvl1, $i_lvl2) = @_;
- my $str = $i_lvl1 . "* " . $lic->getFullLicenseString() . "\n";
- $str .= $i_lvl2;
- my $fstr = "";
- if (@$files) {
- my $inherited_count = 0;
- for my $f (@$files) {
- $fstr .= $i_lvl2;
+ my ($self, $lic, $files, $i_lvl1, $i_lvl2, $msg) = @_;
+ my $str = "--\n";
+ $str .= $i_lvl1 . $lic->getFullLicenseString() .
+ " (" . $lic->getID() . ")\n";
+ my $print_routine = sub {
+ my ($action, $f) = @_;
+
+ $str .= $i_lvl2;
+ if ($action =~ /^\*/) {
+ # Wildcard
+ $str .= $f->getPathWithoutRoot();
+ $str .= "/" if ($f->getDirectory());
+ $str .= "*";
+ $str .= " excluding:" if ($action eq "*-");
+ $str .= "\n";
+ } else {
+ $str .= $action;
if ($f->isInherited("license")) {
- $fstr .= "? ";
- $inherited_count++;
+ $str .= "? ";
} else {
- $fstr .= "- ";
+ $str .= "+ ";
}
- $fstr .= $f->getPathWithoutRoot() . "\n";
+ $str .= $f->getPathWithoutRoot() . "\n";
}
- if ($inherited_count == scalar(@$files)) {
- $str .= sprintf("However, the license for the following file(s) (%d) was not explicitly specified:\n",
- scalar(@$files));
+ };
+ if (@$files) {
+ $str .= $i_lvl2;
+ if (defined($msg) && $msg eq "implicit") {
+ $str .= sprintf("However, the license of %d file(s) was not explicitly specified:\n\n",
+ scalar(@$files));
} else {
- $str .= sprintf("%d file(s) listed below are licensed under this license:\n", scalar(@$files));
+ $str .= sprintf("%d file(s) are licensed under this license:\n\n", scalar(@$files));
}
+ CHCore::Directory::wildcardize($print_routine, $files, 1);
}
- return $str . $fstr;
+ $str .= "\n" . $lic->getLicenseTerms($i_lvl1) . "\n--\n";
+ return $str;
}
sub CHCore::LicenseSummary::toString {
@@ -936,7 +1034,7 @@
my $lic_array = $values[0];
$maxlic = $lic_array->[0];
$maxfiles = $lic_array->[1];
- my @files = grep { $->isScanned() && $_->isInherited("license") } @$maxfiles;
+ my @files = grep { $_->isScanned() && $_->isInherited("license") } @$maxfiles;
$str .= $i_lvl1 . "License for all components is:\n";
$str .= $self->__toStringLicense($maxlic, \@files, $i_lvl2, $i_lvl3);
@@ -953,7 +1051,7 @@
$str .= $i_lvl1 . "License for all components unless stated otherwise:\n";
my @files = grep { $_->isScanned() && $_->isInherited("license") } @$maxfiles;
- $str .= $self->__toStringLicense($maxlic, \@files, $i_lvl2, $i_lvl3);
+ $str .= $self->__toStringLicense($maxlic, \@files, $i_lvl2, $i_lvl3, "implicit");
$str .= "\n";
$str .= $i_lvl1 . "Other used licenses:\n";
Modified: people/modax/copyright-helper/trunk/CHLicenses.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHLicenses.pm 2008-08-21 20:50:27 UTC (rev 11968)
+++ people/modax/copyright-helper/trunk/CHLicenses.pm 2008-08-21 22:25:28 UTC (rev 11969)
@@ -86,7 +86,7 @@
my ($self, $verPrefix, $verAnyStr) = @_;
$verAnyStr = "" unless defined($verAnyStr);
my $ver = $self->getVersion();
- return (defined $ver) ? "${verPrefix}${ver}" : $verAnyStr
+ return (defined $ver) ? "${verPrefix}${ver}" : $verAnyStr;
}
sub CHLicenses::LicenseBase::getID($) {
@@ -170,4 +170,23 @@
return 0;
}
}
+
+sub CHLicenses::LicenseBase::getLicenseTerms {
+ my ($self, $indent) = @_;
+ $indent = "" unless defined $indent;
+ return sprintf("%sOn Debian systems, the complete text of the\n%s%s%s can be found in\n%s%s",
+ $indent,
+ $indent, $self->getLongName(), $self->formatVersion(" version "),
+ $indent, $self->getLicenseDebianLocation());
+}
+
+sub CHLicenses::LicenseBase::getLicenseDebianLocation {
+ my $self = shift;
+ if ($self->getVersion()) {
+ return sprintf("/usr/share/common-licenses/%s-%s", $self->getShortName(), $self->getVersion());
+ } else {
+ return sprintf("/usr/share/common-licenses/%s", $self->getShortName());
+ }
+}
+
1;
Modified: people/modax/copyright-helper/trunk/copyright-helper.pl
===================================================================
--- people/modax/copyright-helper/trunk/copyright-helper.pl 2008-08-21 20:50:27 UTC (rev 11968)
+++ people/modax/copyright-helper/trunk/copyright-helper.pl 2008-08-21 22:25:28 UTC (rev 11969)
@@ -221,7 +221,7 @@
}
# Entry point
-${main::VERSION}='0.4.7';
+${main::VERSION}='0.4.8';
print_msg "\n";
print_msg "Copyright Helper v${main::VERSION}\n";
print_msg "Extracts copyright and license information from source code\n\n";
Modified: people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/gnulgpl.pm 2008-08-21 20:50:27 UTC (rev 11968)
+++ people/modax/copyright-helper/trunk/licenses/gnulgpl.pm 2008-08-21 22:25:28 UTC (rev 11969)
@@ -101,6 +101,16 @@
}
sub getLongName($) {
- "GNU Library/Lesser General Public License";
+ my $self = shift;
+ my $ver = $self->getVersion();
+ if ($ver) {
+ if ($ver eq "1" || $ver eq "2") {
+ return "GNU Library General Public License";
+ } else {
+ return "GNU Lesser General Public License";
+ }
+ } else {
+ return "GNU Library/Lesser General Public License";
+ }
}
Modified: people/modax/copyright-helper/trunk/parsers/c_cpp.pm
===================================================================
--- people/modax/copyright-helper/trunk/parsers/c_cpp.pm 2008-08-21 20:50:27 UTC (rev 11968)
+++ people/modax/copyright-helper/trunk/parsers/c_cpp.pm 2008-08-21 22:25:28 UTC (rev 11969)
@@ -91,7 +91,7 @@
my $i = 0;
for my $line (@lines) {
my $p;
- if ($line =~ m%^([\s*/])*(.*?)([\s*/])*\s*$%) {
+ if ($line =~ m%^([\s*/#])*(.*?)([\s*/#])*\s*$%) {
$p = $2;
} else {
$p = $line;
More information about the pkg-kde-commits
mailing list