diff options
author | Bernard Normier <bernard@zeroc.com> | 2004-04-28 23:05:00 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2004-04-28 23:05:00 +0000 |
commit | 8ec944533e230504a1fcf61a7527bb49356266b6 (patch) | |
tree | eb010e37b95f83565b198e4eb70d9e18ac43c8aa /cpp/fixCopyright.py | |
parent | cleaning up my previous fix (diff) | |
download | ice-8ec944533e230504a1fcf61a7527bb49356266b6.tar.bz2 ice-8ec944533e230504a1fcf61a7527bb49356266b6.tar.xz ice-8ec944533e230504a1fcf61a7527bb49356266b6.zip |
*** empty log message ***
Diffstat (limited to 'cpp/fixCopyright.py')
-rwxr-xr-x | cpp/fixCopyright.py | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/cpp/fixCopyright.py b/cpp/fixCopyright.py new file mode 100755 index 00000000000..c94aa47f48c --- /dev/null +++ b/cpp/fixCopyright.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python + +import os, sys, shutil, fnmatch, re, glob + +# +# Program usage. +# +def usage(): + print "Usage: " + sys.argv[0] + " [options] [path]" + print + print "Options:" + print "-h Show this message." + print + +# +# Returns the new copyright +# +def copyright(commentMark): + result = [ ] + result.append(commentMark) + result.append(" **********************************************************************\n") + result.append(commentMark) + result.append("\n") + result.append(commentMark) + result.append(" Copyright (c) 2003 - 2004\n") + result.append(commentMark) + result.append(" ZeroC, Inc.\n") + result.append(commentMark) + result.append(" North Palm Beach, FL, USA\n") + result.append(commentMark) + result.append("\n") + result.append(commentMark) + result.append(" All Rights Reserved.\n") + result.append(commentMark) + result.append("\n") + result.append(commentMark) + result.append(" This copy of Ice is licensed to you under the terms described in the\n") + result.append(commentMark) + result.append(" ICE_LICENSE file included in this distribution.\n") + result.append(commentMark) + result.append("\n") + result.append(commentMark) + result.append(" **********************************************************************\n") + return result + + +# +# Replace one copyright +# +def replaceCopyright(file, commentMark, commentBegin, commentEnd, newCopyrightLines): + oldFile = open(file, "r") + oldLines = oldFile.readlines() + + done = 0 + commentFound = 0 + copyrightFound = 0 + + beforeCopyrightLines = [] + newLines = [] + + if commentBegin == "": + for x in oldLines: + if not commentFound and not x.startswith(commentMark): + beforeCopyrightLines.append(x) + elif not done and x.startswith(commentMark): + commentFound = 1 + if not copyrightFound and x.lower().find("copyright") != -1: + copyrightFound = 1 + # skip this comment line + else: + done = 1 + newLines.append(x) + + else: + for x in oldLines: + if not done: + if x.startswith(commentBegin): + commentFound = 1 + if commentFound: + if not copyrightFound and x.find("Copyright") != -1: + copyrightFound = 1 + + # skip this comment line + if x.find(commentEnd) != -1: + done = 1 + else: + beforeCopyrightLines.append(x) + else: + newLines.append(x) + + + oldFile.close() + + if copyrightFound: + origFile = file + ".orig" + shutil.copy2(file, origFile) + + newFile = open(file, "w") + newFile.writelines(beforeCopyrightLines) + newFile.writelines(newCopyrightLines) + + # + # Hack to keep the .err files + # + if fnmatch.fnmatch(file, "*test/Slice/errorDetection/*.ice") != -1: + newFile.write("\n") + + newFile.writelines(newLines) + newFile.close() + + return copyrightFound + +# +# Replace alls copyrights +# +def replaceAllCopyrights(path): + + cppCopyright = copyright("//") + mcCopyright = copyright("; //") + makefileCopyright = copyright("#") + pythonCopyright = [] + pythonCopyright.append("#!/usr/bin/env python\n"); + pythonCopyright.extend(makefileCopyright) + xmlCopyright = [] + xmlCopyright.append("<!--\n"); + xmlCopyright.extend(copyright("")) + xmlCopyright.append("-->\n"); + + files = os.listdir(path) + for x in files: + fullpath = os.path.join(path, x); + if x == "CVS": + print "Skipping CVS directory" + elif os.path.isdir(fullpath) and not os.path.islink(fullpath): + replaceAllCopyrights(fullpath) + else: + + commentMark = "" + commentBegin = "" + commentEnd = "" + copyrightLines = [] + skip = 0 + + if x == "config" or x == ".depend" or x == ".dummy" or fnmatch.fnmatch(x, "*.dsp") or fnmatch.fnmatch(x, "*.sln") or fnmatch.fnmatch(x, "*.vdproj") or fnmatch.fnmatch(x, "*.err") or fnmatch.fnmatch(x, "*.class") or fnmatch.fnmatch(x, "*.ico") or fnmatch.fnmatch(x, "*.gif") or fnmatch.fnmatch(x, "*.jpg") or fnmatch.fnmatch(x, "*.orig"): + print "Skipping file " + fullpath + ": no copyright needed" + skip = 1 + elif fnmatch.fnmatch(x, "*.h") or fnmatch.fnmatch(x, "*.cpp") or fnmatch.fnmatch(x, "*.ice") or fnmatch.fnmatch(x, "*.java") or fnmatch.fnmatch(x, "*.l") or fnmatch.fnmatch(x, "*.y"): + commentMark = "//" + copyrightLines = cppCopyright + elif fnmatch.fnmatch(x, "*.py"): + commentMark = "#" + copyrightLines = pythonCopyright + elif fnmatch.fnmatch(x, "*.mc"): + commentMark = "; //" + copyrightLines = mcCopyright + elif fnmatch.fnmatch(x, "Make*") or fnmatch.fnmatch(x, "*.properties"): + commentMark = "#" + copyrightLines = makefileCopyright + elif x == "build.xml": + commentBegin = "<!--" + commentEnd = "-->" + copyrightLines = xmlCopyright + else: + print "***** Skipping file " + fullpath + ": unknown type" + skip = 1 + + if not skip: + if replaceCopyright(fullpath, commentMark, commentBegin, commentEnd, copyrightLines): + print "Replaced copyright in " + fullpath + else: + print "***** WARNING: Did not find copyright in " + fullpath + +# +# Main +# + +path = "." + +for x in sys.argv[1:]: + if x == "-h": + usage() + sys.exit(0) + elif x.startswith("-"): + print sys.argv[0] + ": unknown option `" + x + "'" + print + usage() + sys.exit(1) + else: + path = x + +replaceAllCopyrights(path) |