update.
[chise/ruby.git] / chise / management.rb
1 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
2
3 require "pathname"
4 require "fileutils"
5 require "chise/char"
6 require "chise/qp"
7
8 module CHISE
9   class DataBaseManagement
10     def dump_all
11       cd = ChiseDB.instance
12 =begin
13       cd.each_feature_name {|f|
14         ft = cd.get_feature(f)
15         ft.dump
16         ft.close
17       }
18 =end
19       cd.each_ccs {|ccs|
20         ct = cd.get_ccs(ccs)
21         ct.dump
22         ct.close
23       }
24     end
25   end
26
27   class DataBaseFileManagement
28
29     # from specs/char-atr.ja.txt
30     OBSOLETE_FEATURES = "
31 cns-radical
32 cns-radical?
33 kangxi-radical
34 daikanwa-radical
35
36 cns-strokes
37 kangxi-strokes
38 daikanwa-strokes
39 shinjigen-1-radical
40 gb-original-radical
41 japanese-strokes
42 jis-strokes-a
43 jisx0208-strokes
44 unicode-strokes
45
46 cns-total-strokes
47
48 non-morohashi
49
50 =>ucs*
51 #=>mojikyo
52 #=mojikyo
53 ->identical
54
55 ancient-ideograph-of
56 ancient-char-of-shinjigen-1
57 original-ideograph-of
58 original-char-of-shinjigen-1
59 vulgar-ideograph-of
60 vulgar-char-of-shinjigen-1
61 ideographic-variants
62 variant-of-shinjigen-1
63
64 iso-10646-comment
65 ".split
66
67     def initialize()
68       # @opt = {:noop=>true, :verbose=>true}
69       @opt = {:verbose=>true}
70     end
71
72     def move_obsolete_files
73       #fpath = Config.instance.db_dir.path+"system-char-id"
74       fpath = Config.instance.db_dir.path+"character/feature"
75       #fpath.chdir {
76       Dir.chdir(fpath.to_s) {
77         opath = "obsolete".path
78         opath.mkdir unless opath.directory?
79
80         OBSOLETE_FEATURES.each {|attr|
81           next if attr.nil?
82           next if /\A#/ =~ attr
83           f = attr.path.escape.escape_win_filename
84           FileUtils.mv(f.to_s, opath.to_s, @opt) if f.exist?
85           f = (f.to_s+".txt").path
86           FileUtils.mv(f.to_s, opath.to_s, @opt) if f.exist?
87         }
88       }
89     end
90
91     def rename_files
92       path = Config.instance.db_dir.path
93
94       nfpath = path+"character/feature"
95       FileUtils.mkdir_p(nfpath.to_s, @opt) unless nfpath.directory?
96
97       fpath = path+"system-char-id"
98       fpath.each_entry {|f|
99         next if /\A\./ =~ f
100         FileUtils.mv((fpath+f).to_s, nfpath.to_s, @opt)
101       }
102
103       ncpath = path+"character/by_feature"
104       FileUtils.mkdir_p(ncpath.to_s, @opt) unless ncpath.directory?
105
106       path.each_entry {|f|
107         next if /\A\./ =~ f
108         next if f.to_s == "character"
109         d = path + f
110         next unless d.directory?
111         ff = d + "system-char-id"
112         FileUtils.mv(ff.to_s, (ncpath+f).to_s, @opt) if ff.exist?
113       }
114     end
115   end
116 end