Class: Roma::KeyList
- Inherits:
-
Object
- Object
- Roma::KeyList
- Defined in:
- lib/roma/tools/key_list.rb
Instance Method Summary collapse
- #each_hash(path) ⇒ Object
-
#initialize(strgpath, param_sleep) ⇒ KeyList
constructor
A new instance of KeyList.
- #new_storage(ext) ⇒ Object
- #open_storage(path) ⇒ Object
Constructor Details
#initialize(strgpath, param_sleep) ⇒ KeyList
Returns a new instance of KeyList.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/roma/tools/key_list.rb', line 14 def initialize(strgpath, param_sleep) each_hash(strgpath){|hname, dir| STDERR.puts "### #{hname} #{dir}" st = open_storage(dir) c = 0 n = st.true_length m = n / 100 m = 1 if m < 1 st.divnum.times{|i| st.each_hdb_dump(i){|data| c += 1 STDERR.print "#{c}/#{n}\r" if c % m == 0 vn, last, clk, expt, klen = data.unpack('NNNNN') key, = data[20..-1].unpack("a#{klen}") STDOUT.puts key sleep param_sleep } } st.closedb STDERR.puts "\ndone" } end |
Instance Method Details
#each_hash(path) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/roma/tools/key_list.rb', line 39 def each_hash(path) Dir::glob("#{path}/*").each{|dir| next unless File::directory?(dir) hname = dir[dir.rindex('/')+1..-1] yield hname,dir } end |
#new_storage(ext) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/roma/tools/key_list.rb', line 66 def new_storage(ext) case(ext) when 'tc' return ::Roma::Storage::TCStorage.new when 'dbm' return Roma::Storage::DbmStorage.new when 'sql3' return Roma::Storage::SQLite3Storage.new else return nil end end |
#open_storage(path) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/roma/tools/key_list.rb', line 47 def open_storage(path) unless File::directory?(path) STDERR.puts "#{path} does not found." return nil end # get a file extension ext = File::extname(Dir::glob("#{path}/0.*")[0])[1..-1] # count a number of divided files divnum = Dir::glob("#{path}/*.#{ext}").length st = new_storage(ext) st.divnum = divnum st.vn_list = [] st.storage_path = path st.opendb st end |