pmReplaceCopyright.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 import os, sys
00024
00025
00026 PoaC_COPYRIGHT = """# This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00027 #
00028 # This file is part of the Python-on-a-Chip program.
00029 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00030 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00031 #
00032 # Python-on-a-Chip is distributed in the hope that it will be useful,
00033 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00034 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00035 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00036 # is seen in the file COPYING up one directory from this.
00037 """
00038
00039 PM_COPYRIGHT = """# This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00040 #
00041 # This file is part of the PyMite VM.
00042 # The PyMite VM is free software: you can redistribute it and/or modify
00043 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
00044 #
00045 # The PyMite VM is distributed in the hope that it will be useful,
00046 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00047 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00048 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
00049 # is seen in the file COPYING in this directory.
00050 """
00051
00052 COPYRIGHT = PM_COPYRIGHT
00053
00054
00055 def replace_copyright(fn):
00056 ext = os.path.splitext(fn)[1]
00057 if ext == ".c" or ext == ".h" or ".c." in fn:
00058 lines = open(fn, 'rb').readlines()
00059 if lines[0] == "/*\n" and lines[5] == " */\n":
00060 lines[0:6] = ("/*\n", COPYRIGHT, "*/\n")
00061 else:
00062 print "Did not modify %s" % fn
00063
00064 elif ext == ".py":
00065 lines = open(fn, 'rb').readlines()
00066 if lines[0] == "#\n" and lines[5] == "#\n":
00067 lines[0:6] = (COPYRIGHT, )
00068 else:
00069 print "Did not modify %s" % fn
00070
00071 open(fn, 'wb').writelines(lines)
00072
00073
00074 if __name__ == "__main__":
00075 map(replace_copyright, sys.argv[1:])