OSDN Git Service

refactored
[tdcgexplorer/nimono-crawlers.git] / bin / load-entries.rb
1 #!ruby
2 # vim: fileencoding=utf-8
3 $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4 require 'connection'
5 require 'location'
6 require 'arc'
7 require 'pmd'
8 require 'vmd'
9 require 'x'
10
11 location_code = ARGV.shift || 'mmd'
12 location = Location.find_by_code(location_code)
13 unless location
14   puts "location not found."
15   exit
16 end
17
18 while line = gets
19   case line
20   when /^$/
21     #
22   when /^error:/
23     #
24   when /^# (.+)/
25     path = $1
26     basename = File.basename(path)
27     md = /\.(.+)\z/.match(basename)
28     extname = md[1]
29     code = basename.sub(/\.(.+)\z/, '')
30     case location.code
31     when 'mmd'
32       #
33     when 'mmdfile'
34       code = 'file%04d' % code.to_i
35     when 'mmdacc1'
36       code = 'mini%04d' % code.to_i
37     when 'mmdacc2'
38       code = code[3..-1]
39     end
40     arc = Arc.find_by_location_id_and_code(location.id, code)
41   else
42     size, comp_size, date, path = line.chomp.split(/\t/)
43     if arc && /\.pmd\z/.match(path)
44       puts [ code, path ].join(' ')
45       arc.pmds.find_or_create_by_path(path)
46     end
47     if arc && /\.vmd\z/.match(path)
48       puts [ code, path ].join(' ')
49       arc.vmds.find_or_create_by_path(path)
50     end
51     if arc && /\.x\z/.match(path)
52       puts [ code, path ].join(' ')
53       arc.xes.find_or_create_by_path(path)
54     end
55   end
56 end