File:  [Repository] / kupuMPIWG / tools / convert_to_utf-8.py
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Aug 30 17:10:23 2005 UTC (18 years, 8 months ago) by dwinter
Branches: first, MAIN
CVS tags: alpha, HEAD


#!/usr/bin/env python

import sys

def convert(data, encoding='ISO-8859-1'):
    data = unicode(data, encoding)
    data = data.encode('UTF-8')
    return data

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print 'Usage: %s <inputfile> <outputfile> [<encoding>]'
    infilename = sys.argv[1]
    outfilename = sys.argv[2]
    encoding = 'ISO-8859-1'
    if len(sys.argv) > 3:
        encoding = sys.argv[3]
    fpi = open(infilename)
    try:
        data = fpi.read()
    finally:
        fpi.close()
    utfdata = convert(data, encoding)
    fpo = open(outfilename, 'wb')
    try:
        fpo.write(utfdata)
    finally:
        fpo.close()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>