]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/rbotconfig.rb
First step towards the new modularized core framework
[user/henk/code/ruby/rbot.git] / lib / rbot / rbotconfig.rb
1 module Irc
2   module Config
3     @@datadir = nil
4     @@coredir = nil
5
6     # first try for the default path to the data dir
7     defaultdatadir = File.expand_path(File.dirname($0) + '/../data/rbot')
8     defaultcoredir = File.expand_path(File.dirname($0) + '/../lib/rbot/core')
9
10     if File.directory? defaultdatadir
11       @@datadir = defaultdatadir
12     end
13
14     if File.directory? defaultcoredir
15       @@coredir = defaultcoredir
16     end
17
18     # setup pkg-based configuration - i.e. where were we installed to, where
19     # are our data files, etc.
20     if @@datadir.nil? or @@coredir.nil?
21       begin
22         debug "trying to load rubygems"
23         require 'rubygems'
24         debug "loaded rubygems, looking for rbot-#$version"
25         if $version =~ /(.*)-svn\Z/
26           version = $1
27         else
28           version = $version
29         end
30         gemname, gem = Gem.source_index.find{|name, spec| spec.name == 'rbot' && spec.version.version == version}
31         debug "got gem #{gem}"
32         if gem && path = gem.full_gem_path
33           debug "installed via rubygems to #{path}"
34           @@datadir = "#{path}/data/rbot"
35           @@datadir = "#{path}/lib/rbot/core"
36         else
37           debug "not installed via rubygems"
38         end
39       rescue LoadError,NameError,NoMethodError
40         debug "no rubygems installed"
41       end
42     end
43
44     if @@datadir.nil? or @@coredir.nil?
45       begin
46         require 'rbot/pkgconfig'
47         @@datadir = PKGConfig::DATADIR
48         @@coredir = PKGConfig::COREDIR
49       rescue LoadError
50         error "fatal - no way to determine data or core dir"
51         exit 2
52       end
53     end
54
55     def Config.datadir
56       @@datadir
57     end
58
59     def Config.coredir
60       @@coredir
61     end
62   end
63 end