require 'pmd'
require 'vmd'
require 'x'
+require 'scrap'
location_code = ARGV.shift || 'mmd'
location = Location.find_by_code(location_code)
puts "location not found."
exit
end
+scrap = Scrap.find_by_location(location.code)
-while line = gets
- case line
- when /^$/
- #
- when /^error:/
- #
- when /^# (.+)/
- path = $1
+require 'rubygems'
+gem 'zipruby'
+require 'zipruby'
+require 'nkf'
+
+def encode(str)
+ str && NKF.nkf('-Sw', str)
+end
+
+def dump_zip(path, location)
+ Zip::Archive.open(path) do |ar|
+ puts "# #{path}"
basename = File.basename(path)
md = /\.(.+)\z/.match(basename)
extname = md[1]
code = code[3..-1]
end
arc = Arc.find_by_location_id_and_code(location.id, code)
- else
- size, comp_size, date, path = line.chomp.split(/\t/)
- if arc && /\.pmd\z/.match(path)
- puts [ code, path ].join(' ')
- arc.pmds.find_or_create_by_path(path)
- end
- if arc && /\.vmd\z/.match(path)
- puts [ code, path ].join(' ')
- arc.vmds.find_or_create_by_path(path)
+
+ n = ar.num_files # number of entries
+ n.times do |i|
+ entry_name = ar.get_name(i) # get entry name from archive
+
+ # open entry
+ ar.fopen(i) do |f|
+ size, comp_size, date, path = f.size, f.comp_size, f.mtime.strftime("%d-%m-%y %H:%M"), encode(f.name)
+ if arc && /\.pmd\z/.match(path)
+ puts [ code, path ].join(' ')
+ arc.pmds.find_or_create_by_path(path)
+ end
+ if arc && /\.vmd\z/.match(path)
+ puts [ code, path ].join(' ')
+ arc.vmds.find_or_create_by_path(path)
+ end
+ if arc && /\.x\z/.match(path)
+ puts [ code, path ].join(' ')
+ arc.xes.find_or_create_by_path(path)
+ end
+
+ # content = f.read # read entry content
+ end
end
- if arc && /\.x\z/.match(path)
- puts [ code, path ].join(' ')
- arc.xes.find_or_create_by_path(path)
+ end
+rescue Zip::Error => exc
+ puts "error: " + exc.message
+end
+
+ent = "/Volumes/uploader/src/#{location.code}/index.html"
+open(ent) do |f|
+ while line = f.gets
+ if scrap.match(line)
+ name, = scrap.row
+ dump_zip("/Volumes/uploader/arc/#{location.code}/#{name}", location)
+ puts
end
end
end