OSDN Git Service

t#31902:add import migration
[pettanr/pettanr.git] / script / sbt_helper.rb
1 #フキダシテンプレートを作るサポートツール\r
2 if ARGV.size < 2\r
3   puts "sbt_helper.rb -Ku input.json output.json [work dir=input dir]"\r
4   exit\r
5 end\r
6 require 'json'\r
7 require 'base64'\r
8 \r
9 inputfile = ARGV[0]\r
10 wd = ARGV[2] ? File.expand_path(ARGV[2]) : File.dirname(inputfile)\r
11 outputfile = wd + '/' + ARGV[1]\r
12 \r
13 puts "#{inputfile} to #{outputfile}"\r
14 def replace_system_picture attr, wd\r
15   attr.each do |name, value|\r
16     if value.is_a? Hash\r
17       if value['system_picture_file']\r
18         fn = File.expand_path(wd + '/' + value['system_picture_file'])\r
19         puts 'open system picture file ' + fn\r
20         d = File.open(fn, 'rb').read\r
21         b = Base64.encode64(d).gsub(/\r/, '').gsub(/\n/, '')\r
22         value['system_picture_id'] = {"text" => b}\r
23         value.delete 'system_picture_file'\r
24       end\r
25       replace_system_picture value, wd\r
26     end\r
27   end\r
28 end\r
29 \r
30 json = JSON.parse(open(inputfile).read)\r
31 replace_system_picture json, wd\r
32 \r
33 puts "generating " + outputfile\r
34 File.open(outputfile, 'w') do |f|\r
35   f.write JSON.pretty_generate(json)\r
36 end\r