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