OSDN Git Service

drop support for static text [ci reset]
[kde/Katie.git] / scripts / updatecopyright.py
1 #!/usr/bin/python
2
3 import os
4
5 licenses = ['BSD', 'FDL', 'LGPL']
6
7 lfiles = []
8 for root, subdirs, files in os.walk(os.curdir):
9     for sfile in files:
10         if sfile.endswith(('.cpp', '.h', '.js', '.qs', '.qml', '.ui', \
11             '.g', '.sh', '.cmake', '.pod', '.qdoc', '.c', '.xsl', '.xml', \
12             '.cmake')):
13             lfiles.append('%s/%s' % (root, sfile))
14
15 def readlicense(sfile, replacedashes, replacehashes):
16     sheader = ''
17     with open(sfile, 'r') as f:
18         shouldappend = False
19         for sline in f.readlines():
20             if 'QT_BEGIN_LICENSE' in sline:
21                 shouldappend = True
22             elif 'QT_END_LICENSE' in sline:
23                 sheader = '%s%s' % (sheader, sline)
24                 shouldappend = False
25             if shouldappend:
26                 sheader = '%s%s' % (sheader, sline)
27         if replacedashes:
28             sheader = sheader.replace('**', '--')
29         if replacehashes:
30             sheader = sheader.replace('**', '##')
31     return sheader
32
33 for sfile in lfiles:
34     with open(sfile, 'r') as f:
35         scontent = f.read()
36     for license in licenses:
37         if ('$QT_BEGIN_LICENSE:%s$' % license) in scontent:
38             snewheader = readlicense('%s/header.%s' % (os.curdir, license),
39                 sfile.endswith('.g'), sfile.endswith('.sh'))
40             soldheader = readlicense(sfile, False, False)
41             snewcontent = scontent.replace(soldheader, snewheader)
42             if not snewcontent == scontent:
43                 with open(sfile, 'w') as f:
44                     f.write(snewcontent)
45             
46