rev 13560 - in people/modax/copyright-helper/trunk: . licenses

Modestas Vainius modax-guest at alioth.debian.org
Sun Jan 25 22:57:09 UTC 2009


Author: modax-guest
Date: 2009-01-25 22:57:09 +0000 (Sun, 25 Jan 2009)
New Revision: 13560

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/bsd.pm
   people/modax/copyright-helper/trunk/licenses/mit.pm
Log:
Improved output when there is only file matching for the license

Modified: people/modax/copyright-helper/trunk/CHCore.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHCore.pm	2009-01-25 22:49:27 UTC (rev 13559)
+++ people/modax/copyright-helper/trunk/CHCore.pm	2009-01-25 22:57:09 UTC (rev 13560)
@@ -992,6 +992,7 @@
 sub CHCore::LicenseSummary::__toStringLicense($$) {
     my ($self, $lic, $files, $i_lvl1, $i_lvl2, $msg) = @_;
     my $str = "--\n";
+    my $printLicTerms = 1;
 
     if (defined $lic) {
         $str .= $i_lvl1 . $lic->getFullLicenseString() . 
@@ -1021,15 +1022,16 @@
     if (@$files) {
         if (defined $msg) {
             $str .= $i_lvl2;
+            my $text;
             if ($msg eq "implicit") {
-                $msg = "However, the license of %d files was not explicitly specified:\n\n";
-                $msg = "However, the license was not explicitly specified for the following file:\n\n"
+                $text = "However, the license of %d files was not explicitly specified:\n\n";
+                $text = "However, the license was not explicitly specified for the following file:\n\n"
                     if (scalar(@$files) == 1);
-                $str .= sprintf($msg, scalar(@$files));
+                $str .= sprintf($text, scalar(@$files));
             } elsif ($msg eq "licensed") {
-                $msg = "%d files are licensed under this license:\n\n";
-                $msg = "The following file is licensed under this license:\n\n" if (scalar(@$files) == 1);
-                $str .= sprintf($msg, scalar(@$files));
+                $text = "%d files are licensed under this license:\n\n";
+                $text = "The following file is licensed under this license:\n\n" if (scalar(@$files) == 1);
+                $str .= sprintf($text, scalar(@$files));
             } else {
                 $str .= "\n";
             }
@@ -1037,8 +1039,15 @@
             $str .= "\n";
         }
         CHCore::Directory::wildcardize($print_routine, $files, 1);
+        if (defined $msg && $msg eq "licensed" && scalar(@$files) == 1) {
+            $str .= "\n$i_lvl1" .
+                    join("\n$i_lvl1", $files->[0]->getLicense()->getNiceFoundInText(80)) .
+                    "\n";
+            # Do not print terms. Already printed.
+            $printLicTerms = 0 if (!defined $lic || !$lic->areLicenseTermsLink());
+        }
     }
-    if (defined $lic) {
+    if (defined $lic && $printLicTerms) {
         $str .= "\n" . $lic->getLicenseTerms($i_lvl1) . "\n--\n";
     }
     return $str;

Modified: people/modax/copyright-helper/trunk/CHLicenses.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHLicenses.pm	2009-01-25 22:49:27 UTC (rev 13559)
+++ people/modax/copyright-helper/trunk/CHLicenses.pm	2009-01-25 22:57:09 UTC (rev 13560)
@@ -94,7 +94,15 @@
     my ($self, $verPrefix, $verAnyStr) = @_;
     $verAnyStr = "" unless defined($verAnyStr);
     my $ver = $self->getVersion();
-    return (defined $ver) ? "${verPrefix}${ver}" : $verAnyStr;
+    if (defined $ver) {
+        if ($ver ne "") {
+            return "${verPrefix}${ver}";
+        } else {
+            return "";
+        }
+    } else {
+        return $verAnyStr;
+    }
 }
 
 sub CHLicenses::LicenseBase::getID($) {
@@ -143,25 +151,46 @@
 }
 
 sub CHLicenses::LicenseBase::getNiceFoundInText($$) {
-    my ($text, $limit) = ($_[0]->getFoundInText(), $_[1]);
-    my @words = split(/\s+/, $text);
-    my $line = "";
+    my ($text, $limit) = ($_[0]->getFoundInText(), $_[1], $_[2]);
+
+    my @parags;
+    my $parag = "";
+    my $lastplen = 0;
+    for my $p (split(/\n/, $text)) {
+        if (!$p || $p =~ /^\s+$/) {
+            push @parags, $parag if ($parag);
+            $parag = "";
+        } elsif (length($p) < $lastplen * 0.70) {
+            push @parags, $parag . " $p";
+            $parag = "";
+        } else {
+            $parag .= " $p";
+            $lastplen = length($p);
+        }
+    }
+    push @parags, $parag if ($parag);
+
     my @lines = ();
-    for my $w (@words) {
-        if ((length($line) + length($w) + 1) > $limit) {
-            push @lines, $line;
-            $line = "";
+    for $parag (@parags) {
+        my @words = split(/\s+/, $parag);
+        my $line = "";
+        for my $w (@words) {
+            if ((length($line) + length($w) + 1) > $limit) {
+                push @lines, $line;
+                $line = "";
+            }
+            if ($line) {
+                $line .= " " . "$w";
+            } else {
+                $line = "$w";
+            }
         }
         if ($line) {
-            $line .= " " . "$w";
-        } else {
-            $line = "$w";
+            push @lines, $line;
         }
+        push @lines, "";
     }
-    if ($line) {
-        push @lines, $line;
-    }
-
+    pop @lines; # remove last "\n"
     return @lines;
 }
 
@@ -196,6 +225,10 @@
         $indent, $self->getLicenseDebianLocation());
 }
 
+sub CHLicenses::LicenseBase::areLicenseTermsLink {
+    1;
+}
+
 sub CHLicenses::LicenseBase::getLicenseDebianLocation {
     my $self = shift;
     if ($self->getVersion()) {

Modified: people/modax/copyright-helper/trunk/copyright-helper.pl
===================================================================
--- people/modax/copyright-helper/trunk/copyright-helper.pl	2009-01-25 22:49:27 UTC (rev 13559)
+++ people/modax/copyright-helper/trunk/copyright-helper.pl	2009-01-25 22:57:09 UTC (rev 13560)
@@ -221,7 +221,7 @@
 }
 
 # Entry point
-${main::VERSION}='0.5.2';
+${main::VERSION}='0.5.3';
 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/bsd.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/bsd.pm	2009-01-25 22:49:27 UTC (rev 13559)
+++ people/modax/copyright-helper/trunk/licenses/bsd.pm	2009-01-25 22:57:09 UTC (rev 13560)
@@ -39,11 +39,24 @@
 # This product includes software developed by the University of
 # California, Berkeley and its contributors.
 
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE
+
 my $P1_RE = qr/\bRedistribution\b.*\bsource\b.*\bbinary\b.*\bwith\b.*\bwithout\b.*\bmodification\b.*\bpermitted\b.*\bprovided\b.*conditions?\b.*\bmet\b/is;
 my $P2_RE = qr/\bRedistributions?\b.*\bsource\W+code\b.*\bmust\b.*\bretain\b.*\bcopyright\b.*\bnotice\b.*\bconditions\b/is;
 my $P3_RE = qr/\bRedistributions?\b.*\bbinary\b.*\bmust\b.*\bcopyright\b.*\bnotice\b.*\bconditions\b.*\bdisclaimer\b.*\bdocumentation\b.*\bdistribution/is;
 my $P4_RE = qr/\bNeither\b.*\bname\b.*\bendorse\b.*\bpromote\b.*\bproducts\b.*\bwritten\b.*\bpermissions?\b/is;
 my $ADV_RE = qr/\badvertising\b.*\bfeatures\b.*\bmust\b.*\bdisplay\b.*\backnowledge.*\bpermissions?\b/is;
+my $AS_IS_RE = qr/\bTHIS SOFTWARE IS PROVIDED\b.*\bAS IS\b.*IN NO EVENT\b.*\bBE LIABLE\b/s;
 
 sub getPriority {
     50;
@@ -53,8 +66,9 @@
     my ($self, $text) = @_;
     my $advertising;
     my $score = 0;
-    my $foundInText = "";
+    my @foundInText;
     my ($p1, $p2, $p3, $p4);
+    my $p5 = 0;
     for my $p (@$text) {
         my $foundhere;
 
@@ -87,8 +101,18 @@
             $foundhere = 1;
 #            print STDERR "score (adv):", $score, "\n";
         }
-        $foundInText .= $p;
-        last if ($score >= 9);
+        if ($p =~ $AS_IS_RE) {
+            $foundhere = 1;
+            $p5 = 2;
+        }
+        push @foundInText, $p if ($foundhere);
+        if ($score >= 9) {
+            if ($p5 >= 2) {
+                last;
+            } else {
+                $p5++;
+            }
+        }
     }
     if ($score >= 5) {
         my $license = new CHLicenses::bsd;
@@ -97,7 +121,7 @@
         } else {
             $license->{version} = ""; # No version
         }
-        $license->{foundInText} = $foundInText;
+        $license->{foundInText} = join("\n\n", @foundInText);
         $license->{bsd_score} = $score;
         return $license;
     } else {

Modified: people/modax/copyright-helper/trunk/licenses/mit.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/mit.pm	2009-01-25 22:49:27 UTC (rev 13559)
+++ people/modax/copyright-helper/trunk/licenses/mit.pm	2009-01-25 22:57:09 UTC (rev 13560)
@@ -32,8 +32,18 @@
 # The above copyright notice and this permission notice shall be
 # included in all copies or substantial portions of the Software
 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE
+
 my $P1_RE = qr/\bPermission\b.*\bgranted\b.*\bfree\s+of\s+charge\b.*\bcopy\b.*\bsoftware\b.*\bdocumentation\b.*\bwithout\s+restriction\b.*\bwithout\b.*\blimitations?\b.*\bcopy\b.*\bmodify\b.*\bdistribute\b.*\bsubject\b.*\bconditions?\b/is;
 my $P2_RE = qr/\bcopyright\b.*\bnotice\b.*\bpermission\b.*\bincluded\b.*\bcopies\b.*\bSoftware\b/is;
+my $AS_IS_RE = qr/\bSOFTWARE IS PROVIDED\b.*\bAS IS\b.*\bWITHOUT WARRANTY OF ANY KIND\b/s;
 
 sub getPriority {
     60;
@@ -42,8 +52,10 @@
 sub matchCopyrightedFile($\@) {
     my ($self, $text) = @_;
     my $score = 0;
-    my $foundInText = "";
+    my @foundInText;
     my ($p1, $p2);
+    my $p3 = 0;
+
     for my $p (@$text) {
         my $foundhere;
 
@@ -59,13 +71,23 @@
             $p2 = 1;
 #            print STDERR "score 2:", $score, "\n";
         }
-        $foundInText .= $p;
-        last if ($score >= 3);
+        if ($p =~ $AS_IS_RE) {
+            $foundhere = 1;
+            $p3 = 2;
+        }
+        push @foundInText, $p if ($foundhere);
+        if ($score >= 3) {
+            if ($p3 >= 2) {
+                last;
+            } else {
+                $p3++;
+            }
+        }
     }
     if ($score >= 2) {
         my $license = new CHLicenses::mit;
         $license->{version} = ""; # No version
-        $license->{foundInText} = $foundInText;
+        $license->{foundInText} = join("\n\n", @foundInText);
         $license->{mit_score} = $score;
         return $license;
     } else {
@@ -113,3 +135,7 @@
 ${indent}OTHER DEALINGS IN THE SOFTWARE.
 END
 }
+
+sub areLicenseTermsLink {
+    0;
+}




More information about the pkg-kde-commits mailing list