From cd8659a2748c8afe04e3c8e0964845a84ed739df Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 14 Dec 2011 15:06:39 +0800 Subject: refactor expand_file --- scripts/genbopomofoheader.py | 18 +++--------------- scripts/gendoublepinyinheader.py | 18 ++---------------- scripts/genpinyinheader.py | 18 ++---------------- 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/scripts/genbopomofoheader.py b/scripts/genbopomofoheader.py index 9d617b6..cb4024f 100644 --- a/scripts/genbopomofoheader.py +++ b/scripts/genbopomofoheader.py @@ -21,8 +21,8 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import os from operator import itemgetter +from utils import expand_file bopomofo = [ 'ㄅ', 'ㄆ', 'ㄇ', 'ㄈ', 'ㄉ', 'ㄊ', 'ㄋ', 'ㄌ', 'ㄍ', 'ㄎ', @@ -118,18 +118,6 @@ def get_table_content(tablename): return gen_chewing_tones(scheme); -def expand_file(filename): - infile = open(filename, "r") - for line in infile.readlines(): - line = line.rstrip(os.linesep) - if len(line) < 3 : - print(line) - continue - if line[0] == '@' and line[-1] == '@': - tablename = line[1:-1] - print(get_table_content(tablename)) - else: - print(line) - +### main function ### if __name__ == "__main__": - expand_file("chewing_table.h.in") + expand_file("chewing_table.h.in", get_table_content) diff --git a/scripts/gendoublepinyinheader.py b/scripts/gendoublepinyinheader.py index 96a363e..15de35e 100644 --- a/scripts/gendoublepinyinheader.py +++ b/scripts/gendoublepinyinheader.py @@ -20,9 +20,8 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import os import pinyin - +from utils import expand_file def gen_shengmu_table(scheme): entries = [] @@ -64,20 +63,7 @@ def get_table_content(tablename): if part == "YUN": return gen_yunmu_table(scheme) -def expand_file(filename): - infile = open(filename, "r") - for line in infile.readlines(): - line = line.rstrip(os.linesep) - if len(line) < 3 : - print(line) - continue - if line[0] == '@' and line[-1] == '@': - tablename = line[1:-1] - print(get_table_content(tablename)) - else: - print(line) - ### main function ### if __name__ == "__main__": - expand_file("double_pinyin_table.h.in") + expand_file("double_pinyin_table.h.in", get_table_content) diff --git a/scripts/genpinyinheader.py b/scripts/genpinyinheader.py index 8a0a8fd..7d07a24 100644 --- a/scripts/genpinyinheader.py +++ b/scripts/genpinyinheader.py @@ -20,7 +20,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import os +from utils import expand_file from genpinyintable import gen_content_table, \ gen_pinyin_index, gen_bopomofo_index, \ gen_chewing_key_table @@ -41,20 +41,6 @@ def get_table_content(tablename): return gen_chewing_key_table() -def expand_file(filename): - infile = open(filename, "r") - for line in infile.readlines(): - line = line.rstrip(os.linesep) - if len(line) < 3 : - print(line) - continue - if line[0] == '@' and line[-1] == '@': - tablename = line[1:-1] - print(get_table_content(tablename)) - else: - print(line) - - ### main function ### if __name__ == "__main__": - expand_file("pinyin_parser_table.h.in") + expand_file("pinyin_parser_table.h.in", get_table_content) -- cgit