X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fruby.git;a=blobdiff_plain;f=chise%2Fmanagement.rb;h=781a3ec3aeddb75837beae50d1a9ce764db42e81;hp=38fcfde5fd36ff8ee2b7ee27b6deeabb4e31ab0f;hb=fc94a49ca7fffa51475bcccf26b328a3b92f3758;hpb=a49cb66bf4d120e1c3bccf4ee86ef9e084a69e40 diff --git a/chise/management.rb b/chise/management.rb index 38fcfde..781a3ec 100755 --- a/chise/management.rb +++ b/chise/management.rb @@ -1,13 +1,35 @@ # 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 @@ -16,15 +38,10 @@ shinjigen-1-radical 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 @@ -37,37 +54,61 @@ ancient-ideograph-of 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" #’¼‘Å‚¿‚µ‚Ä‚¢‚éB + 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