summaryrefslogtreecommitdiffstats
path: root/payyans/payyans/payyans
blob: 2600cf4749258d2271d9c2cbd520722987f6f51f (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Payyans Ascii to Unicode Convertor
# Copyright 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>, Nishan Naseer <nishan.naseer@gmail.com>, Manu S Madhav <manusmad@gmail.com>
# http://www.smc.org.in
#
# 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; either version 3 of the License, or
# (at your option) any later version.
#
# 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 Library 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.
#
# If you find any bugs or have any suggestions email: santhosh.thottingal@gmail.com
# URL: http://www.smc.org.in


from payyans import Payyans
from optparse import OptionParser
import sys,os
VERSION=0.7
def error_exit():
	print '''
	Payyans Malayalam Ascii <--> Unicode Converter 
	Please use --help or -h argument to see the options'''
	sys.exit(1)


class Payyan:

	def __init__(self):
		usage = "usage: %prog [options] arg"
		parser = OptionParser(usage)
		parser.add_option("-i", "--input-file", dest="input_filename",   help="the input file in ascii format")
		parser.add_option("-o", "--output-file", dest="output_filename",   help="the output file name")
		parser.add_option("-d", "--direction", dest="direction", help="'a2u': Ascii to Unicode, 'u2a': Unicode to Ascii")		
		parser.add_option("-m", "--mapping-file", dest="mapping_filename", help="the ascii to unicode mapping file name")
		parser.add_option("-v", "--version", action="store_true",  dest="version", help="print the version of this program")
		(options, args) = parser.parse_args()
		if options.version :
			print "Payyans Malayalam Ascii <--> Unicode Converter Version" , VERSION,
			return
		if (options.mapping_filename is None):
			print "\tEnter mapping file"
			error_exit()
		if not os.path.exists(options.mapping_filename):
			print "\tMap file " + options.mapping_filename + " not found"
			error_exit()
		if options.direction not in ['a2u','u2a']:
			print "\tInvalid direction"
			error_exit()
		p=Payyans(options.input_filename ,options.output_filename, options.mapping_filename)
		if options.direction == 'a2u':		
			p.ascii2unicode()
		else:
			p.unicode2ascii()
	
if __name__ == "__main__":
	payyan = Payyan()