author | Maciej Seroka <maciejs@symbian.org> |
Wed, 28 Apr 2010 10:35:22 +0100 | |
changeset 246 | ade7819ee16c |
parent 138 | b9165bfa078f |
permissions | -rw-r--r-- |
138
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/python |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
2 |
# Copyright (c) 2009 Symbian Foundation. |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
3 |
# All rights reserved. |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
8 |
# |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
9 |
# Initial Contributors: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
10 |
# Symbian Foundation - Initial contribution |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
11 |
# |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
12 |
# Description: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
13 |
# Map the SFL license to the EULA license, keeping a copy of the original file |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
14 |
# in a parallel tree for creation of a "repair" kit to reinstate the SFL |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
15 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
16 |
import os |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
17 |
import os.path |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
18 |
import re |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
19 |
import codecs |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
20 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
21 |
oldtext0 = re.compile('terms of the License "Symbian Foundation License v1.0"(to Symbian Foundation)?') |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
22 |
oldtext1 = re.compile('the URL "http:..www.symbianfoundation.org/legal/sfl-v10.html"') |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
23 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
24 |
newtext = [ |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
25 |
'terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members', |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
26 |
'the URL "http://www.symbianfoundation.org/legal/licencesv10.html"' |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
27 |
] |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
28 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
29 |
errorfiles = [] |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
30 |
multinoticefiles = [] |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
31 |
shadowroot = 'shadow_epoc32' |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
32 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
33 |
def file_type(file) : |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
34 |
f = open(file, 'r') |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
35 |
data = f.read(256) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
36 |
f.close() |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
37 |
if len(data) < 2: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
38 |
return None # too short to be worth bothering about anyway |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
39 |
if data[0] == chr(255) and data[1] == chr(254) : |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
40 |
return 'utf_16_le' |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
41 |
if data.find(chr(0)) >= 0 : |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
42 |
return None # zero byte implies binary file |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
43 |
return 'text' |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
44 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
45 |
def map_eula(dir, name, encoded) : |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
46 |
global oldtext0 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
47 |
global newtext1 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
48 |
global newtext |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
49 |
file = os.path.join(dir, name) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
50 |
if encoded == 'text': |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
51 |
f = open(file, 'r') |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
52 |
else: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
53 |
f = codecs.open(file, 'r', encoding=encoded) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
54 |
lines = f.readlines() |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
55 |
# print ">> %s encoded as %s" % (file, f.encoding) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
56 |
f.close() |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
57 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
58 |
updated = 0 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
59 |
newlines = [] |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
60 |
while len(lines) > 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
61 |
line = lines.pop(0) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
62 |
pos1 = oldtext0.search(line) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
63 |
if pos1 != None: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
64 |
# be careful - oldtext is a prefix of newtext |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
65 |
if pos1.group(1) != None: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
66 |
# line already converted - nothing to do |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
67 |
newlines.append(line) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
68 |
continue |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
69 |
midlines = [] |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
70 |
midlinecount = 1 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
71 |
while len(lines) > 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
72 |
nextline = lines.pop(0) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
73 |
if not re.match('^\s$', nextline): |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
74 |
# non-blank line |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
75 |
if midlinecount == 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
76 |
break |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
77 |
midlinecount -= 1 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
78 |
midlines.append(nextline) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
79 |
urlline = nextline |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
80 |
pos2 = oldtext1.search(urlline) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
81 |
if pos2 != None: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
82 |
# found it - assume that there's only one instance |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
83 |
newline = oldtext0.sub(newtext[0], line) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
84 |
newurl = oldtext1.sub(newtext[1], urlline) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
85 |
newlines.append(newline) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
86 |
newlines.extend(midlines) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
87 |
newlines.append(newurl) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
88 |
updated += 1 |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
89 |
continue |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
90 |
else: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
91 |
if updated != 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
92 |
lineno = 1 + len(newlines) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
93 |
print "Problem in " + file + " at " + lineno + ": incorrectly formatted >" |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
94 |
print line |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
95 |
print midlines |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
96 |
print urlline |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
97 |
global errorfiles |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
98 |
errorfiles.append(file) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
99 |
break |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
100 |
newlines.append(line) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
101 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
102 |
if updated == 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
103 |
print " = no change to " + file |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
104 |
return |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
105 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
106 |
if updated > 1: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
107 |
global multinoticefiles |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
108 |
multinoticefiles.append(file) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
109 |
print '! found %d SFL notices in %s' % (updated, file) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
110 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
111 |
global shadowroot |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
112 |
shadowdir = os.path.join(shadowroot, dir) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
113 |
if not os.path.exists(shadowdir) : |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
114 |
os.makedirs(shadowdir) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
115 |
newfile = os.path.join(shadowroot,file) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
116 |
os.rename(file, newfile) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
117 |
if encoded == 'text': |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
118 |
f = open(file, 'w') |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
119 |
else: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
120 |
f = codecs.open(file, 'w', encoding=encoded) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
121 |
f.writelines(newlines) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
122 |
f.close() |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
123 |
print "* updated %s (encoding %s)" % (file, f.encoding) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
124 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
125 |
# process tree |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
126 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
127 |
for root, dirs, files in os.walk('epoc32', topdown=True): |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
128 |
if re.compile('epoc32$').match(root) >= 0: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
129 |
if 'build' in dirs: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
130 |
dirs.remove('build') # don't recurse into the epoc32/build subtree |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
131 |
for name in files: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
132 |
encoding = file_type(os.path.join(root, name)) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
133 |
if encoding: |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
134 |
map_eula(root, name, encoding) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
135 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
136 |
print '%d problem files' % len(errorfiles) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
137 |
print errorfiles |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
138 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
139 |
print '%d files with multiple notices' % len(multinoticefiles) |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
140 |
print multinoticefiles |
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
141 |
|
b9165bfa078f
Add Python version of convert_to_eula, which also handles license notices in Unicode text files
William Roberts <williamr@symbian.org>
parents:
diff
changeset
|
142 |