41 return 'utf_16_le' |
42 return 'utf_16_le' |
42 if data.find(chr(0)) >= 0 : |
43 if data.find(chr(0)) >= 0 : |
43 return None # zero byte implies binary file |
44 return None # zero byte implies binary file |
44 return 'text' |
45 return 'text' |
45 |
46 |
46 def map_eula(dir, name, encoded) : |
47 def map_epl(dir, name, encoded) : |
47 global oldtext0 |
48 global oldtext0 |
48 global newtext1 |
49 global newtext1 |
49 global newtext |
50 global newtext |
50 file = os.path.join(dir, name) |
51 file = os.path.join(dir, name) |
51 if encoded == 'text': |
52 if encoded == 'text': |
122 f = open(file, 'w') |
123 f = open(file, 'w') |
123 else: |
124 else: |
124 f = codecs.open(file, 'w', encoding=encoded) |
125 f = codecs.open(file, 'w', encoding=encoded) |
125 f.writelines(newlines) |
126 f.writelines(newlines) |
126 f.close() |
127 f.close() |
|
128 modifiedfiles.append(file) |
127 print "* updated %s (encoding %s)" % (file, encoded) |
129 print "* updated %s (encoding %s)" % (file, encoded) |
128 return 1 |
130 return 1 |
129 |
131 |
130 parser = OptionParser(version="%prog 0.2", usage="Usage: %prog [options]") |
132 parser = OptionParser(version="%prog 0.3", usage="Usage: %prog [options]") |
131 parser.add_option("-n", "--check", action="store_true", dest="dryrun", |
133 parser.add_option("-n", "--check", action="store_true", dest="dryrun", |
132 help="report the files which would be updated, but don't change anything") |
134 help="report the files which would be updated, but don't change anything") |
133 parser.set_defaults(dryrun=False) |
135 parser.add_option("--nozip", action="store_false", dest="zip", |
|
136 help="disable the attempt to generate a zip of the updated files") |
|
137 parser.set_defaults(dryrun=False,zip=True) |
134 |
138 |
135 (options, args) = parser.parse_args() |
139 (options, args) = parser.parse_args() |
136 if len(args) != 0: |
140 if len(args) != 0: |
137 parser.error("Unexpected commandline arguments") |
141 parser.error("Unexpected commandline arguments") |
138 |
142 |
143 if '.hg' in dirs: |
147 if '.hg' in dirs: |
144 dirs.remove('.hg') # don't recurse into the Mercurial repository storage |
148 dirs.remove('.hg') # don't recurse into the Mercurial repository storage |
145 for name in files: |
149 for name in files: |
146 encoding = file_type(os.path.join(root, name)) |
150 encoding = file_type(os.path.join(root, name)) |
147 if encoding: |
151 if encoding: |
148 update_count += map_eula(root, name, encoding) |
152 update_count += map_epl(root, name, encoding) |
149 |
153 |
150 print '%d problem files' % len(errorfiles) |
154 print '%d problem files' % len(errorfiles) |
151 print errorfiles |
155 print errorfiles |
152 |
156 |
153 print '%d files with multiple notices' % len(multinoticefiles) |
157 print '%d files with multiple notices' % len(multinoticefiles) |
154 print multinoticefiles |
158 print multinoticefiles |
155 |
159 |
156 if options.dryrun and update_count > 0: |
160 if options.dryrun and update_count > 0: |
157 print "%d files need updating" % update_count |
161 print "%d files need updating" % update_count |
158 sys.exit(1) |
162 sys.exit(1) |
|
163 |
|
164 if options.zip and len(modifiedfiles): |
|
165 zip = os.popen('zip fixed_files.zip -@', 'w') |
|
166 for file in modifiedfiles: |
|
167 print >> zip, file |
|
168 zip.close() |
|
169 print "%d files written to fixed_files.zip" % len(modifiedfiles) |
|
170 |
|
171 |
159 |
172 |
160 |
173 |