From c74868872258600e2c3a299510121cc0d84a6abc Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 19:41:09 +0900 Subject: [PATCH 1/6] start/stop ttserver --- History.txt | 4 ++ Manifest.txt | 11 ++++ PostInstall.txt | 7 +++ README.rdoc | 48 +++++++++++++++++++ Rakefile | 26 ++++++++++ lib/shinagawaseaside.rb | 74 ++++++++++++++++++++++++++++++ lib/shinagawaseaside/ShinagawaSeaside.rb | 6 ++ lib/shinagawaseaside/task.rb | 3 + samples/Rakefile | 8 +++ script/console | 10 ++++ script/destroy | 14 ++++++ script/generate | 14 ++++++ test/test_helper.rb | 3 + test/test_shinagawaseaside.rb | 11 ++++ 14 files changed, 239 insertions(+), 0 deletions(-) create mode 100644 History.txt create mode 100644 Manifest.txt create mode 100644 PostInstall.txt create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 lib/shinagawaseaside.rb create mode 100644 lib/shinagawaseaside/ShinagawaSeaside.rb create mode 100644 lib/shinagawaseaside/task.rb create mode 100644 samples/Rakefile create mode 100755 script/console create mode 100755 script/destroy create mode 100755 script/generate create mode 100644 test/test_helper.rb create mode 100644 test/test_shinagawaseaside.rb diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..88be685 --- /dev/null +++ b/History.txt @@ -0,0 +1,4 @@ +=== 0.0.1 2010-07-04 + +* 1 major enhancement: + * Initial release diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..4dc2ef9 --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,11 @@ +History.txt +Manifest.txt +PostInstall.txt +README.rdoc +Rakefile +lib/shinagawaseaside.rb +script/console +script/destroy +script/generate +test/test_helper.rb +test/test_shinagawaseaside.rb diff --git a/PostInstall.txt b/PostInstall.txt new file mode 100644 index 0000000..3e3dbdd --- /dev/null +++ b/PostInstall.txt @@ -0,0 +1,7 @@ + +For more information on shinagawaseaside, see http://shinagawaseaside.rubyforge.org + +NOTE: Change this information in PostInstall.txt +You can also delete it if you don't want it. + + diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..2ae4aaa --- /dev/null +++ b/README.rdoc @@ -0,0 +1,48 @@ += shinagawaseaside + +* http://github.com/#{github_username}/#{project_name} + +== DESCRIPTION: + +FIX (describe your package) + +== FEATURES/PROBLEMS: + +* FIX (list of features or problems) + +== SYNOPSIS: + + FIX (code sample of usage) + +== REQUIREMENTS: + +* FIX (list of requirements) + +== INSTALL: + +* FIX (sudo gem install, anything else) + +== LICENSE: + +(The MIT License) + +Copyright (c) 2010 FIXME full name + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7edef5d --- /dev/null +++ b/Rakefile @@ -0,0 +1,26 @@ +require 'rubygems' +gem 'hoe', '>= 2.1.0' +require 'hoe' +require 'fileutils' +require './lib/shinagawaseaside' + +Hoe.plugin :newgem +# Hoe.plugin :website +# Hoe.plugin :cucumberfeatures + +# Generate all the Rake tasks +# Run 'rake -T' to see list of generated tasks (from gem root directory) +$hoe = Hoe.spec 'shinagawaseaside' do + self.developer 'FIXME full name', 'FIXME email' + self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required + self.rubyforge_name = self.name # TODO this is default value + # self.extra_deps = [['activesupport','>= 2.0.2']] + +end + +require 'newgem/tasks' +Dir['tasks/**/*.rake'].each { |t| load t } + +# TODO - want other tests/tasks run by default? Add them to the list +# remove_task :default +# task :default => [:spec, :features] diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb new file mode 100644 index 0000000..e2e6827 --- /dev/null +++ b/lib/shinagawaseaside.rb @@ -0,0 +1,74 @@ +$:.unshift(File.dirname(__FILE__)) unless + $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) + +module ShinagawaSeaside + VERSION = '0.0.1' + + def ShinagawaSeaside::set(ttdb, opts) + p ttdb + p opts + + ttdb = ttdb.map{|db| + name = db[:name] + port = db[:port].to_i + basedir = opts[:basedir] + { + :cmd => 'ttserver', + :basedir => basedir, + :name => name, + :port => port, + :pidfile => "#{basedir}/#{name}.pid", + :dbname => "#{basedir}/#{name}.tch#bnum=1000000" + } + } + + desc 'start TokyoTyrant server' + task 'ttstart' do + puts 'starting TokyoTyrant servers..' + for tt in ttdb do + Dir.mkdir(tt[:basedir]) if !File.exists?(tt[:basedir]) + puts '' + puts "name=>#{tt[:name]}, port=>#{tt[:port]}, pid=>#{tt[:pidfile]}" + if File.exists?(tt[:pidfile]) + pid = open(tt[:pidfile]).read + puts "existing process - pid:#{pid}" + else + system("#{tt[:cmd]} -port #{tt[:port]} -dmn -pid #{tt[:pidfile]} #{tt[:dbname]}") + puts 'done' + end + end + end + + desc 'stop TokyoTyrant server' + task 'ttstop' do + puts 'stopping TokyoTyrant servers..' + for tt in ttdb do + if File.exists?(tt[:pidfile]) + pid = open(tt[:pidfile]).read + puts '' + puts "name=>#{tt[:name]}, port=>#{tt[:port]}, pid=>#{pid}" + system("kill -TERM #{pid}") + count = 0 + loop do + sleep 0.1 + if !File.exists?(tt[:pidfile]) + puts 'done' + break + end + if (count+=1) > 100 + puts "hanging process - pid:#{pid}" + break + end + end + else + puts 'no process found' + end + end + end + + desc 'restart TokyoTyrant server' + task 'ttrestart' => ['ttstop', 'ttstart'] + + end + +end diff --git a/lib/shinagawaseaside/ShinagawaSeaside.rb b/lib/shinagawaseaside/ShinagawaSeaside.rb new file mode 100644 index 0000000..83878b0 --- /dev/null +++ b/lib/shinagawaseaside/ShinagawaSeaside.rb @@ -0,0 +1,6 @@ + +module ShinagawaSeaside::Task +desc 'shinagawa' +task 'shinagawa' do + puts 'start shinagawa' +end diff --git a/lib/shinagawaseaside/task.rb b/lib/shinagawaseaside/task.rb new file mode 100644 index 0000000..027a711 --- /dev/null +++ b/lib/shinagawaseaside/task.rb @@ -0,0 +1,3 @@ + +puts 'load task' + diff --git a/samples/Rakefile b/samples/Rakefile new file mode 100644 index 0000000..cd27e6f --- /dev/null +++ b/samples/Rakefile @@ -0,0 +1,8 @@ +require 'rubygems' +require '../lib/shinagawaseaside' + +ttdb = [ { :name => 'users', :port => 20010}, + { :name => 'videos',:port => 20011}, + { :name => 'comments', :port => 20012} ] + +ShinagawaSeaside::set(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') diff --git a/script/console b/script/console new file mode 100755 index 0000000..e061bac --- /dev/null +++ b/script/console @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby +# File: script/console +irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb' + +libs = " -r irb/completion" +# Perhaps use a console_lib to store any extra methods I may want available in the cosole +# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}" +libs << " -r #{File.dirname(__FILE__) + '/../lib/shinagawaseaside.rb'}" +puts "Loading shinagawaseaside gem" +exec "#{irb} #{libs} --simple-prompt" \ No newline at end of file diff --git a/script/destroy b/script/destroy new file mode 100755 index 0000000..e48464d --- /dev/null +++ b/script/destroy @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/destroy' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Destroy.new.run(ARGV) diff --git a/script/generate b/script/generate new file mode 100755 index 0000000..c27f655 --- /dev/null +++ b/script/generate @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) + +begin + require 'rubigen' +rescue LoadError + require 'rubygems' + require 'rubigen' +end +require 'rubigen/scripts/generate' + +ARGV.shift if ['--help', '-h'].include?(ARGV[0]) +RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit] +RubiGen::Scripts::Generate.new.run(ARGV) diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..33220e8 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +require 'stringio' +require 'test/unit' +require File.dirname(__FILE__) + '/../lib/shinagawaseaside' diff --git a/test/test_shinagawaseaside.rb b/test/test_shinagawaseaside.rb new file mode 100644 index 0000000..e5c4020 --- /dev/null +++ b/test/test_shinagawaseaside.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/test_helper.rb' + +class TestShinagawaseaside < Test::Unit::TestCase + + def setup + end + + def test_truth + assert true + end +end -- 1.6.3 From 74d2646f09689012777aa65a6da77810e315789b Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 19:41:19 +0900 Subject: [PATCH 2/6] add ignore --- .gitignore | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a39583c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +DS_Store +*~ +pkg/* +ttdb/* +*.tch +*.pid +.fuse* +config.yaml +.\#* +*\#* -- 1.6.3 From 34656ec2b797ea30a43f8a54c209db249b293eed Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 20:04:20 +0900 Subject: [PATCH 3/6] use rspec --- Manifest.txt | 8 ++++++-- README.rdoc | 22 +++++++++++++--------- Rakefile | 4 ++-- lib/shinagawaseaside/ShinagawaSeaside.rb | 6 ------ lib/shinagawaseaside/task.rb | 3 --- spec/shinagawaseaside_spec.rb | 11 +++++++++++ spec/spec.opts | 1 + spec/spec_helper.rb | 10 ++++++++++ tasks/rspec.rake | 21 +++++++++++++++++++++ test/test_helper.rb | 3 --- test/test_shinagawaseaside.rb | 11 ----------- 11 files changed, 64 insertions(+), 36 deletions(-) delete mode 100644 lib/shinagawaseaside/ShinagawaSeaside.rb delete mode 100644 lib/shinagawaseaside/task.rb create mode 100644 spec/shinagawaseaside_spec.rb create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb create mode 100644 tasks/rspec.rake delete mode 100644 test/test_helper.rb delete mode 100644 test/test_shinagawaseaside.rb diff --git a/Manifest.txt b/Manifest.txt index 4dc2ef9..8f917a0 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -7,5 +7,9 @@ lib/shinagawaseaside.rb script/console script/destroy script/generate -test/test_helper.rb -test/test_shinagawaseaside.rb +spec/shinagawaseaside_spec.rb +spec/spec.opts +spec/spec_helper.rb +tasks/rspec.rake +samples/Rakefile + diff --git a/README.rdoc b/README.rdoc index 2ae4aaa..243e435 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,32 +1,36 @@ = shinagawaseaside -* http://github.com/#{github_username}/#{project_name} +* http://github.com/shokai/shinagawaseaside == DESCRIPTION: -FIX (describe your package) +add rake tasks they start/stop tokyo tyrant server -== FEATURES/PROBLEMS: +== SYNOPSIS: -* FIX (list of features or problems) + require 'rubygems' + require 'shinagawaseaside' -== SYNOPSIS: + ttdb = [ { :name => 'users', :port => 20010}, + { :name => 'videos',:port => 20011}, + { :name => 'comments', :port => 20012} ] + + ShinagawaSeaside::set(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') - FIX (code sample of usage) == REQUIREMENTS: -* FIX (list of requirements) +* TokyoTyrant == INSTALL: -* FIX (sudo gem install, anything else) +* sudo gem install ShinagawaSeaside == LICENSE: (The MIT License) -Copyright (c) 2010 FIXME full name +Copyright (c) 2010 Sho Hashimoto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/Rakefile b/Rakefile index 7edef5d..73d361c 100644 --- a/Rakefile +++ b/Rakefile @@ -11,8 +11,8 @@ Hoe.plugin :newgem # Generate all the Rake tasks # Run 'rake -T' to see list of generated tasks (from gem root directory) $hoe = Hoe.spec 'shinagawaseaside' do - self.developer 'FIXME full name', 'FIXME email' - self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required + self.developer 'Sho Hashimoto', 'hashimoto@shokai.org' + # self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required self.rubyforge_name = self.name # TODO this is default value # self.extra_deps = [['activesupport','>= 2.0.2']] diff --git a/lib/shinagawaseaside/ShinagawaSeaside.rb b/lib/shinagawaseaside/ShinagawaSeaside.rb deleted file mode 100644 index 83878b0..0000000 --- a/lib/shinagawaseaside/ShinagawaSeaside.rb +++ /dev/null @@ -1,6 +0,0 @@ - -module ShinagawaSeaside::Task -desc 'shinagawa' -task 'shinagawa' do - puts 'start shinagawa' -end diff --git a/lib/shinagawaseaside/task.rb b/lib/shinagawaseaside/task.rb deleted file mode 100644 index 027a711..0000000 --- a/lib/shinagawaseaside/task.rb +++ /dev/null @@ -1,3 +0,0 @@ - -puts 'load task' - diff --git a/spec/shinagawaseaside_spec.rb b/spec/shinagawaseaside_spec.rb new file mode 100644 index 0000000..afdb080 --- /dev/null +++ b/spec/shinagawaseaside_spec.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/spec_helper.rb' + +# Time to add your specs! +# http://rspec.info/ +describe "Place your specs here" do + + it "find this spec in spec directory" do + # violated "Be sure to write your specs" + end + +end diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..cf6add7 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1 @@ +--colour \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2d53e3f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +begin + require 'spec' +rescue LoadError + require 'rubygems' unless ENV['NO_RUBYGEMS'] + gem 'rspec' + require 'spec' +end + +$:.unshift(File.dirname(__FILE__) + '/../lib') +require 'shinagawaseaside' diff --git a/tasks/rspec.rake b/tasks/rspec.rake new file mode 100644 index 0000000..31a99b0 --- /dev/null +++ b/tasks/rspec.rake @@ -0,0 +1,21 @@ +begin + require 'spec' +rescue LoadError + require 'rubygems' unless ENV['NO_RUBYGEMS'] + require 'spec' +end +begin + require 'spec/rake/spectask' +rescue LoadError + puts <<-EOS +To use rspec for testing you must install rspec gem: + gem install rspec +EOS + exit(0) +end + +desc "Run the specs under spec/models" +Spec::Rake::SpecTask.new do |t| + t.spec_opts = ['--options', "spec/spec.opts"] + t.spec_files = FileList['spec/**/*_spec.rb'] +end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 33220e8..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'stringio' -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/shinagawaseaside' diff --git a/test/test_shinagawaseaside.rb b/test/test_shinagawaseaside.rb deleted file mode 100644 index e5c4020..0000000 --- a/test/test_shinagawaseaside.rb +++ /dev/null @@ -1,11 +0,0 @@ -require File.dirname(__FILE__) + '/test_helper.rb' - -class TestShinagawaseaside < Test::Unit::TestCase - - def setup - end - - def test_truth - assert true - end -end -- 1.6.3 From eed265fcdd971be3cf9f0e5b96fc345cb566d025 Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 20:09:52 +0900 Subject: [PATCH 4/6] fix func name --- README.rdoc | 2 +- lib/shinagawaseaside.rb | 2 +- samples/Rakefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 243e435..7690484 100644 --- a/README.rdoc +++ b/README.rdoc @@ -15,7 +15,7 @@ add rake tasks they start/stop tokyo tyrant server { :name => 'videos',:port => 20011}, { :name => 'comments', :port => 20012} ] - ShinagawaSeaside::set(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') + ShinagawaSeaside::set_tasks(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') == REQUIREMENTS: diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb index e2e6827..1855baf 100644 --- a/lib/shinagawaseaside.rb +++ b/lib/shinagawaseaside.rb @@ -4,7 +4,7 @@ $:.unshift(File.dirname(__FILE__)) unless module ShinagawaSeaside VERSION = '0.0.1' - def ShinagawaSeaside::set(ttdb, opts) + def ShinagawaSeaside::set_tasks(ttdb, opts) p ttdb p opts diff --git a/samples/Rakefile b/samples/Rakefile index cd27e6f..e1a9407 100644 --- a/samples/Rakefile +++ b/samples/Rakefile @@ -5,4 +5,4 @@ ttdb = [ { :name => 'users', :port => 20010}, { :name => 'videos',:port => 20011}, { :name => 'comments', :port => 20012} ] -ShinagawaSeaside::set(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') +ShinagawaSeaside::set_tasks(ttdb, :basedir => File.dirname(__FILE__)+'/ttdb') -- 1.6.3 From 35ea5ea17960e139fc128e132dcee8ff84c52614 Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 21:07:02 +0900 Subject: [PATCH 5/6] fix --- PostInstall.txt | 7 ------- lib/shinagawaseaside.rb | 3 --- samples/Rakefile | 3 ++- 3 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 PostInstall.txt diff --git a/PostInstall.txt b/PostInstall.txt deleted file mode 100644 index 3e3dbdd..0000000 --- a/PostInstall.txt +++ /dev/null @@ -1,7 +0,0 @@ - -For more information on shinagawaseaside, see http://shinagawaseaside.rubyforge.org - -NOTE: Change this information in PostInstall.txt -You can also delete it if you don't want it. - - diff --git a/lib/shinagawaseaside.rb b/lib/shinagawaseaside.rb index 1855baf..78cc777 100644 --- a/lib/shinagawaseaside.rb +++ b/lib/shinagawaseaside.rb @@ -5,9 +5,6 @@ module ShinagawaSeaside VERSION = '0.0.1' def ShinagawaSeaside::set_tasks(ttdb, opts) - p ttdb - p opts - ttdb = ttdb.map{|db| name = db[:name] port = db[:port].to_i diff --git a/samples/Rakefile b/samples/Rakefile index e1a9407..3e6053c 100644 --- a/samples/Rakefile +++ b/samples/Rakefile @@ -1,5 +1,6 @@ require 'rubygems' -require '../lib/shinagawaseaside' +require 'shinagawaseaside' +#require '../lib/shinagawaseaside' ttdb = [ { :name => 'users', :port => 20010}, { :name => 'videos',:port => 20011}, -- 1.6.3 From d02e3948264746026749d63aff7503e0210090af Mon Sep 17 00:00:00 2001 From: Sho Hashimoto Date: Sun, 4 Jul 2010 21:08:41 +0900 Subject: [PATCH 6/6] 0.0.1 --- History.txt | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/History.txt b/History.txt index 88be685..358b0f4 100644 --- a/History.txt +++ b/History.txt @@ -1,4 +1,3 @@ === 0.0.1 2010-07-04 -* 1 major enhancement: - * Initial release +* start/stop ttserver -- 1.6.3