LP-295: uncrustify
[librepilot.git] / flight / libraries / PyMite / tools / pmReplaceCopyright.py
blobb45607cd518c0e2987b0073b0e5e8f70adb6a7b4
1 # This file is Copyright 2009, 2010 Dean Hall.
3 # This file is part of the Python-on-a-Chip program.
4 # Python-on-a-Chip is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
7 # Python-on-a-Chip is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
11 # is seen in the file COPYING up one directory from this.
13 ## @file
14 # @copydoc pmReplaceCopyright
16 ## @package pmReplaceCopyright
17 # @brief This program naively replaces the copyright header of a c, h or py file.
19 # Once this program is used on the source tree, it will no longer work
20 # because the copyright header will have changed size.
23 import os, sys
26 PoaC_COPYRIGHT = """# This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
28 # This file is part of the Python-on-a-Chip program.
29 # Python-on-a-Chip is free software: you can redistribute it and/or modify
30 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
32 # Python-on-a-Chip is distributed in the hope that it will be useful,
33 # but WITHOUT ANY WARRANTY; without even the implied warranty of
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
36 # is seen in the file COPYING up one directory from this.
37 """
39 PM_COPYRIGHT = """# This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
41 # This file is part of the PyMite VM.
42 # The PyMite VM is free software: you can redistribute it and/or modify
43 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
45 # The PyMite VM is distributed in the hope that it will be useful,
46 # but WITHOUT ANY WARRANTY; without even the implied warranty of
47 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
48 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
49 # is seen in the file COPYING in this directory.
50 """
52 COPYRIGHT = PM_COPYRIGHT
55 def replace_copyright(fn):
56 ext = os.path.splitext(fn)[1]
57 if ext == ".c" or ext == ".h" or ".c." in fn:
58 lines = open(fn, 'rb').readlines()
59 if lines[0] == "/*\n" and lines[5] == " */\n":
60 lines[0:6] = ("/*\n", COPYRIGHT, "*/\n")
61 else:
62 print "Did not modify %s" % fn
64 elif ext == ".py":
65 lines = open(fn, 'rb').readlines()
66 if lines[0] == "#\n" and lines[5] == "#\n":
67 lines[0:6] = (COPYRIGHT, )
68 else:
69 print "Did not modify %s" % fn
71 open(fn, 'wb').writelines(lines)
74 if __name__ == "__main__":
75 map(replace_copyright, sys.argv[1:])