# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+require "pathname"
+require "fileutils"
+require "chise/char"
+require "chise/qp"
+
module CHISE
- class DBS_Management # DataBase file management
- OBSOLETE_ATTRIBUTES = "
+ class DataBaseManagement
+ def dump_all
+ cd = ChiseDB.instance
+ cd.each_feature_name {|f|
+ ft = cd.get_feature(f)
+ ft.dump
+ ft.close
+ }
+ cd.each_ccs {|ccs|
+ ct = cd.get_ccs(ccs)
+ ct.dump
+ ct.close
+ }
+ end
+ end
+
+ class DataBaseFileManagement
+
+ # from specs/char-atr.ja.txt
+ OBSOLETE_FEATURES = "
cns-radical
cns-radical?
kangxi-radical
daikanwa-radical
-unicode-radical
cns-strokes
kangxi-strokes
gb-original-radical
japanese-strokes
jis-strokes-a
-jis-strokes-b
jisx0208-strokes
-jis-x0213-strokes
-jisx0213-strokes
unicode-strokes
-totalstrokes
cns-total-strokes
-jis-total-strokes-b
non-morohashi
ancient-char-of-shinjigen-1
original-ideograph-of
original-char-of-shinjigen-1
-simplified-ideograph-of
vulgar-ideograph-of
vulgar-char-of-shinjigen-1
-ideograph=
ideographic-variants
variant-of-shinjigen-1
iso-10646-comment
".split
- def initialize
- dir = Config.instance.db_dir
- @odir = dir+"/system-char-id/obsolete" #\92¼\91Å\82¿\82µ\82Ä\82¢\82é\81B
+ def initialize()
+ # @opt = {:noop=>true, :verbose=>true}
+ @opt = {:verbose=>true}
end
- def move_obsolete_files # move obsolete BDB files
- db = CharDB.instance
- db.close_all
- Dir.mkdir(@odir) unless FileTest.directory? @odir
- OBSOLETE_ATTRIBUTES.each {|attr|
- next if attr =~ /^#/
- filename = db.get_filename(attr)
- move_to_obsolete(filename)
- move_to_obsolete(filename+".txt")
+ def move_obsolete_files
+ #fpath = Config.instance.db_dir.path+"system-char-id"
+ fpath = Config.instance.db_dir.path+"character/feature"
+ #fpath.chdir {
+ Dir.chdir(fpath.to_s) {
+ opath = "obsolete".path
+ opath.mkdir unless opath.directory?
+
+ OBSOLETE_FEATURES.each {|attr|
+ next if attr.nil?
+ next if /\A#/ =~ attr
+ f = attr.path.escape.escape_win_filename
+ FileUtils.mv(f.to_s, opath.to_s, @opt) if f.exist?
+ f = (f.to_s+".txt").path
+ FileUtils.mv(f.to_s, opath.to_s, @opt) if f.exist?
+ }
}
end
- def move_to_obsolete(file)
- cmd = "mv \"#{file}\" #{@odir}"
- #p cmd
- system cmd
+ def rename_files
+ path = Config.instance.db_dir.path
+
+ nfpath = path+"character/feature"
+ FileUtils.mkdir_p(nfpath.to_s, @opt) unless nfpath.directory?
+
+ fpath = path+"system-char-id"
+ fpath.each_entry {|f|
+ next if /\A\./ =~ f
+ FileUtils.mv((fpath+f).to_s, nfpath.to_s, @opt)
+ }
+
+ ncpath = path+"character/by_feature"
+ FileUtils.mkdir_p(ncpath.to_s, @opt) unless ncpath.directory?
+
+ path.each_entry {|f|
+ next if /\A\./ =~ f
+ next if f.to_s == "character"
+ d = path + f
+ next unless d.directory?
+ ff = d + "system-char-id"
+ FileUtils.mv(ff.to_s, (ncpath+f).to_s, @opt) if ff.exist?
+ }
end
end
end