pmReplaceCopyright.py

Go to the documentation of this file.
00001 # This file is Copyright 2009, 2010 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 ## @file
00014 #  @copydoc pmReplaceCopyright
00015 
00016 ## @package pmReplaceCopyright
00017 #  @brief This program naively replaces the copyright header of a c, h or py file.
00018 #
00019 #  Once this program is used on the source tree, it will no longer work
00020 #  because the copyright header will have changed size.
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:])

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9