2 ########################################################################
4 ## Copyright (C) 2009 MiM
6 ## Contact: Handspring <xhealer@gmail.com>
8 ## AUTHOR: Alsor Zhou <alsor.zhou@gmail.com>
10 ## This file is part of MiM Pinyin.
12 ## This is free software: you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation, either version 3 of the License, or
15 ## (at your option) any later version.
17 ## This is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
22 ## You should have received a copy of the GNU General Public License
23 ## along with Sigil. If not, see <http://www.gnu.org/licenses/>.
25 ########################################################################
33 # Global ERROR DEFINATION
38 '''Print wrapper with debug function supported
40 Never use this function in production (always output) code '''
46 Copyright (C) 2009 MiM
48 Contact: Handspring <xhealer@gmail.com>
52 This file is part of MiM Pinyin.
54 This is free software: you can redistribute it and/or modify
55 it under the terms of the GNU General Public License as published by
56 the Free Software Foundation, either version 3 of the License, or
57 (at your option) any later version.
59 This is distributed in the hope that it will be useful,
60 but WITHOUT ANY WARRANTY; without even the implied warranty of
61 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62 GNU General Public License for more details.
64 You should have received a copy of the GNU General Public License
65 along with Sigil. If not, see <http://www.gnu.org/licenses/>.
70 '''converter.py [options] SRC [options...DEST]
71 -s SRC : specify dictionary source
72 -t DEST : save converted binary map into DEST
73 -c SRC : syntax check SRC, without converstion
76 --source SRC : same with '-s SRC'
77 --target DEST: same with '-t DEST'
78 --check SRC : same with '-c SRC'
83 '''MiM pinyin dictionary converter version 0.0.1 Handspring <xhealer@gmail.com>'''
86 def convert(src, dest):
87 '''Convertion from original text format dictionary to binary map.
89 @param src : text format dictionary
90 @param dest: binary map dictionary
94 PRINT(convert.__doc__)
97 '''Check syntax format of orignal text format dictionary
99 @param src : text format dictionary
101 @return True without syntax error, False else.
106 '''Main business logic
108 @param argv : sys.argv[1:]
109 @return error code if any
112 # handle parameter parse
113 valid_args = "hvVt:c:s:d"
114 valid_long_args = ["help", "version", "source", "target", "check"]
119 opts, args = getopt.getopt(argv, valid_args, valid_long_args)
120 except getopt.GetoptError, err:
128 if o in ("-s", "--source"):
130 assert False, "No dictionary source specified"
133 # no dest specified, use same filename as src to store file
135 basename = os.path.basename(src)
136 dest = os.path.splitext(basename)[0]
137 dest = os.path.join(dest, ".bin")
140 elif o in ("-t", "--target"):
142 elif o in ("-c", "--check"):
146 elif o in ("-h", "--help"):
149 elif o in ("-V", "--version"):
154 if __name__ == "__main__":