[BioRuby-cvs] bioruby/lib/bio/shell session.rb,1.6,1.7

Katayama Toshiaki k at pub.open-bio.org
Fri Nov 25 12:26:56 EST 2005


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

Modified Files:
	session.rb 
Log Message:
* save file function is added


Index: session.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/session.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** session.rb	24 Nov 2005 19:30:08 -0000	1.6
--- session.rb	25 Nov 2005 17:26:54 -0000	1.7
***************
*** 40,48 ****
    end
  
!   def rm(name)                  # name = :hoge
      begin
!       eval("#{name} = nil", conf.workspace.binding)
      rescue
!       puts "Usage: rm :var (rm var is not valid)"
      end
    end
--- 40,55 ----
    end
  
!   def rm(name)
!     list = eval("local_variables", conf.workspace.binding).reject { |x|
!       eval(x, conf.workspace.binding).nil?
!     }
      begin
!       if list.include?(name.to_s)
!         eval("#{name} = nil", conf.workspace.binding)
!       else
!         raise
!       end
      rescue
!       warn "Usage: rm :var or rm 'var' (rm var is not valid)"
      end
    end
***************
*** 54,57 ****
--- 61,76 ----
    end
  
+   ### object
+ 
+   def reload_object
+     Bio::Shell.load_object
+   end
+ 
+   ### plugin
+ 
+   def reload_plugin
+     Bio::Shell.load_plugin
+   end
+ 
    ### config
  
***************
*** 75,90 ****
    end
  
-   ### object
- 
-   def reload_object
-     Bio::Shell.load_object
-   end
- 
-   ### plugin
- 
-   def reload_plugin
-     Bio::Shell.load_plugin
-   end
- 
    ### pager
  
--- 94,97 ----
***************
*** 97,103 ****
    end
  
-   #--
-   # mysql> pager less
-   #++
    def display(*obj)
      # The original idea is from http://sheepman.parfait.ne.jp/20050215.html
--- 104,107 ----
***************
*** 119,125 ****
  
    def less(file)
-     #Readline.completion_proc = proc {|p|
-     #  Dir.glob("#{p}*")
-     #}
      pager = ENV['PAGER'] || "less"
      system("#{pager} #{file}")
--- 123,126 ----
***************
*** 136,139 ****
--- 137,164 ----
      end
      display str
+   end
+ 
+   ### file save
+ 
+   def save(file, *objs)
+     if File.exists?(file)
+       loop do
+         print "Overwrite existing #{file}? [y/n]: "
+         answer = gets
+         return if /^\s*[Nn]/.match(answer)
+         break if /^\s*[Yy]/.match(answer)
+       end
+     end
+     begin
+       print "Saving data (#{file}) ... "
+       File.open(file, "w") do |f|
+         objs.each do |obj|
+           f.puts obj.to_s
+         end
+       end
+       puts "done"
+     rescue
+       warn "Error: Failed to save (#{file}) : #{$!}"
+     end
    end
  



More information about the bioruby-cvs mailing list