Shin-ya Murakami
null****@okkez*****
2013年 12月 24日 (火) 22:01:36 JST
Shin-ya Murakami 2013-11-19 21:29:43 +0900 (Tue, 19 Nov 2013) New Revision: cdf8345fcb6838bf5a06f5247198e4d8b3255763 https://github.com/hiki/hiki/commit/cdf8345fcb6838bf5a06f5247198e4d8b3255763 Merged 213daae: Merge pull request #46 from murashin/master Message: add support for info.db conversion. Modified files: tool/convert.rb Modified: tool/convert.rb (+24 -0) =================================================================== --- tool/convert.rb 2013-12-02 21:13:30 +0900 (e788aa6) +++ tool/convert.rb 2013-11-19 21:29:43 +0900 (86132a4) @@ -9,9 +9,32 @@ require "digest/md5" require "nkf" require "hiki/util" require "hiki/config" +require 'hiki/db/ptstore' FILE_NAME_MAX_SIZE = 255 +def convert_info_db(data_path, input_encoding, output_encoding, nkf) + + info_db_path = data_path + "info.db" + db = PTStore.new(info_db_path) + + db.transaction do + db.roots.each do |d| + db[d][:title] = encode(db[d][:title], input_encoding, output_encoding, nkf) + db[d][:references].map! do |r| + encode(r, input_encoding, output_encoding, nkf) + end + end + db.roots.each do |d| + d_new = Hiki::Util.escape(encode(Hiki::Util.unescape(d), + input_encoding, output_encoding, nkf)) + db[d_new] = db[d] + db.delete d + end + db.commit + end +end + def check(data_path, database_class, input_encoding, output_encoding, nkf) config = Struct.new(:data_path).new config.data_path = data_path.expand_path @@ -142,6 +165,7 @@ def main(argv) if check_only check(data_path, database_class, input_encoding, output_encoding, nkf) else + convert_info_db(data_path, input_encoding, output_encoding, nkf) convert(data_path, database_class, input_encoding, output_encoding, nkf) end end