[r1731]: developer_scripts / ensure_utf8.py  Maximize  Restore  History

Download this file

49 lines (39 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright 2004-2008 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import os
import codecs
from file_system_iter import files_iterator, folders_iterator
to_be_validated_file_exts = [
'*.rest'
]
def ensure_utf8( fpath ):
def read_content( fpath ):
last_error = None
for encoding in [ 'ascii', 'UTF8', 'UTF16' ]:
try:
f = codecs.open( fpath, 'rb', encoding )
fcontent = f.read()
f.close()
return fcontent
except UnicodeDecodeError, err:
last_error = err
else:
raise last_error
def write_content( fpath, content ):
fcontent_new = content #unicode( content, 'UTF8' )
fcontent_new = fcontent_new.lstrip( unicode( codecs.BOM_UTF8, "utf8" ) )
f = codecs.open( fpath, 'w+b', 'UTF8' )
f.write( fcontent_new )
f.close()
write_content( fpath, read_content( fpath ) )
if __name__ == '__main__':
sources_dir = os.path.join( os.path.abspath( os.curdir ), '..' )
dirs_to_go = [ os.path.join( sources_dir, 'pydsc_dev' )
, os.path.join( sources_dir, 'pygccxml_dev' )
, os.path.join( sources_dir, 'pyplusplus_dev' ) ]
for fpath in files_iterator( dirs_to_go, to_be_validated_file_exts ):
print 'converting %s' % fpath
ensure_utf8( fpath )
print 'converting %s - done' % fpath

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks