111ac8f3ea1b99553facaf1d72e704c1513bb284
[chise/ruby.git] / tools / make-chisedb-tarball.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 $LOAD_PATH.unshift("..")
5 require "find"
6 require "pathname"
7 require "fileutils"
8 require "chise/path"
9 require "chise/qp"
10
11 def usage()
12   puts "Usage: make-chisedb-tarball.rb <CHISE-DB dir> <tmp dir>"
13   puts "% ./make-chisedb-tarball.rb /usr/local/lib/xemacs-21.4.14/i686-pc-linux/chise-db /var/tmp"
14   exit
15 end
16
17 def main(argv)
18   usage if argv.length < 1
19   dir = argv.shift
20   unless dir.path.directory?
21     print "no chise-db here. #{dir}\n"
22     usage
23   end
24   tmpdir = argv.shift || "/var/tmp"
25   orgdir = Dir.pwd
26
27   print "copy all chise-db to tmpdir"
28   system "cp -a #{dir} #{tmpdir}" # 
29   puts "."
30
31   print "escape special characters"
32   Find.find(tmpdir+"/chise-db") {|f|
33     next if f.path.directory?
34     nf = f.path.escape.to_s
35     next if f == nf
36     cmd = "mv '#{f}' '#{nf}'"
37     #puts cmd
38     system cmd
39   }
40   puts "."
41
42   Dir.chdir(tmpdir){
43     print "make tarball"
44     system "tar czf chise-db.tar.gz chise-db"
45     puts "."
46     print "mv it"
47     system "mv chise-db.tar.gz #{orgdir}"
48     puts "."
49     print "remove tmpdir/chise-db"
50     system "rm -rf #{tmpdir}/chise-db"
51     puts "."
52   }
53 end
54 main(ARGV)