OSDN Git Service

create entries with archivers
authornomeu <nomeu@users.sourceforge.jp>
Thu, 4 Aug 2011 08:51:59 +0000 (17:51 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Thu, 4 Aug 2011 08:51:59 +0000 (17:51 +0900)
app/models/arc.rb
bin/load-arcs-bowl.rb
bin/load-arcs.rb
lib/archivers.rb

index e781036..f7894df 100644 (file)
@@ -5,9 +5,13 @@ class Arc < ActiveGroonga::Base
     key
   end
 
-  def create_zip_entries(path)
-    zip = Archivers::Zip.new(path)
-    zip.each_entry do |ent|
+  def create_entries(path)
+    archiver = Archiver.load(path, extname)
+    unless archiver
+      puts "archiver not found: #{path}"
+      return
+    end
+    archiver.each_entry do |ent|
       case ent
       when /\.pmd\z/
         puts [ code, ent ].join(' ')
index 6b4c1f9..e24d87d 100644 (file)
@@ -26,6 +26,6 @@ Bowl.each_code_in_rss do |code|
   locked = bowl.locked?
 
   arc = site.create_arc(name, summary, size, date, origname, locked)
-  arc.create_zip_entries("/Volumes/uploader/arc/#{site.code}/#{name}") unless locked
+  arc.create_entries("/Volumes/uploader/arc/#{site.code}/#{name}") unless locked
   puts
 end
index 04f5c9f..7592620 100644 (file)
@@ -25,7 +25,7 @@ open(ent) do |f|
     if scrap.match(line)
       name, summary, size, date, origname, locked = scrap.row
       arc = site.create_arc(name, summary, size, date, origname, locked)
-      arc.create_zip_entries("/Volumes/uploader/arc/#{site.code}/#{name}") unless locked
+      arc.create_entries("/Volumes/uploader/arc/#{site.code}/#{name}") unless locked
       puts
     end
   end
index cbdbe9f..bec903c 100644 (file)
@@ -73,4 +73,23 @@ module Archivers
       puts "error: " + exc.message
     end
   end
+
+module_function
+
+  def class_from_extname(extname)
+    case extname
+    when 'lzh'
+      Lzh
+    when 'rar'
+      Rar
+    when 'zip'
+      Zip
+    end
+  end
+
+  def load(path, extname)
+    klass = class_from_extname(extname)
+    klass.new(path) if klass
+  end
+
 end