|
1 #!/usr/bin/python |
|
2 # |
|
3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # Checks that all the source files have a proper copyright header. |
|
17 # Ignores number of known 3rd party source files and directories. |
|
18 # |
|
19 # Run this script on a clean workarea in order to avoid warnings |
|
20 # about exported files and qmake generated files. |
|
21 # |
|
22 # The excluded directories should be checked every now and then |
|
23 # so that there won't be other problems (like files without any |
|
24 # header). |
|
25 |
|
26 import sys, os, re |
|
27 |
|
28 # Specify here the file types to be checked |
|
29 checkedFileTypes = [".cpp", ".h", ".java", ".py", ".mk"] |
|
30 |
|
31 # Include here the directories to be ignored |
|
32 ignoredDirectories = [ |
|
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 "jrt\\tools", # Tools not delivered |
|
40 "\\internal" # Internal directories not delivered |
|
41 ] |
|
42 |
|
43 # Include here any individual files to be ignored |
|
44 ignoredFiles = [ |
|
45 "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\Timer.java", # Apache license |
|
46 "javacommons\\jvms\\cldc_1.1.1\\javasrc\\java\\util\\TimerTask.java", # Apache license |
|
47 "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTaskTest.java", # Apache license |
|
48 "javacommons\\jvms\\cldc_1.1.1\\tsrc\\javasrc\\com\\nokia\\mj\\test\\java\\util\\TimerTest.java", # Apache license |
|
49 "javacommons\\utils\\inc\\convertutf.h", # Unicode Inc. |
|
50 "javacommons\\utils\\src\\convertutf.cpp" # Unicode Inc. |
|
51 ] |
|
52 |
|
53 # The copyright text to be checked |
|
54 copyrightText = "Nokia Corporation and/or its subsidiary(-ies)" |
|
55 |
|
56 |
|
57 def main(): |
|
58 |
|
59 def visitFun(arg, dirname, names): |
|
60 |
|
61 # Skip SVN directories |
|
62 if dirname.find("\\.svn") != -1: |
|
63 return |
|
64 |
|
65 # Skip all the directories to be ignored |
|
66 for dir in ignoredDirectories: |
|
67 if dirname.find(dir) != -1: |
|
68 names[:] = [] |
|
69 # print "Ignoring directory", dirname |
|
70 return |
|
71 |
|
72 # Check then the files |
|
73 for f in names: |
|
74 |
|
75 fname = dirname + "\\" + f |
|
76 |
|
77 # Skip directories |
|
78 if os.path.isdir(fname): |
|
79 continue |
|
80 |
|
81 # Skip ignored files |
|
82 found = False |
|
83 for file in ignoredFiles: |
|
84 if fname.find(file) != -1: |
|
85 # print "Ignoring file", fname |
|
86 found = True |
|
87 break |
|
88 if found: |
|
89 continue |
|
90 |
|
91 # Skip non-wanted file types |
|
92 lastDot = f.rfind(".") |
|
93 if lastDot == -1 or not f[lastDot:] in checkedFileTypes: |
|
94 # print "Ignoring file", f |
|
95 continue |
|
96 |
|
97 # Check if the file contains the copyright text |
|
98 try: |
|
99 file = open(fname) |
|
100 found = False |
|
101 line = file.readline() |
|
102 while line != "": |
|
103 if copyrightText in line: |
|
104 found = True |
|
105 break; |
|
106 line = file.readline() |
|
107 file.close() |
|
108 |
|
109 except IOError: |
|
110 print "Error reading the file " + fname |
|
111 |
|
112 if not found: |
|
113 print fname |
|
114 continue |
|
115 |
|
116 os.path.walk(sys.argv[1], visitFun, None) |
|
117 |
|
118 |
|
119 if __name__ == "__main__": |
|
120 main() |