Commits

Mats Lidell committed c15cc21

The version used for the first bulk GPLv2 or later move

  • Participants
  • Parent commits cf8cc1f

Comments (0)

Files changed (3)

File matsl/gplv3/ChangeLog

-2009-03-05  Mats Lidell  <mats.lidell@cag.se>
+2010-10-14  Mats Lidell  <matsl@xemacs.org>
+
+	* substgplv2: Version used to do the first GPLv3 or later move.
+	* nonsense.py: Support file of limited value.
+
+2009-03-05  Mats Lidell  <matsl@xemacs.org>
 
 	* findgplv2 (checkGPLv2): Verbose on lgplv2 should say just that. 
 	(findFiles): Be verbose on ignored files as well.

File matsl/gplv3/nonsense.py

+# This is a dictionary of files that has no license ...
+
+# Explanation...
+NL = "No license"
+LISPREF_TEXI = "see lispref.texi for copyright, not version 2 or later!?"
+
+nonsense = { 
+    './src/m/is386.h': NL,
+    './man/make-stds.texi' : NL,
+    "./man/lispref/back.texi" : NL,
+}	 
+

File matsl/gplv3/substgplv2

+#!/bin/env python
+
+# Find files that are gplv2 or not and as an option substitute a new
+# GPLv3 or later license on some of the files...
+
+# This 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, or (at your option)
+# any later version.
+
+import sys
+import os
+import re
+import getopt
+
+import nonsense
+
+maxSearchLines = 200
+
+# options
+substitute = False
+
+# Don't recurse down these folders
+ignoreDirNames = re.compile('\.|\.\.|\.hg|CVS')
+
+# Don't bother with these files at all.
+ignoreFiles = re.compile('.*\.(bmp|gpg|ico|png|ps\.gz|xbm|xpm|orig)$|\.(cvs|hg)(ignore|tags)|README.*|.*(~|ChangeLog|NEWS)|depend|dir|install-sh|COPYING')
+
+## gplv2 = re.compile('GNU General Public License as published by the Free Software Foundation; either version(|s) 2(| of the License), or \(at your option\) any later version\.')
+## lgplv2 = re.compile('GNU Library General Public License as published by the Free Software Foundation; either version 2(| of the License), or \(at your option\) any later version\.')
+
+# Generic copyleft
+genericCopyleft = """This file is part of XEmacs.
+
+XEmacs 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.
+
+XEmacs 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 XEmacs.  If not, see <http://www.gnu.org/licenses/>."""
+
+def insertPrefixCommentChar(text, prefix):
+    return prefix + ("\n" + prefix).join(text.split('\n'))
+
+def removeCommentWhitespaceLines(prefix, text):
+    p = re.compile(prefix + "[ \t]*\n")
+    return p.sub("\n", text)
+
+# Leading comment remover
+leadingComment = re.compile('^\s*[*#;]+')
+
+def removeLeadingComment(s):
+    m = leadingComment.match(s)
+    if m:
+        return s[m.end(0):]
+    else:
+        return s
+
+# Turn file into one long string
+def fileToStr(f):
+    ln = 0
+    lines = []
+    fp = open(f)
+    for line in fp:
+        l = removeLeadingComment(line[:-1])
+        lines.append(l.strip())
+        ln += 1
+        if maxSearchLines < ln:
+            break
+    fp.close()
+    return ' '.join(lines)
+
+def findFiles(p):
+    for f in os.listdir(p):
+        fn = os.path.join(p, f)
+        isdir = os.path.isdir(fn)
+
+        if (not isdir and ignoreFiles.match(f)) or (isdir and ignoreDirNames.match(f)):
+            if verbose: printFile("no(C)", fn, None, "ignored", None)
+            continue
+
+        if isdir:
+            findFiles(fn)
+            continue
+
+        # checkGPLv2(fn)
+        checkFile(fn)
+
+### Patterns - List of license patterns defined by the tripple:
+### regular expression matching the license, the name of the license
+### and finally a potential substitution. If substitution is None then
+### there will be no substitution!
+
+licensePatterns = [
+
+# Pattern zero...
+[
+"""This file is part of (GNU |X)Emacs.
+
+\s*(GNU |X)Emacs is free software; you can redistribute it and/or modify\s+it\s+under the terms of the GNU General Public License as published by\s+the\s+Free Software Foundation; either version 2, or \(at your option\)\s+any\s+later version.
+
+\s*(GNU |X)Emacs is distributed in the hope that it will be useful,\s+but\s+WITHOUT\s+ANY WARRANTY; without even the implied warranty of\s+MERC(HA|)NTABILITY or\s+FITNESS FOR A PARTICULAR PURPOSE.  See the\s+GNU\s+General Public License\s+for more details.\s*
+\s*You should have received a copy of the GNU General Public License
+\s*along with (GNU |X)Emacs; see the file COPYING.  If not, write to\s+the\s+Free\s+Software Foundation, Inc., 5(9 Temple Place - Suite 330|1 Franklin Street, Fifth Floor),\s+Boston, MA\s+0211[01]-130[17], USA.\s*\*/
+""",
+"gplv2",
+genericCopyleft + " */\n",
+],
+
+# Pattern one...
+[
+"""This file is part of (GNU |X)Emacs.
+
+(GNU |X)Emacs is free software; you can redistribute it and/or modify\s+it\s+under the terms of the GNU General Public License as published by\s+the\s+Free Software Foundation; either version 2, or \(at your option\)\s+any\s+later version.
+
+(GNU |X)Emacs is distributed in the hope that it will be useful,\s+but\s+WITHOUT\s+ANY WARRANTY; without even the implied warranty of\s+MERC(HA|)NTABILITY or\s+FITNESS FOR A PARTICULAR PURPOSE.  See the\s+GNU\s+General Public License\s+for more details.\s*
+You should have received a copy of the GNU General Public License
+along with (GNU |X)Emacs; see the file COPYING.  If not, write to\s+the\s+Free\s+Software Foundation, Inc., 5(9 Temple Place - Suite 330|1 Franklin Street, Fifth Floor),\s+Boston, MA\s+0211[01]-130[17], USA.
+""",
+"gplv2",
+genericCopyleft,
+],
+
+# Pattern two...
+[
+"""\s*This file is part of (GNU |X)Emacs.
+
+\s*(GNU |X)Emacs is free software; you can redistribute it and/or modify\s+it\s+under the terms of the GNU General Public License as published by\s+the\s+Free Software Foundation; either version 2, or \(at your option\)\s+any\s+later version.
+
+\s*(GNU |X)Emacs is distributed in the hope that it will be useful,\s+but WITHOUT\s+ANY WARRANTY; without even the implied warranty of\s+MERCHANTABILITY or\s+FITNESS FOR A PARTICULAR PURPOSE.  See the\s+GNU General Public License\s+for more details.
+
+\s*You should have received a copy of the GNU General Public License
+\s*along with (GNU |X)Emacs; see the file COPYING.  If not, write to\s+the Free\s+Software Foundation, Inc., 59 Temple Place - Suite 330,\s+Boston, MA\s+02111-1307, USA.
+""",
+"gplv2",
+None,
+],
+
+# Pattern three...
+[
+"""   This program is free software; you can redistribute it and/or modify\s+it\s+under the terms of the GNU General Public License as published by\s+the\s+Free Software Foundation; either version 2, or \(at your option\)\s+any\s+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;( see the file COPYING.|)\s+[Ii]f not, write to\s+the Free Software Foundation,\s+Inc., 59 Temple Place - Suite 330,\s+Boston, MA 02111-1307, USA.\s+\*/
+""",
+"gplv2",
+insertPrefixCommentChar(genericCopyleft, "   ") + " */",
+],
+
+# Pattern four...
+[
+"""# This file is part of (GNU |X)Emacs.
+(#|\s)*
+# (GNU |X)Emacs is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by(\s|#)+the(\s|#)+Free Software Foundation; either version 2, or \(at your(\s|#)+option\)(\s|#)+any(\s|#)+later version.
+(#|\s)*
+# (GNU |X)Emacs is distributed in the hope that it will be useful, but(\s|#)+WITHOUT(\s|#)+ANY WARRANTY; without even the implied warranty of(\s|#)+MERCHANTABILITY or(\s|#)+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU(\s|#)+General Public License(\s|#)+for more details.
+(#|\s)*
+# You should have received a copy of the GNU General Public License
+# along with (GNU |X)Emacs; see the file COPYING.  If not, write to(\s|#)+the Free(\s|#)+Software Foundation, Inc., .*(\s|#)+Boston.*USA(\.|)
+""",
+"gplv2",
+insertPrefixCommentChar(genericCopyleft, "# ") + "\n",
+],
+
+# Pattern five...
+[
+"""## This file is part of (GNU |X)Emacs.
+
+## (GNU |X)Emacs is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by(\s|#)+the(\s|#)+Free Software Foundation; either version 2, or \(at your option\)(\s|#)+any(\s|#)+later version.
+
+## (GNU |X)Emacs is distributed in the hope that it will be useful, but(\s|#)+WITHOUT(\s|#)+ANY WARRANTY; without even the implied warranty of(\s|#)+MERCHANTABILITY or(\s|#)+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU(\s|#)+General Public License(\s|#)+for more details.
+
+## You should have received a copy of the GNU General Public License
+## along with (GNU |X)Emacs; see the file COPYING.  If not, write to(\s|#)+the Free(\s|#)+Software Foundation, Inc., (59 Temple Place - Suite 330,|51 Franklin Street, Fifth Floor,)(\s|#)+Boston, MA(\s|#)+( 02110-1301 |02111-1307,) USA(.|)
+""",
+"gplv2",
+removeCommentWhitespaceLines("## ", insertPrefixCommentChar(genericCopyleft, "## ")) +"\n",
+],
+
+# Pattern six...
+[
+"""# 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 2, 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, you can either send email to this
+# program's maintainer or write to: The Free Software Foundation,
+# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
+""",
+"gplv2",
+removeCommentWhitespaceLines("# ", insertPrefixCommentChar(genericCopyleft, "# ")) + "\n",
+],
+
+# Pattern seven...
+[
+"""; This file is part of (GNU |X)Emacs.
+;
+; (GNU |X)Emacs 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 2, or \(at your option\) any
+; later version.
+;
+; (GNU |X)Emacs 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 (GNU |X)Emacs; see the file COPYING.  If not, write to
+; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+; Boston, MA 02111-1307, USA.
+""",
+"gplv2",
+removeCommentWhitespaceLines("; ", insertPrefixCommentChar(genericCopyleft, "; ")) + "\n",
+],
+
+# Pattern eigth...
+[
+""";; This file is (NOT |)part of (GNU |X|SX)Emacs.
+(;;|\s*)
+;; (GNU |X|SX)Emacs is free software; you can redistribute it and/or modify(\s|;)+it(\s|;)+under the terms of the GNU General Public License as published by(\s|;)+the(\s|;)+Free Software Foundation; either version 2, or(\s|;)+\(at your option\)(\s|;)+any(\s|;)+later version.
+(;;|\s*)
+;; (GNU |X|SX)Emacs is distributed in the hope that it will be useful,(\s|;)+but(\s|;)+WITHOUT(\s|;)+ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or(\s|;)+FITNESS FOR A PARTICULAR PURPOSE.  See the(\s|;)+GNU(\s|;)+General Public License(\s|;)+for more details.
+(;;|\s*)
+;; You should have received a copy of the GNU General Public License
+;; along with (GNU |X|SX)(E|)macs; (see the file COPYING.  |)[Ii]f not,.*(\s|;)+.*Software(\s|;)+Foundation,.*(\s|;)+.*(\s|;)+.*USA\..*
+""",
+"gplv2",
+removeCommentWhitespaceLines(";; ", insertPrefixCommentChar(genericCopyleft, ";; ")) + "\n",
+],
+
+# Pattern nine...
+[
+""";;; This file is part of (GNU |X)Emacs.
+(;;;|\s*)
+;;; (GNU |X)Emacs is free software; you can redistribute it and/or modify(\s|;)+it(\s|;)+under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2, or \(at your(\s|;)+option\)(\s|;)+any later version.
+(;;;|\s*)
+;;; (GNU |X)Emacs is distributed in the hope that it will be useful,(\s|;)+but(\s|;)+WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the(\s|;)+GNU(\s|;)+General Public License for more details.
+(;;;|\s*)
+;;; You should have received a copy of the GNU General Public License
+;;; along with (GNU |X)Emacs; see the file COPYING.  If not, write to.*(\s|;)+.*Software Foundation,.*(\s|;)+.*(\s|;)+.*USA\..*
+""",
+"gplv2",
+removeCommentWhitespaceLines(";;; ", insertPrefixCommentChar(genericCopyleft, ";; ")) + "\n",
+],
+
+# Pattern ten...
+[
+"""This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or \(at your option\) any later version.
+
+This library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; if not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. \*/
+
+""",
+"lgplv2",
+None,
+],
+
+# Pattern eleven...
+[
+"""This file is not considered part of GNU Emacs.
+
+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 2 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, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+""",
+"gplv2",
+genericCopyleft,
+],
+
+# Pattern twelve...
+[
+"""    (This document|XEmacs) is free software; you can redistribute it and/or modify\s+it\s+under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2( of the License|), or\s+\(at your option\)\s+any later version.
+
+    (This program|XEmacs) is distributed in the hope that it will be useful,\s+but\s+WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\s+GNU\s+General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with (this program|XEmacs);( see the file COPYING.|)\s+[Ii]f not, write to the\s+Free Software\s+Foundation, Inc., 5(1 Franklin St, Fifth Floor,|9 Temple Place - Suite 330,)\s+Boston, MA\s+(02110-1301 |02111-1307,) USA\.?
+""",
+"gplv2",
+removeCommentWhitespaceLines("    ", insertPrefixCommentChar(genericCopyleft, "    ")),
+],
+
+# Pattern thirteen...
+["""@c See the file lispref.texi for copying conditions.""",
+ "copyleft",
+ None,
+],
+
+# Pattern forteen...
+["""([Cc]opyright|COPYRIGHT)""",
+ "unknown(C)",
+ None,
+]
+
+]
+
+def printFile(category, fn, extra, pattern, substitution):
+    print (category + ":").ljust(12), ('"' + fn + '"').ljust(50),
+    if extra:
+        print ("-> " + extra).ljust(15),
+    else:
+        print "".ljust(15),
+    if pattern:
+        print "Match:" + pattern + "\t",
+        if substitution:
+            print ""
+        else:
+            print "No subst"
+    else:
+        print
+
+def checkGPLv2(f):
+    text = open(f).read();
+    for pos, copy in zip(range(len(licensePatterns)), licensePatterns):
+        pat = re.compile(copy[0])
+        m = pat.search(text)
+        if m:
+            # We got a match
+            printFile(copy[1], f, None, str(pos), copy[2])
+            assert(not f in nonsense.nonsense)
+            return pos
+    if f in nonsense.nonsense:
+        printFile("?!!", f, nonsense.nonsense[f], "Nonsense", None)
+    else:
+        printFile("?", f ,None, None, None)
+    return -1
+
+def substFile(f):
+    text = open(f).read();
+    for pos, pair in zip(range(len(licensePatterns)), licensePatterns):
+        newtext = substFile_(text, re.compile(pair[0]), pair[2])
+        if len(newtext):
+            return newtext
+
+def substFile_(text, p, subst):
+    m = p.search(text)
+    if m:
+        # print "It was a match", m.span()
+        start, stop = m.span()
+        return text[0:start] + subst + text[stop:-1]
+    else:
+        return ""
+
+def checkFile(f):
+    match = checkGPLv2(f)
+    if substitute and match >= 0:
+        if licensePatterns[match][2] == None:
+            print "File: " + f + " NO SUBSTITUTION DEFINED"
+        else:
+            text = substFile(f) + "\n"
+            os.rename(f, f + ".orig")
+            fd = open(f, "w")
+            fd.write(text)
+            fd.close()
+            print "File: " + f + " subsituted\n"
+
+def usage():
+    print os.path.basename(sys.argv[0]) + " [-h|--help] [-v|--verbose] [-s|--subsitute] [file]"
+    print " - With file dumps stringified version of it to stdout for inspection"
+
+def main():
+    global verbose, substitute
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hvs", ["help", "verbose", "subsitute"])
+    except getopt.GetoptError, err:
+        print str(err)
+        usage()
+        sys.exit(2)
+    verbose = False
+    for o, a in opts:
+        if o in ["-v", "--verbose"]:
+            verbose = True
+        elif o in ["-s", "--subsitute"]:
+            substitute = True
+        elif o in ("-h", "--help"):
+            usage()
+            sys.exit()
+        else:
+            assert False, "unhandled option"
+
+    if len(args) == 1:
+        verbose = True
+        checkFile(args[0])
+    else:
+        findFiles('.')
+        pass
+
+if __name__ == "__main__":
+    main()