File: mkTuxpaintIM.py

package info (click to toggle)
tuxpaint 1%3A0.9.20-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 21,004 kB
  • ctags: 2,143
  • sloc: ansic: 22,917; objc: 1,082; makefile: 922; sh: 172; cpp: 119; python: 75
file content (46 lines) | stat: -rw-r--r-- 1,481 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/env python
# -*- coding: Big5 -*-
# Copyright: Song Huang <songhuang.tw@gmail.com>
# create: 2007/11/04
# License: GNU GPL 
ver = "0.1"

from optparse import OptionParser
from codecs import open as copen

if __name__ == '__main__':
    # parse script arguments
    optparser = OptionParser(usage='./%prog [options]', version="%prog "+ver)
    optparser.add_option("-o", "--outputfile",   action="store",  
                         help=unicode("XɮתW","big5"))
    optparser.add_option("-m", "--phonemap",   action="store",
                         help=unicode("P`Ӫ(utf8 - expect file was xcin table:phone.cin)","big5"))
    (options, args) = optparser.parse_args()

    ## ]wDnܼ
    #  XɦW
    outfile = copen(options.outputfile, "w", "utf8")
    outfile.write("section\n\n")
    # P`Ӫ
    phonemap = options.phonemap

    # X
    cinfile = copen(phonemap, "r", "utf8")
    (bopomofo, chinachar) = cinfile.readline().split()
    bpmf_count = 0
    bpmf_temp = bopomofo
    while bopomofo:
        if bpmf_temp == bopomofo:
            bpmf_count += 1
        else:
            bpmf_count = 1
	    bpmf_temp  = bopomofo
        chinacharnum = str(hex(ord(chinachar)))[2:]
        outfile.write("%s\t%s%s\t-\t# %s \n" % (chinacharnum, bopomofo, bpmf_count, chinachar))
	try:
            (bopomofo, chinachar) = cinfile.readline().split()
	except:
            break
    # 
    cinfile.close()
    outfile.close()