| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | import os |
|---|
| 5 | import re |
|---|
| 6 | |
|---|
| 7 | DIRS = [ |
|---|
| 8 | 'src', |
|---|
| 9 | ] |
|---|
| 10 | |
|---|
| 11 | LICENSE = """boc-flash |
|---|
| 12 | Copyright (C) 2008-2009 Bolloré telecom |
|---|
| 13 | See AUTHORS file for a full list of contributors. |
|---|
| 14 | |
|---|
| 15 | This program is free software: you can redistribute it and/or modify |
|---|
| 16 | it under the terms of the GNU General Public License as published by |
|---|
| 17 | the Free Software Foundation, either version 3 of the License, or |
|---|
| 18 | (at your option) any later version. |
|---|
| 19 | |
|---|
| 20 | This program is distributed in the hope that it will be useful, |
|---|
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | GNU General Public License for more details. |
|---|
| 24 | |
|---|
| 25 | You should have received a copy of the GNU General Public License |
|---|
| 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 27 | """ |
|---|
| 28 | |
|---|
| 29 | START = "/*\n" |
|---|
| 30 | END = " */\n\n" |
|---|
| 31 | |
|---|
| 32 | NOTICE = START |
|---|
| 33 | for i in LICENSE.splitlines(): |
|---|
| 34 | NOTICE += " * %s\n" % i |
|---|
| 35 | NOTICE += END |
|---|
| 36 | |
|---|
| 37 | def findsource(dir, recurse=False): |
|---|
| 38 | out = [] |
|---|
| 39 | for entry in os.listdir(dir): |
|---|
| 40 | path = os.path.join(dir, entry) |
|---|
| 41 | if re.match('.*\.(c|cc|cpp|h|js)$', entry) and os.path.isfile(path): |
|---|
| 42 | out.append(path) |
|---|
| 43 | elif recurse and entry != '.svn' and os.path.isdir(path): |
|---|
| 44 | out.extend(findsource(path)) |
|---|
| 45 | return out |
|---|
| 46 | |
|---|
| 47 | files = [] |
|---|
| 48 | for dir in DIRS: |
|---|
| 49 | files.extend(findsource(dir)) |
|---|
| 50 | |
|---|
| 51 | for file in files: |
|---|
| 52 | print("processing %s" % file) |
|---|
| 53 | orig = open(file, 'r').read() |
|---|
| 54 | if orig.startswith(START): |
|---|
| 55 | new = NOTICE + orig[orig.index(END) + len(END):] |
|---|
| 56 | else: |
|---|
| 57 | new = NOTICE + orig |
|---|
| 58 | |
|---|
| 59 | if new != orig: |
|---|
| 60 | print "Updating %s" % file |
|---|
| 61 | open(file, 'w').write(new) |
|---|