root/addcopyright

Revision a13581c9e2a3bf9273276d3e71c43dbe245a0938, 1.6 KB (checked in by Jeremy Lainé <jeremy.laine@…>, 3 years ago)

add script to update copyright headers

  • Property mode set to 100755
Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4import os
5import re
6
7DIRS = [
8    'src',
9]
10
11LICENSE = """boc-flash
12Copyright (C) 2008-2009 Bolloré telecom
13See AUTHORS file for a full list of contributors.
14
15This program is free software: you can redistribute it and/or modify
16it under the terms of the GNU General Public License as published by
17the Free Software Foundation, either version 3 of the License, or
18(at your option) any later version.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program.  If not, see <http://www.gnu.org/licenses/>.
27"""
28
29START = "/*\n"
30END = " */\n\n"
31
32NOTICE = START
33for i in LICENSE.splitlines():
34    NOTICE += " * %s\n" % i
35NOTICE += END
36
37def 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
47files = []
48for dir in DIRS:
49    files.extend(findsource(dir))
50
51for 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)
Note: See TracBrowser for help on using the browser.