2009-06-25 19:42:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2009 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
|
|
|
|
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-06-25 19:42:22 +00:00
|
|
|
|
2009-06-23 16:25:40 +00:00
|
|
|
import codecs
|
2009-06-25 19:42:22 +00:00
|
|
|
import sys
|
2009-06-23 16:25:40 +00:00
|
|
|
|
2009-07-19 06:31:08 +00:00
|
|
|
def convert_file(inname, outname):
|
2009-07-08 06:55:08 +00:00
|
|
|
"""
|
|
|
|
Convert a file from another encoding into UTF-8.
|
2009-06-23 16:25:40 +00:00
|
|
|
|
2009-07-08 06:55:08 +00:00
|
|
|
``inname``
|
|
|
|
The name of the file to be opened and converted.
|
2009-06-23 16:25:40 +00:00
|
|
|
|
2009-07-08 06:55:08 +00:00
|
|
|
``outname``
|
|
|
|
The output file name.
|
|
|
|
"""
|
2009-07-21 18:10:14 +00:00
|
|
|
infile = codecs.open(inname, 'r', encoding='CP1252')
|
2009-07-08 06:55:08 +00:00
|
|
|
writefile = codecs.open(outname, 'w', encoding='utf-8')
|
|
|
|
for line in infile:
|
|
|
|
#replace the quotes with quotes
|
2009-07-19 06:31:08 +00:00
|
|
|
#TODO fix double quotes
|
|
|
|
#line = line.replace(u'\'\'', u'@')
|
2009-07-08 06:55:08 +00:00
|
|
|
writefile.write(line)
|
|
|
|
infile.close()
|
|
|
|
writefile.close()
|
2009-06-23 16:25:40 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-07-08 06:55:08 +00:00
|
|
|
"""
|
|
|
|
Run the conversion script.
|
|
|
|
"""
|
2009-06-25 19:42:22 +00:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print 'No action specified.'
|
|
|
|
sys.exit()
|
2009-07-08 06:55:08 +00:00
|
|
|
print 'Uncode conversion:'
|
|
|
|
print 'Input file = ', sys.argv[1]
|
|
|
|
print 'Output file = ', sys.argv[2]
|
|
|
|
print 'Converting...'
|
|
|
|
convert_file(sys.argv[1], sys.argv[2])
|
|
|
|
print 'Done.'
|