OSDN Git Service

merged nimono
authornomeu <nomeu@nomeu.org>
Sun, 13 Jun 2010 02:01:51 +0000 (11:01 +0900)
committernomeu <nomeu@nomeu.org>
Sun, 13 Jun 2010 02:01:51 +0000 (11:01 +0900)
bin/dbtest.rb [new file with mode: 0644]
bin/load-arcs.rb [new file with mode: 0644]
bin/load-entries.rb [new file with mode: 0644]
bin/load-locations.rb [new file with mode: 0644]
config/database.yml [new file with mode: 0644]
lib/arc.rb [new file with mode: 0644]
lib/connection.rb [new file with mode: 0644]
lib/location.rb [new file with mode: 0644]
lib/pmd.rb [new file with mode: 0644]
lib/vmd.rb [new file with mode: 0644]
lib/x.rb [new file with mode: 0644]

diff --git a/bin/dbtest.rb b/bin/dbtest.rb
new file mode 100644 (file)
index 0000000..158b85c
--- /dev/null
@@ -0,0 +1,4 @@
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'connection'
+require 'location'
+p Location.count
diff --git a/bin/load-arcs.rb b/bin/load-arcs.rb
new file mode 100644 (file)
index 0000000..47838bf
--- /dev/null
@@ -0,0 +1,42 @@
+#!ruby
+# vim: fileencoding=utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'connection'
+require 'location'
+require 'arc'
+
+location_code = ARGV.shift || 'mmd'
+location = Location.find_by_code(location_code)
+unless location
+  puts "location not found."
+  exit
+end
+
+while line = gets
+  case location.code
+  when 'mmd'
+    name, summary, size, date, mime, origname, with_key, with_password = line.chomp.split(/\t/)
+  when 'mmdfile', 'mmdacc1', 'mmdacc2'
+    name, summary, size, date, origname = line.chomp.split(/\t/)
+  end
+  md = /\.(.+)\z/.match(name)
+  extname = md[1]
+  code = File.basename(name, '.' + extname)
+  case location.code
+  when 'mmd'
+    #
+  when 'mmdfile'
+    code = 'file%04d' % code.to_i
+  when 'mmdacc1'
+    code = 'mini%04d' % code.to_i
+  when 'mmdacc2'
+    code = code[3..-1]
+  end
+  arc = Arc.find_by_code(code)
+  if arc
+    puts "found code: #{code}"
+    next
+  end
+  puts "Arc.create code: #{code}"
+  arc = Arc.create(:code => code, :extname => extname, :location => location, :summary => summary, :origname => origname)
+end
diff --git a/bin/load-entries.rb b/bin/load-entries.rb
new file mode 100644 (file)
index 0000000..849fa3e
--- /dev/null
@@ -0,0 +1,56 @@
+#!ruby
+# vim: fileencoding=utf-8
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'connection'
+require 'location'
+require 'arc'
+require 'pmd'
+require 'vmd'
+require 'x'
+
+location_code = ARGV.shift || 'mmd'
+location = Location.find_by_code(location_code)
+unless location
+  puts "location not found."
+  exit
+end
+
+while line = gets
+  case line
+  when /^$/
+    #
+  when /^error:/
+    #
+  when /^# (.+)/
+    path = $1
+    basename = File.basename(path)
+    md = /\.(.+)\z/.match(basename)
+    extname = md[1]
+    code = basename.sub(/\.(.+)\z/, '')
+    case location.code
+    when 'mmd'
+      #
+    when 'mmdfile'
+      code = 'file%04d' % code.to_i
+    when 'mmdacc1'
+      code = 'mini%04d' % code.to_i
+    when 'mmdacc2'
+      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)
+    end
+    if arc && /\.x\z/.match(path)
+      puts [ code, path ].join(' ')
+      arc.xes.find_or_create_by_path(path)
+    end
+  end
+end
diff --git a/bin/load-locations.rb b/bin/load-locations.rb
new file mode 100644 (file)
index 0000000..5478088
--- /dev/null
@@ -0,0 +1,17 @@
+#!ruby
+# vim: fileencoding=utf-8 :
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'connection'
+require 'location'
+
+location = Location.find_or_initialize_by_id(1)
+location.update_attributes(:code => "mmd", :site => "http://bytatsu.net/uploader/mikumikudance/", :summary => "MMD専用アップローダ")
+
+location = Location.find_or_initialize_by_id(2)
+location.update_attributes(:code => "mmdfile", :site => "http://loda.jp/mmdfile/", :summary => "MMDデータ保管庫")
+
+location = Location.find_or_initialize_by_id(3)
+location.update_attributes(:code => "mmdacc1", :site => "http://www9.atpages.jp/~mmdaccessory/uploader/", :summary => "MMDアクセサリアップローダ(小物版)")
+
+location = Location.find_or_initialize_by_id(4)
+location.update_attributes(:code => "mmdacc2", :site => "http://www9.atpages.jp/~mmdaccessory/uploader2/", :summary => "MMD Accessory Uploader")
diff --git a/config/database.yml b/config/database.yml
new file mode 100644 (file)
index 0000000..1a75bdc
--- /dev/null
@@ -0,0 +1,51 @@
+# PostgreSQL. Versions 7.4 and 8.x are supported.
+#
+# Install the ruby-postgres driver:
+#   gem install ruby-postgres
+# On Mac OS X:
+#   gem install ruby-postgres -- --include=/usr/local/pgsql
+# On Windows:
+#   gem install ruby-postgres
+#       Choose the win32 build.
+#       Install PostgreSQL and put its /bin directory on your path.
+development:
+  adapter: postgresql
+  encoding: unicode
+  database: nimono_development
+  pool: 5
+  username: nimono
+  password:
+
+  # Connect on a TCP socket. Omitted by default since the client uses a
+  # domain socket that doesn't need configuration. Windows does not have
+  # domain sockets, so uncomment these lines.
+  #host: localhost
+  #port: 5432
+
+  # Schema search path. The server defaults to $user,public
+  #schema_search_path: myapp,sharedapp,public
+
+  # Minimum log levels, in increasing order:
+  #   debug5, debug4, debug3, debug2, debug1,
+  #   log, notice, warning, error, fatal, and panic
+  # The server defaults to notice.
+  #min_messages: warning
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+  adapter: postgresql
+  encoding: unicode
+  database: nimono_test
+  pool: 5
+  username: nimono
+  password:
+
+production:
+  adapter: postgresql
+  encoding: unicode
+  database: nimono_production
+  pool: 5
+  username: nimono
+  password:
diff --git a/lib/arc.rb b/lib/arc.rb
new file mode 100644 (file)
index 0000000..c3d5c26
--- /dev/null
@@ -0,0 +1,6 @@
+class Arc < ActiveRecord::Base
+  belongs_to :location
+  has_many :pmds
+  has_many :vmds
+  has_many :xes
+end
diff --git a/lib/connection.rb b/lib/connection.rb
new file mode 100644 (file)
index 0000000..024b36b
--- /dev/null
@@ -0,0 +1,6 @@
+require 'yaml'
+options = YAML.load(IO.read("config/database.yml"))["development"]
+require 'rubygems'
+gem 'activerecord'
+require 'active_record'
+ActiveRecord::Base.establish_connection(options)
diff --git a/lib/location.rb b/lib/location.rb
new file mode 100644 (file)
index 0000000..e3acd90
--- /dev/null
@@ -0,0 +1,2 @@
+class Location < ActiveRecord::Base
+end
diff --git a/lib/pmd.rb b/lib/pmd.rb
new file mode 100644 (file)
index 0000000..2cdb870
--- /dev/null
@@ -0,0 +1,3 @@
+class Pmd < ActiveRecord::Base
+  belongs_to :arc
+end
diff --git a/lib/vmd.rb b/lib/vmd.rb
new file mode 100644 (file)
index 0000000..048c7dc
--- /dev/null
@@ -0,0 +1,3 @@
+class Vmd < ActiveRecord::Base
+  belongs_to :arc
+end
diff --git a/lib/x.rb b/lib/x.rb
new file mode 100644 (file)
index 0000000..08c6d89
--- /dev/null
+++ b/lib/x.rb
@@ -0,0 +1,3 @@
+class X < ActiveRecord::Base
+  belongs_to :arc
+end