commit 44648f836854c616d6b78a07abb0eeea8f637a4d
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Sun Apr 4 16:39:50 2010 +0200

    [cleanup] split 'lib/cyborghood/base.rb' and reorganized requires a bit

diff --git a/.gitignore b/.gitignore
index f994d21..99e056d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,7 @@
 \#*#
 # generated by installer
 .config
-lib/cyborghood/config.rb
+lib/cyborghood/config_setup.rb
 data/locale
 #
 conf
diff --git a/Rakefile b/Rakefile
index af35742..8d068e3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,7 @@ ENV['LC_ALL'] = "C"
 
 require 'rake'
 require 'gettext/utils'
-require 'lib/cyborghood/config'
+require 'lib/cyborghood/config_setup'
 require 'lib/cyborghood/info'
 
 namespace :i18n do
diff --git a/bin/postman b/bin/postman
index 47b34b1..32968ac 100755
--- a/bin/postman
+++ b/bin/postman
@@ -24,7 +24,7 @@ $: << File.join(File.dirname(__FILE__), "..", "lib")
 #require 'socket'
 require 'tempfile'
 require 'shellwords'
-require 'cyborghood/language'
+require 'cyborghood'
 require 'cyborghood/imap'
 require 'cyborghood/mail'
 require 'cyborghood/mail_order'
diff --git a/bin/postman_daemon b/bin/postman_daemon
index 99bd277..74a7e4a 100755
--- a/bin/postman_daemon
+++ b/bin/postman_daemon
@@ -22,7 +22,7 @@
 $: << File.join(File.dirname(__FILE__), "..", "lib")
 
 require 'daemons'
-require 'cyborghood/config'
+require 'cyborghood/config_setup'
 
 options = {
   :app_name     => "CyborgHood_Postman",
diff --git a/lib/cyborghood.rb b/lib/cyborghood.rb
new file mode 100644
index 0000000..ea0c71b
--- /dev/null
+++ b/lib/cyborghood.rb
@@ -0,0 +1,31 @@
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+$KCODE = 'UTF8'
+require 'jcode'
+require "cyborghood/config"
+require "cyborghood/info"
+require "cyborghood/lang_additions"
+require 'cyborghood/logger'
+require 'cyborghood/language'
+require 'cyborghood/exceptions'
+
+module CyborgHood
+  include I18nTranslation
+  bindtextdomain("cyborghood", {:path => Config::L10N_DIR, :charset => "UTF-8"})
+end
diff --git a/lib/cyborghood/base.rb b/lib/cyborghood/base.rb
deleted file mode 100644
index ed0d831..0000000
--- a/lib/cyborghood/base.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-#--
-# CyborgHood, a distributed system management software.
-# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#++
-
-$KCODE = 'UTF8'
-require 'jcode'
-require 'singleton'
-require 'yaml'
-require 'log4r'
-require "cyborghood/config"
-require "cyborghood/info"
-require "cyborghood/lang_additions"
-require 'cyborghood/language'
-
-module CyborgHood
-  include I18nTranslation
-  bindtextdomain("cyborghood", {:path => Config::L10N_DIR, :charset => "UTF-8"})
-
-  # severities: :grave :unrecoverable :processable :ignorable
-  # categories:
-  #  - db (not a protocol?)
-  #    + ldap
-  #    + sql
-  #  - protocol
-  #    + imap
-  #    + mail
-  #  - service
-  #    + dns
-  class CyberError < StandardError
-    attr_accessor :severity, :category
-
-    #include GetTextSupport
-
-    def initialize(severity, category, message)
-      @severity = severity
-      @category = category
-      super(message)
-    end
-  end
-
-  class Logger < Log4r::Logger
-    include Singleton
-
-    LOG_FORMAT = "[%5l - %d] #PREFIX#%m"
-
-    def output_level(level)
-      l = case level
-      when :verbose
-        Log4r::DEBUG
-      when :quiet
-        Log4r::FATAL
-      else # normal
-        Log4r::WARN
-      end
-      @main_outputter.level = l
-    end
-
-    def log_to_file(filename)
-      file_outputter = Log4r::FileOutputter.new(filename, :filename => filename)
-      file_outputter.formatter = @default_formatter
-      self.outputters << file_outputter
-    end
-
-    def set_prefix(prefix = "")
-      prefix ||= ""
-      log_format = LOG_FORMAT.gsub("#PREFIX#", prefix)
-      @default_formatter = Log4r::PatternFormatter.new(:pattern => log_format)
-      self.outputters.each{|outputter| outputter.formatter = @default_formatter }
-    end
-
-    private
-
-    def initialize
-      super(PRODUCT)
-
-      self.level = Log4r::DEBUG
-      @main_outputter = Log4r::Outputter.stdout
-      @main_outputter.level = Log4r::WARN
-      self.outputters = [@main_outputter]
-
-      set_prefix()
-    end
-  end
-
-  class Config
-    include Singleton
-
-    CONFFILE_GLOBAL = "cyborghood.conf"
-    CONFFILE_BOT = "cyborghood_%s.conf"
-
-    def self.load(name = nil)
-      # load all config parts
-      config = fetch_config
-      unless name.nil?
-        config_spc = fetch_config(name)
-        config = merge_configs(config, config_spc) if config_spc
-      end
-
-      # create config object for easier access
-      @@config = config.to_ostruct.freeze
-    end
-
-    def method_missing(sym, *args, &block)
-      begin
-        @@config.send sym, *args, &block
-      rescue
-        nil
-      end
-    end
-
-    private
-
-    def self.fetch_config(name = nil)
-      begin
-        if name.nil?
-          filename = CONFFILE_GLOBAL
-        else
-          filename = sprintf(CONFFILE_BOT, name)
-        end
-        filepath = File.join(File.expand_path(CFG_DIR), filename)
-        str = File.read(filepath)
-        YAML.load(str)
-      rescue
-        logger.fatal "Problems fetching configuration file '" + filepath + "': " + $!
-        exit 1
-      end
-    end
-
-    def self.merge_configs(conf1, conf2)
-      new_conf = conf1.dup
-      conf2.each_pair do |k, v|
-        if conf1.has_key?(k) and conf1[k].is_a?(Hash) and v.is_a?(Hash)
-          new_conf[k] = merge_configs(conf1[k], v)
-        else
-          new_conf[k] = v
-        end
-      end
-      return new_conf
-    end
-  end
-end
diff --git a/lib/cyborghood/config.rb b/lib/cyborghood/config.rb
new file mode 100644
index 0000000..a87c417
--- /dev/null
+++ b/lib/cyborghood/config.rb
@@ -0,0 +1,80 @@
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+require 'singleton'
+require 'yaml'
+require "cyborghood/config_setup"
+
+module CyborgHood
+  class Config
+    include Singleton
+
+    CONFFILE_GLOBAL = "cyborghood.conf"
+    CONFFILE_BOT = "cyborghood_%s.conf"
+
+    def self.load(name = nil)
+      # load all config parts
+      config = fetch_config
+      unless name.nil?
+        config_spc = fetch_config(name)
+        config = merge_configs(config, config_spc) if config_spc
+      end
+
+      # create config object for easier access
+      @@config = config.to_ostruct.freeze
+    end
+
+    def method_missing(sym, *args, &block)
+      begin
+        @@config.send sym, *args, &block
+      rescue
+        nil
+      end
+    end
+
+    private
+
+    def self.fetch_config(name = nil)
+      begin
+        if name.nil?
+          filename = CONFFILE_GLOBAL
+        else
+          filename = sprintf(CONFFILE_BOT, name)
+        end
+        filepath = File.join(File.expand_path(CFG_DIR), filename)
+        str = File.read(filepath)
+        YAML.load(str)
+      rescue
+        logger.fatal "Problems fetching configuration file '" + filepath + "': " + $!
+        exit 1
+      end
+    end
+
+    def self.merge_configs(conf1, conf2)
+      new_conf = conf1.dup
+      conf2.each_pair do |k, v|
+        if conf1.has_key?(k) and conf1[k].is_a?(Hash) and v.is_a?(Hash)
+          new_conf[k] = merge_configs(conf1[k], v)
+        else
+          new_conf[k] = v
+        end
+      end
+      return new_conf
+    end
+  end
+end
diff --git a/lib/cyborghood/cyborg.rb b/lib/cyborghood/cyborg.rb
index 936780b..3d89656 100644
--- a/lib/cyborghood/cyborg.rb
+++ b/lib/cyborghood/cyborg.rb
@@ -16,7 +16,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
-require 'cyborghood/base'
 require 'xmpp4r'
 require 'xmpp4r/presence'
 require 'xmpp4r/version/iq/version'
diff --git a/lib/cyborghood/exceptions.rb b/lib/cyborghood/exceptions.rb
new file mode 100644
index 0000000..fefe96c
--- /dev/null
+++ b/lib/cyborghood/exceptions.rb
@@ -0,0 +1,41 @@
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+module CyborgHood
+  # severities: :grave :unrecoverable :processable :ignorable
+  # categories:
+  #  - db (not a protocol?)
+  #    + ldap
+  #    + sql
+  #  - protocol
+  #    + imap
+  #    + mail
+  #  - service
+  #    + dns
+  class CyberError < StandardError
+    attr_accessor :severity, :category
+
+    #include GetTextSupport
+
+    def initialize(severity, category, message)
+      @severity = severity
+      @category = category
+      super(message)
+    end
+  end
+end
diff --git a/lib/cyborghood/imap.rb b/lib/cyborghood/imap.rb
index 3034af3..b8c33c5 100644
--- a/lib/cyborghood/imap.rb
+++ b/lib/cyborghood/imap.rb
@@ -16,7 +16,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
-require 'cyborghood/base'
 require 'net/imap'
 
 module CyborgHood
diff --git a/lib/cyborghood/logger.rb b/lib/cyborghood/logger.rb
new file mode 100644
index 0000000..85a0985
--- /dev/null
+++ b/lib/cyborghood/logger.rb
@@ -0,0 +1,66 @@
+#--
+# CyborgHood, a distributed system management software.
+# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#++
+
+require 'singleton'
+require 'log4r'
+
+module CyborgHood
+  class Logger < Log4r::Logger
+    include Singleton
+
+    LOG_FORMAT = "[%5l - %d] #PREFIX#%m"
+
+    def output_level(level)
+      l = case level
+      when :verbose
+        Log4r::DEBUG
+      when :quiet
+        Log4r::FATAL
+      else # normal
+        Log4r::WARN
+      end
+      @main_outputter.level = l
+    end
+
+    def log_to_file(filename)
+      file_outputter = Log4r::FileOutputter.new(filename, :filename => filename)
+      file_outputter.formatter = @default_formatter
+      self.outputters << file_outputter
+    end
+
+    def set_prefix(prefix = "")
+      prefix ||= ""
+      log_format = LOG_FORMAT.gsub("#PREFIX#", prefix)
+      @default_formatter = Log4r::PatternFormatter.new(:pattern => log_format)
+      self.outputters.each{|outputter| outputter.formatter = @default_formatter }
+    end
+
+    private
+
+    def initialize
+      super(PRODUCT)
+
+      self.level = Log4r::DEBUG
+      @main_outputter = Log4r::Outputter.stdout
+      @main_outputter.level = Log4r::WARN
+      self.outputters = [@main_outputter]
+
+      set_prefix()
+    end
+  end
+end
diff --git a/lib/cyborghood/mail.rb b/lib/cyborghood/mail.rb
index 1d9cce0..fddacf1 100644
--- a/lib/cyborghood/mail.rb
+++ b/lib/cyborghood/mail.rb
@@ -24,7 +24,6 @@ Dir.new(DEB_RAILS_PATH).each do |file|
         $: << path if File.directory?(path)
 end
 
-require 'cyborghood/base'
 require 'delegate'
 require 'tmail'
 require 'tmail_gpg'
diff --git a/lib/cyborghood/objects.rb b/lib/cyborghood/objects.rb
index 681e819..ccbdb36 100644
--- a/lib/cyborghood/objects.rb
+++ b/lib/cyborghood/objects.rb
@@ -16,7 +16,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
-require 'cyborghood/base'
 require 'delegate'
 require 'cyborghood/objects/ldap'
 require 'http_headers'
diff --git a/post-clean.rb b/post-clean.rb
index c4991c8..d87ba3d 100644
--- a/post-clean.rb
+++ b/post-clean.rb
@@ -18,5 +18,5 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #++
 
-conffile = "lib/cyborghood/config.rb"
+conffile = "lib/cyborghood/config_setup.rb"
 File.unlink(conffile) if FileTest.exists?(conffile)
diff --git a/post-config.rb b/post-config.rb
index 6a35b94..5d12799 100644
--- a/post-config.rb
+++ b/post-config.rb
@@ -20,7 +20,7 @@
 
 # General header.
 header = <<HEADER
-# config.rb - Coin-diff setup configuration
+# config_setup.rb - Coin-diff setup configuration
 
 #--
 # CyborgHood, a distributed system management software.
@@ -45,9 +45,9 @@ header = <<HEADER
 
 HEADER
 
-# Generate config.rb containing general compile/setup time configuration
+# Generate config_setup.rb containing general compile/setup time configuration
 # information (in the CoinDiff::Config module).
-File.open('lib/cyborghood/config.rb', 'w') do |file|
+File.open('lib/cyborghood/config_setup.rb', 'w') do |file|
 
   file.print header
   file.print <<-CONFIG
