class Roma::KeyList

Public Class Methods

new(strgpath, param_sleep) click to toggle source
   # File lib/roma/tools/key_list.rb
14 def initialize(strgpath, param_sleep)
15   each_hash(strgpath){|hname, dir|
16     STDERR.puts "### #{hname} #{dir}"
17     st = open_storage(dir)
18 
19     c = 0
20     n = st.true_length
21     m = n / 100
22     m = 1 if m < 1
23     st.divnum.times{|i|
24       st.each_hdb_dump(i){|data|
25         c += 1
26         STDERR.print "#{c}/#{n}\r" if c % m == 0
27         vn, last, clk, expt, klen = data.unpack('NNNNN')
28         key, = data[20..-1].unpack("a#{klen}")
29         STDOUT.puts key
30         sleep param_sleep
31       }
32     }
33 
34     st.closedb
35     STDERR.puts "\ndone"
36   }
37 end

Public Instance Methods

each_hash(path) { |hname,dir| ... } click to toggle source
   # File lib/roma/tools/key_list.rb
39 def each_hash(path)
40   Dir::glob("#{path}/*").each{|dir|
41     next unless File::directory?(dir)
42     hname = dir[dir.rindex('/')+1..-1]
43     yield hname,dir
44   }     
45 end
new_storage(ext) click to toggle source
   # File lib/roma/tools/key_list.rb
66 def new_storage(ext)
67   case(ext)
68   when 'tc'
69     return ::Roma::Storage::TCStorage.new
70   when 'dbm'
71     return Roma::Storage::DbmStorage.new
72   when 'sql3'
73     return Roma::Storage::SQLite3Storage.new
74   else
75     return nil
76   end
77 end
open_storage(path) click to toggle source
   # File lib/roma/tools/key_list.rb
47 def open_storage(path)
48   unless File::directory?(path)
49     STDERR.puts "#{path} does not found."
50     return nil
51   end
52 
53   # get a file extension
54   ext = File::extname(Dir::glob("#{path}/0.*")[0])[1..-1]
55   # count a number of divided files
56   divnum = Dir::glob("#{path}/*.#{ext}").length
57     
58   st = new_storage(ext)
59   st.divnum = divnum
60   st.vn_list = []
61   st.storage_path = path
62   st.opendb
63   st
64 end