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

Modestas Vainius modax-guest at alioth.debian.org
Sun Jan 25 15:03:46 UTC 2009


Author: modax-guest
Date: 2009-01-25 15:03:46 +0000 (Sun, 25 Jan 2009)
New Revision: 13536

Added:
   people/modax/copyright-helper/trunk/licenses/mit.pm
Modified:
   people/modax/copyright-helper/trunk/CHLicenses.pm
   people/modax/copyright-helper/trunk/licenses/bsd.pm
   people/modax/copyright-helper/trunk/licenses/gnugpl.pm
   people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
Log:
Add support for MIT-like licenses. Prioritize license parses for faster parsing

Modified: people/modax/copyright-helper/trunk/CHLicenses.pm
===================================================================
--- people/modax/copyright-helper/trunk/CHLicenses.pm	2009-01-25 15:02:25 UTC (rev 13535)
+++ people/modax/copyright-helper/trunk/CHLicenses.pm	2009-01-25 15:03:46 UTC (rev 13536)
@@ -37,9 +37,11 @@
             require "$f";
             my $parser = new $class;
             push @parsers, $parser;
-            print STDERR $parser->getShortName(), ".\n";
+            print STDERR $parser->getShortName(), " (prio ", $parser->getPriority(), ").\n";
         }
     }
+    # Sort parsers by priority
+    @parsers = sort { $a->getPriority() <=> $b->getPriority() } @parsers;
 }
 
 sub all_license_parsers() {
@@ -82,6 +84,12 @@
     return "Long license name not specified";
 }
 
+sub CHLicenses::LicenseBase::getPriority($) {
+    # Lower values mean the license module will
+    # be consulted earlier while parsing
+    99;
+}
+
 sub CHLicenses::LicenseBase::formatVersion($$$) {
     my ($self, $verPrefix, $verAnyStr) = @_;
     $verAnyStr = "" unless defined($verAnyStr);

Modified: people/modax/copyright-helper/trunk/licenses/bsd.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/bsd.pm	2009-01-25 15:02:25 UTC (rev 13535)
+++ people/modax/copyright-helper/trunk/licenses/bsd.pm	2009-01-25 15:03:46 UTC (rev 13536)
@@ -45,6 +45,10 @@
 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;
 
+sub getPriority {
+    50;
+}
+
 sub matchCopyrightedFile($\@) {
     my ($self, $text) = @_;
     my $advertising;

Modified: people/modax/copyright-helper/trunk/licenses/gnugpl.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/gnugpl.pm	2009-01-25 15:02:25 UTC (rev 13535)
+++ people/modax/copyright-helper/trunk/licenses/gnugpl.pm	2009-01-25 15:03:46 UTC (rev 13536)
@@ -18,6 +18,10 @@
 use CHLicenses;
 our @ISA = qw( CHLicenses::LicenseBase );
 
+sub getPriority {
+    10;
+}
+
 sub matchCopyrightedFile($\@) {
     my ($self, $text) = @_;
     my $i = 0;

Modified: people/modax/copyright-helper/trunk/licenses/gnulgpl.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/gnulgpl.pm	2009-01-25 15:02:25 UTC (rev 13535)
+++ people/modax/copyright-helper/trunk/licenses/gnulgpl.pm	2009-01-25 15:03:46 UTC (rev 13536)
@@ -18,6 +18,10 @@
 use CHLicenses;
 our @ISA = qw( CHLicenses::LicenseBase );
 
+sub getPriority {
+    12;
+}
+
 sub matchCopyrightedFile($\@) {
     my ($self, $text) = @_;
     for my $p (@$text) {

Added: people/modax/copyright-helper/trunk/licenses/mit.pm
===================================================================
--- people/modax/copyright-helper/trunk/licenses/mit.pm	                        (rev 0)
+++ people/modax/copyright-helper/trunk/licenses/mit.pm	2009-01-25 15:03:46 UTC (rev 13536)
@@ -0,0 +1,115 @@
+# Copyright (C) 2008-2009 Modestas Vainius <modestas at vainius.eu>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+
+package CHLicenses::mit;
+use strict;
+use CHLicenses;
+our @ISA = qw( CHLicenses::LicenseBase );
+
+# Preamle is usually like:
+
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of 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;
+
+sub getPriority {
+    60;
+}
+
+sub matchCopyrightedFile($\@) {
+    my ($self, $text) = @_;
+    my $score = 0;
+    my $foundInText = "";
+    my ($p1, $p2);
+    for my $p (@$text) {
+        my $foundhere;
+
+        if (!$p1 && $p =~ $P1_RE) {
+            $score += 2;
+            $foundhere = 1;
+            $p1 = 1;
+#            print STDERR "score 1:", $score, "\n";
+        }
+        if (!$p2 && $p =~ $P2_RE) {
+            $score += 1;
+            $foundhere = 1;
+            $p2 = 1;
+#            print STDERR "score 2:", $score, "\n";
+        }
+        $foundInText .= $p;
+        last if ($score >= 3);
+    }
+    if ($score >= 2) {
+        my $license = new CHLicenses::mit;
+        $license->{version} = ""; # No version
+        $license->{foundInText} = $foundInText;
+        $license->{mit_score} = $score;
+        return $license;
+    } else {
+        return 0;
+    }
+}
+
+sub matchLicenseText($\@) {
+    my ($self, $text) = @_;
+    return $self->matchCopyrightedFile($text);
+}
+
+sub getShortName($) {
+    "MIT";
+}
+
+sub getLongName($) {
+    return "MIT-like License";
+}
+
+sub getLicenseTerms {
+    my ($self, $indent) = @_;
+    $indent = "" unless defined $indent;
+
+    return <<END
+${indent}Permission is hereby granted, free of charge, to any person
+${indent}obtaining a copy of this software and associated documentation
+${indent}files (the "Software"), to deal in the Software without
+${indent}restriction, including without limitation the rights to use,
+${indent}copy, modify, merge, publish, distribute, sublicense, and/or sell
+${indent}copies of the Software, and to permit persons to whom the
+${indent}Software is furnished to do so, subject to the following
+${indent}conditions:
+
+${indent}The above copyright notice and this permission notice shall be
+${indent}included in all copies or substantial portions of the Software.
+
+${indent}THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+${indent}EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+${indent}OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+${indent}NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+${indent}HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+${indent}WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+${indent}FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+${indent}OTHER DEALINGS IN THE SOFTWARE.
+END
+}




More information about the pkg-kde-commits mailing list