[BioRuby-cvs] bioruby/lib/bio/shell core.rb, 1.25, 1.26 interface.rb, 1.17, 1.18 setup.rb, 1.6, 1.7 web.rb, 1.4, 1.5
Katayama Toshiaki
k at dev.open-bio.org
Tue Jun 26 08:38:40 UTC 2007
Update of /home/repository/bioruby/bioruby/lib/bio/shell
In directory dev.open-bio.org:/tmp/cvs-serv16040
Modified Files:
core.rb interface.rb setup.rb web.rb
Log Message:
* changed to cache full path of the save directory and avoid to use
Dir.chdir, so that user can freely use Dir.chdir in the shell
environment without affecting saving session functionality
Index: interface.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/interface.rb,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** interface.rb 20 Jun 2007 17:24:54 -0000 1.17
--- interface.rb 26 Jun 2007 08:38:38 -0000 1.18
***************
*** 150,154 ****
def savefile(file, *objs)
! datadir = Bio::Shell.datadir
message = "Save file '#{file}' in '#{datadir}' directory? [y/n] "
if ! file[/^#{datadir}/] and Bio::Shell.ask_yes_or_no(message)
--- 150,154 ----
def savefile(file, *objs)
! datadir = Bio::Shell.data_dir
message = "Save file '#{file}' in '#{datadir}' directory? [y/n] "
if ! file[/^#{datadir}/] and Bio::Shell.ask_yes_or_no(message)
Index: web.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/web.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** web.rb 5 Apr 2007 23:35:41 -0000 1.4
--- web.rb 26 Jun 2007 08:38:38 -0000 1.5
***************
*** 36,49 ****
def install_rails
! unless File.exist?("script/generate")
puts "Installing Rails application for BioRuby shell ... "
! system("rails .")
puts "done"
end
! unless File.exist?("app/controllers/bioruby_controller.rb")
basedir = File.dirname(__FILE__)
puts "Installing Rails plugin for BioRuby shell ... "
! FileUtils.cp_r("#{basedir}/rails/.", ".")
! system("./script/generate bioruby shell")
puts "done"
end
--- 36,54 ----
def install_rails
! savedir = Bio::Shell.cache[:savedir]
! path = File.join(savedir, "script", "generate")
! unless File.exist?(path)
puts "Installing Rails application for BioRuby shell ... "
! system("rails #{savedir}")
puts "done"
end
! path = File.join(savedir, "app", "controllers", "bioruby_controller.rb")
! unless File.exist?(path)
basedir = File.dirname(__FILE__)
puts "Installing Rails plugin for BioRuby shell ... "
! FileUtils.cp_r("#{basedir}/rails/.", savedir)
! Dir.chdir(savedir) do
! system("./script/generate bioruby shell")
! end
puts "done"
end
***************
*** 52,59 ****
def start_rails
begin
! Bio::Shell.cache[:rails] = Thread.new {
! require './config/boot'
! require 'commands/server'
! }
end
end
--- 57,66 ----
def start_rails
begin
! Bio::Shell.cache[:rails] = Thread.new do
! Dir.chdir(Bio::Shell.cache[:savedir]) do
! require './config/boot'
! require 'commands/server'
! end
! end
end
end
Index: setup.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/setup.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** setup.rb 26 Jun 2007 01:43:24 -0000 1.6
--- setup.rb 26 Jun 2007 08:38:38 -0000 1.7
***************
*** 80,88 ****
if arg.nil?
# run in the current directory
! workdir = "#{ENV['HOME']}/.bioruby"
install_workdir(workdir)
elsif File.directory?(arg)
# run in the existing directory
! workdir = arg
elsif File.file?(arg)
# run file as a bioruby shell script (slightly tricky)
--- 80,88 ----
if arg.nil?
# run in the current directory
! workdir = File.join(ENV['HOME'].to_s, ".bioruby")
install_workdir(workdir)
elsif File.directory?(arg)
# run in the existing directory
! workdir = File.join(Dir.pwd, arg)
elsif File.file?(arg)
# run file as a bioruby shell script (slightly tricky)
***************
*** 92,96 ****
else
# run in new directory
! workdir = arg
install_workdir(workdir)
end
--- 92,96 ----
else
# run in new directory
! workdir = File.join(Dir.pwd, arg)
install_workdir(workdir)
end
Index: core.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/core.rb,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** core.rb 26 Jun 2007 01:41:33 -0000 1.25
--- core.rb 26 Jun 2007 08:38:38 -0000 1.26
***************
*** 11,24 ****
module Bio::Shell::Core
! # chdir
! # change to File.join for / ended dirs
! SAVEDIR = "shell/session/"
! CONFIG = "config"
! OBJECT = "object"
! HISTORY = "history"
! SCRIPT = "shell/script.rb"
! PLUGIN = "shell/plugin/"
! DATADIR = "data/"
! BIOFLAT = "data/bioflat/"
MARSHAL = [ Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION ]
--- 11,28 ----
module Bio::Shell::Core
! # TODO:
! # * load history from current and savedir
! # * don'nt show history saved when exit 'no save' mode
! # * replace File to Pathname
!
! SHELLDIR = "shell"
! DATADIR = "data"
! SESSION = File.join(SHELLDIR, "session")
! PLUGIN = File.join(SHELLDIR, "plugin")
! SCRIPT = File.join(SHELLDIR, "script.rb")
! CONFIG = File.join(SESSION, "config")
! OBJECT = File.join(SESSION, "object")
! HISTORY = File.join(SESSION, "history")
! BIOFLAT = File.join(DATADIR, "bioflat")
MARSHAL = [ Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION ]
***************
*** 42,59 ****
end
! def datadir
! File.join(@cache[:workdir], DATADIR)
end
def script_dir
! File.dirname(SCRIPT)
end
def object_file
! File.join(@cache[:workdir], SAVEDIR, OBJECT)
end
def history_file
! File.join(@cache[:workdir], SAVEDIR, HISTORY)
end
--- 46,87 ----
end
! def shell_dir
! File.join(@cache[:savedir], SHELLDIR)
! end
!
! def data_dir
! File.join(@cache[:savedir], DATADIR)
! end
!
! def session_dir
! File.join(@cache[:savedir], SESSION)
! end
!
! def plugin_dir
! File.join(@cache[:savedir], PLUGIN)
! end
!
! def script_file
! File.join(@cache[:savedir], SCRIPT)
end
def script_dir
! File.dirname(script_file)
! end
!
! def config_file
! File.join(@cache[:savedir], CONFIG)
end
def object_file
! File.join(@cache[:savedir], OBJECT)
end
def history_file
! File.join(@cache[:savedir], HISTORY)
! end
!
! def bioflat_dir
! File.join(@cache[:savedir], BIOFLAT)
end
***************
*** 91,95 ****
def configure(workdir)
! savedir = File.join(Dir.pwd, workdir)
@config = {}
@cache = {
--- 119,128 ----
def configure(workdir)
! if workdir == File.join(ENV['HOME'].to_s, ".bioruby")
! savedir = workdir
! workdir = Dir.pwd
! else
! savedir = workdir
! end
@config = {}
@cache = {
***************
*** 122,126 ****
end
#STDERR.puts "Leaving directory '#{@cache[:workdir]}'"
! STDERR.puts "History is saved in '#{@cache[:workdir]}/#{SAVEDIR + HISTORY}'"
end
--- 155,159 ----
end
#STDERR.puts "Leaving directory '#{@cache[:workdir]}'"
! STDERR.puts "History is saved in '#{history_file}'"
end
***************
*** 128,148 ****
def create_save_dir
! create_real_dir(SAVEDIR)
! create_real_dir(DATADIR)
! create_real_dir(PLUGIN)
end
def create_save_dir_ask
! Dir.chdir(@cache[:workdir]) do |path|
! if File.directory?(SAVEDIR)
! @cache[:save] = true
! end
end
unless @cache[:save]
! if ask_yes_or_no("Save session in '#{@cache[:workdir]}/#{SAVEDIR}' directory? [y/n] ")
! create_real_dir(SAVEDIR)
! create_real_dir(PLUGIN)
! create_real_dir(DATADIR)
! create_real_dir(BIOFLAT)
@cache[:save] = true
else
--- 161,179 ----
def create_save_dir
! create_real_dir(session_dir)
! create_real_dir(plugin_dir)
! create_real_dir(data_dir)
end
def create_save_dir_ask
! if File.directory?(session_dir)
! @cache[:save] = true
end
unless @cache[:save]
! if ask_yes_or_no("Save session in '#{@cache[:workdir]}' directory? [y/n] ")
! create_real_dir(session_dir)
! create_real_dir(plugin_dir)
! create_real_dir(data_dir)
! create_real_dir(bioflat_dir)
@cache[:save] = true
else
***************
*** 154,166 ****
def create_real_dir(dir)
! Dir.chdir(@cache[:workdir]) do |path|
! unless File.directory?(dir)
! begin
! STDERR.print "Creating directory (#{path}/#{dir}) ... "
! FileUtils.mkdir_p(dir)
! STDERR.puts "done"
! rescue
! warn "Error: Failed to create directory (#{path}/#{dir}) : #{$!}"
! end
end
end
--- 185,195 ----
def create_real_dir(dir)
! unless File.directory?(dir)
! begin
! STDERR.print "Creating directory (#{dir}) ... "
! FileUtils.mkdir_p(dir)
! STDERR.puts "done"
! rescue
! warn "Error: Failed to create directory (#{dir}) : #{$!}"
end
end
***************
*** 170,195 ****
def create_flat_dir(dbname)
! flatdb = ""
! Dir.chdir(@cache[:workdir]) do |path|
! dir = BIOFLAT + dbname.to_s.strip
! unless File.directory?(dir)
! FileUtils.mkdir_p(dir)
! end
! flatdb = "#{path}/#{dir}"
end
! return flatdb
end
def find_flat_dir(dbname)
! flatdb = ""
! Dir.chdir(@cache[:workdir]) do |path|
! dir = BIOFLAT + dbname.to_s.strip
! if File.exists?(dir)
! flatdb = "#{path}/#{dir}"
! else
! flatdb = nil
! end
end
- return flatdb
end
--- 199,216 ----
def create_flat_dir(dbname)
! dir = File.join(bioflat_dir, dbname.to_s.strip)
! unless File.directory?(dir)
! FileUtils.mkdir_p(dir)
end
! return dir
end
def find_flat_dir(dbname)
! dir = File.join(bioflat_dir, dbname.to_s.strip)
! if File.exists?(dir)
! return dir
! else
! return nil
end
end
***************
*** 197,230 ****
def load_config
! load_config_file(SAVEDIR + CONFIG)
end
def load_config_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! if File.exists?(file)
! STDERR.print "Loading config (#{path}/#{file}) ... "
! if hash = YAML.load(File.read(file))
! @config.update(hash)
! end
! STDERR.puts "done"
end
end
end
def save_config
! save_config_file(SAVEDIR + CONFIG)
end
def save_config_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! begin
! STDERR.print "Saving config (#{path}/#{file}) ... "
! File.open(file, "w") do |f|
! f.puts @config.to_yaml
! end
! STDERR.puts "done"
! rescue
! warn "Error: Failed to save (#{path}/#{file}) : #{$!}"
end
end
end
--- 218,247 ----
def load_config
! load_config_file(config_file)
end
def load_config_file(file)
! if File.exists?(file)
! STDERR.print "Loading config (#{file}) ... "
! if hash = YAML.load(File.read(file))
! @config.update(hash)
end
+ STDERR.puts "done"
end
end
def save_config
! save_config_file(config_file)
end
def save_config_file(file)
! begin
! STDERR.print "Saving config (#{file}) ... "
! File.open(file, "w") do |f|
! f.puts @config.to_yaml
end
+ STDERR.puts "done"
+ rescue
+ warn "Error: Failed to save (#{file}) : #{$!}"
end
end
***************
*** 277,291 ****
def load_plugin
! load_plugin_dir(PLUGIN)
end
def load_plugin_dir(dir)
! Dir.chdir(@cache[:workdir]) do |path|
! if File.directory?(dir)
! Dir.glob("#{dir}/*.rb").sort.each do |file|
! STDERR.print "Loading plugin (#{path}/#{file}) ... "
! load file
! STDERR.puts "done"
! end
end
end
--- 294,306 ----
def load_plugin
! load_plugin_dir(plugin_dir)
end
def load_plugin_dir(dir)
! if File.directory?(dir)
! Dir.glob("#{dir}/*.rb").sort.each do |file|
! STDERR.print "Loading plugin (#{file}) ... "
! load file
! STDERR.puts "done"
end
end
***************
*** 303,307 ****
begin
check_marshal
! load_object_file(SAVEDIR + OBJECT)
rescue
warn "Error: Load aborted : #{$!}"
--- 318,322 ----
begin
check_marshal
! load_object_file(object_file)
rescue
warn "Error: Load aborted : #{$!}"
***************
*** 310,368 ****
def load_object_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! if File.exists?(file)
! STDERR.print "Loading object (#{path}/#{file}) ... "
! begin
! bind = Bio::Shell.cache[:binding]
! hash = Marshal.load(File.read(file))
! hash.each do |k, v|
! begin
! Thread.current[:restore_value] = v
! eval("#{k} = Thread.current[:restore_value]", bind)
! rescue
! STDERR.puts "Warning: object '#{k}' couldn't be loaded : #{$!}"
! end
end
- rescue
- warn "Error: Failed to load (#{path}/#{file}) : #{$!}"
end
! STDERR.puts "done"
end
end
end
def save_object
! save_object_file(SAVEDIR + OBJECT)
end
def save_object_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! begin
! STDERR.print "Saving object (#{path}/#{file}) ... "
! File.rename(file, "#{file}.old") if File.exist?(file)
! File.open(file, "w") do |f|
! bind = Bio::Shell.cache[:binding]
! list = eval("local_variables", bind)
! list -= ["_"]
! hash = {}
! list.each do |elem|
! value = eval(elem, bind)
! if value
! begin
! Marshal.dump(value)
! hash[elem] = value
! rescue
! # value could not be dumped.
! end
end
end
- Marshal.dump(hash, f)
- @config[:marshal] = MARSHAL
end
! STDERR.puts "done"
! rescue
! File.rename("#{file}.old", file) if File.exist?("#{file}.old")
! warn "Error: Failed to save (#{file}) : #{$!}"
end
end
end
--- 325,379 ----
def load_object_file(file)
! if File.exists?(file)
! STDERR.print "Loading object (#{file}) ... "
! begin
! bind = Bio::Shell.cache[:binding]
! hash = Marshal.load(File.read(file))
! hash.each do |k, v|
! begin
! Thread.current[:restore_value] = v
! eval("#{k} = Thread.current[:restore_value]", bind)
! rescue
! STDERR.puts "Warning: object '#{k}' couldn't be loaded : #{$!}"
end
end
! rescue
! warn "Error: Failed to load (#{file}) : #{$!}"
end
+ STDERR.puts "done"
end
end
def save_object
! save_object_file(object_file)
end
def save_object_file(file)
! begin
! STDERR.print "Saving object (#{file}) ... "
! File.rename(file, "#{file}.old") if File.exist?(file)
! File.open(file, "w") do |f|
! bind = Bio::Shell.cache[:binding]
! list = eval("local_variables", bind)
! list -= ["_"]
! hash = {}
! list.each do |elem|
! value = eval(elem, bind)
! if value
! begin
! Marshal.dump(value)
! hash[elem] = value
! rescue
! # value could not be dumped.
end
end
end
! Marshal.dump(hash, f)
! @config[:marshal] = MARSHAL
end
+ STDERR.puts "done"
+ rescue
+ File.rename("#{file}.old", file) if File.exist?("#{file}.old")
+ warn "Error: Failed to save (#{file}) : #{$!}"
end
end
***************
*** 371,377 ****
def open_history
! Dir.chdir(@cache[:workdir]) do |path|
! @cache[:histfile] = File.open(SAVEDIR + HISTORY, "a")
! end
@cache[:histfile].sync = true
end
--- 382,386 ----
def open_history
! @cache[:histfile] = File.open(history_file, "a")
@cache[:histfile].sync = true
end
***************
*** 388,407 ****
def load_history
if @cache[:readline]
! load_history_file(SAVEDIR + HISTORY)
end
end
def load_history_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! if File.exists?(file)
! STDERR.print "Loading history (#{path}/#{file}) ... "
! File.open(file).each do |line|
! unless line[/^# /]
! Readline::HISTORY.push line.chomp
! end
end
end
- STDERR.puts "done"
end
end
--- 397,414 ----
def load_history
if @cache[:readline]
! load_history_file(history_file)
end
end
def load_history_file(file)
! if File.exists?(file)
! STDERR.print "Loading history (#{file}) ... "
! File.open(file).each do |line|
! unless line[/^# /]
! Readline::HISTORY.push line.chomp
end
end
end
+ STDERR.puts "done"
end
***************
*** 409,427 ****
def save_history
if @cache[:readline]
! save_history_file(SAVEDIR + HISTORY)
end
end
def save_history_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! begin
! STDERR.print "Saving history (#{path}/#{file}) ... "
! File.open(file, "w") do |f|
! f.puts Readline::HISTORY.to_a
! end
! STDERR.puts "done"
! rescue
! warn "Error: Failed to save (#{path}/#{file}) : #{$!}"
end
end
end
--- 416,432 ----
def save_history
if @cache[:readline]
! save_history_file(history_file)
end
end
def save_history_file(file)
! begin
! STDERR.print "Saving history (#{file}) ... "
! File.open(file, "w") do |f|
! f.puts Readline::HISTORY.to_a
end
+ STDERR.puts "done"
+ rescue
+ warn "Error: Failed to save (#{file}) : #{$!}"
end
end
***************
*** 462,476 ****
def save_script
if @script_begin and @script_end and @script_begin <= @script_end
! Dir.chdir(@cache[:workdir]) do |path|
! if File.exists?(SCRIPT)
! message = "Overwrite script file (#{path}/#{SCRIPT})? [y/n] "
! else
! message = "Save script file (#{path}/#{SCRIPT})? [y/n] "
! end
! if ask_yes_or_no(message)
! save_script_file(SCRIPT)
! else
! STDERR.puts " ... save aborted."
! end
end
elsif @script_begin and @script_end and @script_begin - @script_end == 1
--- 467,479 ----
def save_script
if @script_begin and @script_end and @script_begin <= @script_end
! if File.exists?(script_file)
! message = "Overwrite script file (#{script_file})? [y/n] "
! else
! message = "Save script file (#{script_file})? [y/n] "
! end
! if ask_yes_or_no(message)
! save_script_file(script_file)
! else
! STDERR.puts " ... save aborted."
end
elsif @script_begin and @script_end and @script_begin - @script_end == 1
***************
*** 482,499 ****
def save_script_file(file)
! Dir.chdir(@cache[:workdir]) do |path|
! begin
! STDERR.print "Saving script (#{path}/#{file}) ... "
! File.open(file, "w") do |f|
! f.puts "#!/usr/bin/env bioruby"
! f.puts
! f.puts Readline::HISTORY.to_a[@script_begin.. at script_end]
! f.puts
! end
! STDERR.puts "done"
! rescue
! @script_begin = nil
! warn "Error: Failed to save (#{path}/#{file}) : #{$!}"
end
end
end
--- 485,500 ----
def save_script_file(file)
! begin
! STDERR.print "Saving script (#{file}) ... "
! File.open(file, "w") do |f|
! f.puts "#!/usr/bin/env bioruby"
! f.puts
! f.puts Readline::HISTORY.to_a[@script_begin.. at script_end]
! f.puts
end
+ STDERR.puts "done"
+ rescue
+ @script_begin = nil
+ warn "Error: Failed to save (#{file}) : #{$!}"
end
end
More information about the bioruby-cvs
mailing list