]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/registry.rb
+ (botuser + maskdb) fast netmask lookup + supplemental fixes for transient users
[user/henk/code/ruby/rbot.git] / lib / rbot / registry.rb
index 749f1830b26c803ef6dc5bde26b1be08aaa65ac5..358c80d68e0b30acd178627724b2de68b58ac508 100644 (file)
@@ -1,10 +1,11 @@
 require 'rbot/dbhash'
 
 module Irc
+class Bot
 
-  # this class is now used purely for upgrading from prior versions of rbot
+  # This class is now used purely for upgrading from prior versions of rbot
   # the new registry is split into multiple DBHash objects, one per plugin
-  class BotRegistry
+  class Registry
     def initialize(bot)
       @bot = bot
       upgrade_data
@@ -16,7 +17,7 @@ module Irc
     # work with is @bot.botclass.
     def upgrade_data
       if File.exist?("#{@bot.botclass}/registry.db")
-        log "upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format"
+        log _("upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format")
         old = BDB::Hash.open("#{@bot.botclass}/registry.db", nil,
                              "r+", 0600)
         new = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
@@ -36,7 +37,7 @@ module Irc
         Dir.mkdir("#{@bot.botclass}/registry") unless File.exist?("#{@bot.botclass}/registry")
         env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)# | BDB::TXN_NOSYNC)
         dbs = Hash.new
-        log "upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format"
+        log _("upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format")
         old = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
           "r+", 0600, "env" => env)
         old.each {|k,v|
@@ -49,13 +50,13 @@ module Irc
             dirs.length.times { |i|
               dir = dirs[0,i+1].join("/")+"/"
               unless File.exist?(dir)
-                log "creating subregistry directory #{dir}"
-                Dir.mkdir(dir) 
+                log _("creating subregistry directory #{dir}")
+                Dir.mkdir(dir)
               end
             }
           end
           unless dbs.has_key?(prefix)
-            log "creating db #{@bot.botclass}/registry/#{prefix}.db"
+            log _("creating db #{@bot.botclass}/registry/#{prefix}.db")
             dbs[prefix] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db",
               nil, BDB::CREATE | BDB::EXCL,
               0600, "env" => env)
@@ -65,13 +66,12 @@ module Irc
         old.close
         File.rename("#{@bot.botclass}/plugin_registry.db", "#{@bot.botclass}/plugin_registry.db.old")
         dbs.each {|k,v|
-          log "closing db #{k}"
+          log _("closing db #{k}")
           v.close
         }
         env.close
       end
     end
-  end
 
 
   # This class provides persistent storage for plugins via a hash interface.
@@ -94,7 +94,7 @@ module Irc
   # in object store mode, don't make the mistake of treating it like a live
   # object, e.g. (using the example above)
   #   @registry[:blah][:foo] = "flump"
-  # will NOT modify the object in the registry - remember that BotRegistry#[]
+  # will NOT modify the object in the registry - remember that Registry#[]
   # returns a Marshal.restore'd object, the object you just modified in place
   # will disappear. You would need to:
   #   blah = @registry[:blah]
@@ -117,11 +117,11 @@ module Irc
   # Your plugins section of the registry is private, it has its own namespace
   # (derived from the plugin's class name, so change it and lose your data).
   # Calls to registry.each etc, will only iterate over your namespace.
-  class BotRegistryAccessor
+  class Accessor
 
     attr_accessor :recovery
 
-    # plugins don't call this - a BotRegistryAccessor is created for them and
+    # plugins don't call this - a Registry::Accessor is created for them and
     # is accessible via @registry.
     def initialize(bot, name)
       @bot = bot
@@ -131,12 +131,12 @@ module Irc
         dir = dirs[0,i+1].join("/")+"/"
         unless File.exist?(dir)
           debug "creating subregistry directory #{dir}"
-          Dir.mkdir(dir) 
+          Dir.mkdir(dir)
         end
       }
       @registry = nil
       @default = nil
-      @recover = nil
+      @recovery = nil
       # debug "initializing registry accessor with name #{@name}"
     end
 
@@ -179,16 +179,14 @@ module Irc
       begin
         Marshal.restore(val)
       rescue Exception => e
-        error "failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default"
-        debug e.inspect
-        debug e.backtrace.join("\n")
-        if @recovery
+        error _("failed to restore marshal data for #{val.inspect}, attempting recovery or fallback to default")
+        debug e
+        if defined? @recovery and @recovery
           begin
             return @recovery.call(val)
           rescue Exception => ee
-            error "marshal recovery failed, trying default"
-            debug ee.inspect
-            debug ee.backtrace.join("\n")
+            error _("marshal recovery failed, trying default")
+            debug ee
           end
         end
         unless @default.nil?
@@ -317,7 +315,7 @@ module Irc
     end
 
     def sub_registry(prefix)
-      return BotRegistryAccessor.new(@bot, @name + "/" + prefix.to_s)
+      return Accessor.new(@bot, @name + "/" + prefix.to_s)
     end
 
     # returns the number of keys in your registry namespace
@@ -328,4 +326,6 @@ module Irc
 
   end
 
+  end
+end
 end