[BioRuby-cvs] bioruby/lib/bio/shell core.rb, 1.9, 1.10 session.rb, 1.5, 1.6

Katayama Toshiaki k at pub.open-bio.org
Thu Nov 24 14:30:10 EST 2005


Update of /home/repository/bioruby/bioruby/lib/bio/shell
In directory pub.open-bio.org:/tmp/cvs-serv21764/lib/bio/shell

Modified Files:
	core.rb session.rb 
Log Message:
* global variable $bioruby_config and $bioruby_cache are removed (changed to
  use Bio::Shell::Core::Config & Cache, which have accessor methods like
  Bio::Shell.config(param, value), Bio::Shell.cache(param, value))


Index: session.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/session.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** session.rb	14 Nov 2005 02:01:54 -0000	1.5
--- session.rb	24 Nov 2005 19:30:08 -0000	1.6
***************
*** 48,61 ****
    end
  
    ### config
  
    def config(mode = :show, *opts)
!     Bio::Shell.config(mode, *opts)
    end
  
!   ### script
  
!   def script(mode = nil)
!     Bio::Shell.script(mode)
    end
  
--- 48,82 ----
    end
  
+   ### script
+ 
+   def script(mode = nil)
+     Bio::Shell.script(mode)
+   end
+ 
    ### config
  
    def config(mode = :show, *opts)
!     case mode
!     when :show, "show"
!       Bio::Shell.config_show
!     when :echo, "echo"
!       Bio::Shell.config_echo
!     when :color, "color"
!       Bio::Shell.config_color
!     when :pager, "pager"
!       Bio::Shell.config_pager(*opts)
!     when :message, "message"
!       Bio::Shell.config_message(*opts)
!     end
    end
  
!   def reload_config
!     Bio::Shell.load_config
!   end
  
!   ### object
! 
!   def reload_object
!     Bio::Shell.load_object
    end
  
***************
*** 68,71 ****
--- 89,100 ----
    ### pager
  
+   def pager(cmd = nil)
+     unless Bio::Shell.config(:pager)
+       cmd = ENV['PAGER'] || cmd
+     end
+     Bio::Shell.config_pager(cmd)
+     puts "Pager is set to '#{cmd ? cmd : 'off'}'"
+   end
+ 
    #--
    # mysql> pager less
***************
*** 73,78 ****
    def display(*obj)
      # The original idea is from http://sheepman.parfait.ne.jp/20050215.html
!     if $bioruby_config[:PAGER]
!       pg = IO.popen($bioruby_config[:PAGER], "w")
        begin
          stdout_save = STDOUT.clone
--- 102,107 ----
    def display(*obj)
      # The original idea is from http://sheepman.parfait.ne.jp/20050215.html
!     if Bio::Shell.config(:pager)
!       pg = IO.popen(Bio::Shell.config(:pager), "w")
        begin
          stdout_save = STDOUT.clone
***************
*** 89,92 ****
--- 118,141 ----
    end
  
+   def less(file)
+     #Readline.completion_proc = proc {|p|
+     #  Dir.glob("#{p}*")
+     #}
+     pager = ENV['PAGER'] || "less"
+     system("#{pager} #{file}")
+   end
+ 
+   def head(file, num = 10)
+     str = ""
+     File.open(file) do |f|
+       num.times do
+         if line = f.gets
+           str << line
+         end
+       end
+     end
+     display str
+   end
+ 
    ### file system
  
***************
*** 125,140 ****
        display str
      end
-   end
- 
-   def head(file, num = 10)
-     str = ""
-     File.open(file) do |f|
-       num.times do
-         if line = f.gets
-           str << line
-         end
-       end
-     end
-     display str
    end
  
--- 174,177 ----

Index: core.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/core.rb,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** core.rb	24 Nov 2005 16:57:43 -0000	1.9
--- core.rb	24 Nov 2005 19:30:08 -0000	1.10
***************
*** 56,59 ****
--- 56,81 ----
    }
  
+   # A hash to store persistent configurations
+   Config = {}
+ 
+   # A hash to store temporal (per session) configurations
+   Cache  = {}
+ 
+   attr_accessor :config, :cache
+ 
+   def config(param, value = nil)
+     if value
+       Config[param] = value
+     end
+     return Config[param]
+   end
+ 
+   def cache(param, value = nil)
+     if value
+       Cache[param] = value
+     end
+     return Cache[param]
+   end
+ 
    ### save/restore the environment
  
***************
*** 64,76 ****
    end
  
-   #--
-   # *TODO* is this needed? (for reset)
-   #++
-   def reload
-     load_config
-     load_plugin
-     load_object
-   end
- 
    def open
      load_object
--- 86,89 ----
***************
*** 112,116 ****
        raise "BioRuby shell runs on Ruby version >= 1.8.2"
      end
!     if $bioruby_config[:MARSHAL] and $bioruby_config[:MARSHAL] != MARSHAL
        raise "Marshal version mismatch"
      end
--- 125,129 ----
        raise "BioRuby shell runs on Ruby version >= 1.8.2"
      end
!     if Config[:marshal] and Config[:marshal] != MARSHAL
        raise "Marshal version mismatch"
      end
***************
*** 127,134 ****
    # 1. ask to save in SAVEDIR directory in the current directory
    # 2. otherwise save in USERDIR directory
!   # 3. remember the choice in $bioruby_cache[:SAVEDIR] once per session
    def ask_save_dir
!     if $bioruby_cache[:SAVEDIR]
!       dir = $bioruby_cache[:SAVEDIR]
      else
        dir = SAVEDIR
--- 140,147 ----
    # 1. ask to save in SAVEDIR directory in the current directory
    # 2. otherwise save in USERDIR directory
!   # 3. remember the choice in Cache[:savedir] once per session
    def ask_save_dir
!     if Cache[:savedir]
!       dir = Cache[:savedir]
      else
        dir = SAVEDIR
***************
*** 145,149 ****
          end
        end
!       $bioruby_cache[:SAVEDIR] = dir
      end
      return dir
--- 158,162 ----
          end
        end
!       Cache[:savedir] = dir
      end
      return dir
***************
*** 174,178 ****
        print "Loading config (#{file}) ... "
        if hash = YAML.load(File.read(file))
!         $bioruby_config.update(hash)
        end
        puts "done"
--- 187,191 ----
        print "Loading config (#{file}) ... "
        if hash = YAML.load(File.read(file))
!         Config.update(hash)
        end
        puts "done"
***************
*** 189,193 ****
        print "Saving config (#{file}) ... "
        File.open(file, "w") do |f|
!         f.puts $bioruby_config.to_yaml
        end
        puts "done"
--- 202,206 ----
        print "Saving config (#{file}) ... "
        File.open(file, "w") do |f|
!         f.puts Config.to_yaml
        end
        puts "done"
***************
*** 197,217 ****
    end
  
-   def config(mode, *opts)
-     case mode
-     when :show, "show"
-       config_show
-     when :echo, "echo"
-       config_echo
-     when :color, "color"
-       config_color
-     when :pager, "pager"
-       config_pager(*opts)
-     when :message, "message"
-       config_message(*opts)
-     end
-   end
- 
    def config_show
!     $bioruby_config.each do |k, v|
        puts "#{k}\t= #{v.inspect}"
      end
--- 210,215 ----
    end
  
    def config_show
!     Config.each do |k, v|
        puts "#{k}\t= #{v.inspect}"
      end
***************
*** 220,225 ****
    def config_echo
      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
!     flag = ! $bioruby_config[:ECHO]
!     $bioruby_config[:ECHO] = IRB.conf[:ECHO] = flag
      eval("conf.echo = #{flag}", bind)
      puts "Echo #{flag ? 'on' : 'off'}"
--- 218,223 ----
    def config_echo
      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
!     flag = ! Config[:echo]
!     Config[:echo] = IRB.conf[:ECHO] = flag
      eval("conf.echo = #{flag}", bind)
      puts "Echo #{flag ? 'on' : 'off'}"
***************
*** 228,233 ****
    def config_color
      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
!     flag = ! $bioruby_config[:COLOR]
!     $bioruby_config[:COLOR] = flag
      if flag
        IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
--- 226,231 ----
    def config_color
      bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
!     flag = ! Config[:color]
!     Config[:color] = flag
      if flag
        IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
***************
*** 240,249 ****
  
    def config_pager(cmd = nil)
!     $bioruby_config[:PAGER] = cmd
    end
  
    def config_message(str = nil)
      str ||= Bio::Shell::Core::MESSAGE
!     $bioruby_config[:MESSAGE] = str
    end
  
--- 238,247 ----
  
    def config_pager(cmd = nil)
!     Config[:pager] = cmd
    end
  
    def config_message(str = nil)
      str ||= Bio::Shell::Core::MESSAGE
!     Config[:message] = str
    end
  
***************
*** 321,325 ****
            end
            Marshal.dump(hash, f)
!           $bioruby_config[:MARSHAL] = MARSHAL
          rescue
            raise "Failed to dump (#{file}) : #{$!}"
--- 319,323 ----
            end
            Marshal.dump(hash, f)
!           Config[:marshal] = MARSHAL
          rescue
            raise "Failed to dump (#{file}) : #{$!}"
***************
*** 336,340 ****
  
    def load_history
!     if $bioruby_cache[:READLINE]
        load_history_file(SITEDIR + HISTORY)
        load_history_file(USERDIR + HISTORY)
--- 334,338 ----
  
    def load_history
!     if Cache[:readline]
        load_history_file(SITEDIR + HISTORY)
        load_history_file(USERDIR + HISTORY)
***************
*** 354,358 ****
    
    def save_history
!     if $bioruby_cache[:READLINE]
        dir = create_save_dir
        save_history_file(dir + HISTORY)
--- 352,356 ----
    
    def save_history
!     if Cache[:readline]
        dir = create_save_dir
        save_history_file(dir + HISTORY)
***************
*** 377,393 ****
      case mode
      when :begin, "begin", :start, "start"
!       $bioruby_cache[:SCRIPT] = true
        script_begin
      when :end, "end", :stop, "stop"
!       $bioruby_cache[:SCRIPT] = false
        script_end
        save_script
      else
!       if $bioruby_cache[:SCRIPT]
!         $bioruby_cache[:SCRIPT] = false
          script_end
          save_script
        else
!         $bioruby_cache[:SCRIPT] = true
          script_begin
        end
--- 375,391 ----
      case mode
      when :begin, "begin", :start, "start"
!       Cache[:script] = true
        script_begin
      when :end, "end", :stop, "stop"
!       Cache[:script] = false
        script_end
        save_script
      else
!       if Cache[:script]
!         Cache[:script] = false
          script_end
          save_script
        else
!         Cache[:script] = true
          script_begin
        end
***************
*** 434,439 ****
  
    def splash_message
!     $bioruby_config[:MESSAGE] ||= MESSAGE
!     $bioruby_config[:MESSAGE].to_s.split(//).join(" ")
    end
  
--- 432,437 ----
  
    def splash_message
!     Config[:message] ||= MESSAGE
!     Config[:message].to_s.split(//).join(" ")
    end
  
***************
*** 452,456 ****
  
      print "\n"
!     if $bioruby_config[:COLOR]
        0.step(l,2) do |i|
          l1 = l-i;  l2 = l1/2;  l4 = l2/2
--- 450,454 ----
  
      print "\n"
!     if Config[:color]
        0.step(l,2) do |i|
          l1 = l-i;  l2 = l1/2;  l4 = l2/2
***************
*** 465,469 ****
        end
      end
!     if $bioruby_config[:COLOR]
        print splash_message_color
      else
--- 463,467 ----
        end
      end
!     if Config[:color]
        print splash_message_color
      else
***************
*** 477,481 ****
    def closing_splash
      print "\n\n"
!     if $bioruby_config[:COLOR]
        print splash_message_color
      else
--- 475,479 ----
    def closing_splash
      print "\n\n"
!     if Config[:color]
        print splash_message_color
      else



More information about the bioruby-cvs mailing list