author | hgs |
Fri, 15 Oct 2010 12:29:39 +0300 | |
changeset 80 | d6dafc5d983f |
parent 35 | 85266cc22c7f |
permissions | -rw-r--r-- |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
# |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
# All rights reserved. |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
# This component and the accompanying materials are made available |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
# under the terms of "Eclipse Public License v1.0" |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
# which accompanies this distribution, and is available |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
# |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
# Initial Contributors: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
# Nokia Corporation - initial contribution. |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
# |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
# Contributors: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
# |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
# Description: |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
16 |
# Checks that all the source files have a proper EPL copyright header. |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
# Ignores number of known 3rd party source files and directories. |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
# |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
19 |
# Run this script on a clean workarea in order to avoid warnings |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
20 |
# about exported files and qmake generated files. |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
# |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
22 |
# The excluded directories should be checked every now and then |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
23 |
# so that there won't be other problems (like files without any header). |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
import sys, os, re |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
|
80 | 27 |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
# Specify here the file types to be checked |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
checkedFileTypes = [".cpp", ".h", ".java", ".py", ".mk"] |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
|
80 | 31 |
# Specify here the directories to be ignored relative to the root |
32 |
ignoredRootDirs = [ |
|
33 |
"javaextensions/bluetooth/bluecove", # Bluecove |
|
34 |
"javacommons/jvms/j9/s60/inc", # IBM J9 |
|
35 |
"javauis/eswt_akn", # eSWT checked separately |
|
36 |
"javauis/eswt_qt", # eSWT checked separately |
|
37 |
"javauis/tsrc/fute/eswt", # eSWT checked separately |
|
38 |
"javaextensions/webservices", # Webservices not delivered |
|
39 |
"tools" # Tools not delivered |
|
40 |
] |
|
41 |
||
42 |
# Specify here the directories to be ignored everywhere |
|
43 |
ignoredAnyDirs = [ |
|
44 |
".svn", # SVN directories |
|
45 |
"internal" # Internal directories not delivered |
|
46 |
] |
|
47 |
||
48 |
# Specify here any individual files to be ignored relative to the root |
|
49 |
ignoredFiles = [ |
|
50 |
"javacommons/jvms/cldc_1.1.1/javasrc/java/util/Timer.java", # Apache |
|
51 |
"javacommons/jvms/cldc_1.1.1/javasrc/java/util/TimerTask.java", # Apache |
|
52 |
"javacommons/jvms/cldc_1.1.1/tsrc/javasrc/com/nokia/mj/test/java/util/TimerTaskTest.java", # Apache |
|
53 |
"javacommons/jvms/cldc_1.1.1/tsrc/javasrc/com/nokia/mj/test/java/util/TimerTest.java", # Apache |
|
54 |
"javacommons/utils/inc/convertutf.h", # Unicode Inc. |
|
55 |
"javacommons/utils/src/convertutf.cpp", # Unicode Inc. |
|
56 |
"javaextensions/ccapi/ccapiext/javasrc/com/innovision/rf/JewelTagConnection.java", # Innovision |
|
57 |
"javaextensions/ccapi/ccapiext/javasrc/com/sony/felica/Type3TagConnection.java" # Sony |
|
58 |
] |
|
59 |
||
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
|
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
61 |
# The copyright texts to be searched for |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
62 |
copyrightText1 = "Nokia Corporation and/or its subsidiary(-ies)" |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
63 |
copyrightText2 = "Eclipse Public License v1.0" |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
def main(): |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
67 |
|
80 | 68 |
root = os.path.abspath(sys.argv[1]) |
69 |
rootlen = len(root) + 1 |
|
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
70 |
|
80 | 71 |
# Preprocess the ignore lists to speed up the actual checking |
72 |
rootDirsToIgnore = map(os.path.normpath, ignoredRootDirs) |
|
73 |
filesToIgnore = map(os.path.normpath, ignoredFiles) |
|
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
74 |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
75 |
def visitFun(arg, dirname, names): |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
|
80 | 77 |
# Skip the ignored directories |
78 |
if os.path.split(dirname)[1] in ignoredAnyDirs or \ |
|
79 |
dirname[rootlen:] in rootDirsToIgnore: |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
80 |
names[:] = [] |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
return |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
# Check then the files |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
for f in names: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
|
80 | 86 |
fname = os.path.join(dirname, f) |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
|
80 | 88 |
# Skip directories and ignored files |
89 |
if os.path.isdir(fname) or fname[rootlen:] in filesToIgnore: |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
continue |
80 | 91 |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
# Skip non-wanted file types |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
lastDot = f.rfind(".") |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
if lastDot == -1 or not f[lastDot:] in checkedFileTypes: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
continue |
80 | 96 |
|
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
97 |
# Check if the file contains the copyright texts |
80 | 98 |
found = False |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
99 |
try: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
file = open(fname) |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
101 |
|
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
102 |
# Search for the first text |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
found = False |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
104 |
line = file.readline() |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
while line != "": |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
106 |
if copyrightText1 in line: |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
found = True |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
108 |
break; |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
109 |
line = file.readline() |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
110 |
|
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
111 |
# Search the second copyright text as well |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
112 |
if found: |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
113 |
found = False |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
114 |
line = file.readline() |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
115 |
while line != "": |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
116 |
if copyrightText2 in line: |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
117 |
found = True |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
118 |
break; |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
119 |
line = file.readline() |
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
120 |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
121 |
file.close() |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
122 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
123 |
except IOError: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
124 |
print "Error reading the file " + fname |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
125 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
126 |
if not found: |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
127 |
print fname |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
continue |
35
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
129 |
|
85266cc22c7f
Revision: v2.2.1
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
130 |
os.path.walk(root, visitFun, None) |
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
131 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
132 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
133 |
if __name__ == "__main__": |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
134 |
main() |