class Roma::KeyAccess

Public Class Methods

new(argv) click to toggle source
   # File lib/roma/tools/key_access.rb
14 def initialize(argv)
15   options(argv)
16   
17   each_hash(@path){|hname, dir|
18     puts "hash : #{hname}"
19     st = open_storage(dir)
20 
21     vn, last, clk, expt, value = st.get_raw2(@key)
22     if vn
23       if @sv
24         puts "vnode: #{vn}"
25         puts "last : #{Time.at(last)}"
26         puts "clock: #{clk}"
27         puts "expt : #{Time.at(expt)}"
28         begin
29           puts "value #{Marshal.load(value)}"
30         rescue
31           puts "value: #{value}"
32         end
33       else
34         puts "exist"
35       end
36       st.closedb
37       return
38     end
39 
40     st.closedb
41   }
42   puts "not exist"
43 end

Public Instance Methods

each_hash(path) { |hname,dir| ... } click to toggle source
   # File lib/roma/tools/key_access.rb
61 def each_hash(path)
62   Dir::glob("#{path}/*").each{|dir|
63     next unless File::directory?(dir)
64     hname = dir[dir.rindex('/')+1..-1]
65     yield hname,dir
66   }     
67 end
new_storage(ext) click to toggle source
   # File lib/roma/tools/key_access.rb
88 def new_storage(ext)
89   case(ext)
90   when 'tc'
91     return ::Roma::Storage::TCStorage.new
92   when 'dbm'
93     return Roma::Storage::DbmStorage.new
94   when 'sql3'
95     return Roma::Storage::SQLite3Storage.new
96   else
97     return nil
98   end
99 end
open_storage(path) click to toggle source
   # File lib/roma/tools/key_access.rb
69 def open_storage(path)
70   unless File::directory?(path)
71     STDERR.puts "#{path} does not found."
72     return nil
73   end
74 
75   # get a file extension
76   ext = File::extname(Dir::glob("#{path}/0.*")[0])[1..-1]
77   # count a number of divided files
78   divnum = Dir::glob("#{path}/*.#{ext}").length
79     
80   st = new_storage(ext)
81   st.divnum = divnum
82   st.vn_list = []
83   st.storage_path = path
84   st.opendb
85   st
86 end
options(argv) click to toggle source
   # File lib/roma/tools/key_access.rb
45 def options(argv)
46   opts = OptionParser.new
47   opts.banner="usage:#{File.basename($0)} storage-path key"
48   
49   @sv = false
50   opts.on("-v","--value","show value") { |v| @sv = true }
51 
52   opts.parse!(argv)
53   raise OptionParser::ParseError.new if argv.length < 2
54   @path = argv[0]
55   @key = argv[1]
56 rescue OptionParser::ParseError => e
57   STDERR.puts opts.help
58   exit 1
59 end