Imported from archive.
[mudpy.git] / lib / muff / muffconf.py
1 """Configuration objects for the MUFF Engine"""
2
3 # Copyright (c) 2005 mudpy, Jeremy Stanley <fungi@yuggoth.org>, all rights reserved.
4 # Licensed per terms in the LICENSE file distributed with this software.
5
6 # muff configuration files use the ini format supported by ConfigParser
7 import ConfigParser
8
9 # need os for testing whether the config file exists and is readable
10 import os
11
12 # hack to load all modules in teh muff package
13 import muff
14 for module in muff.__all__:
15         exec("import " + module)
16
17 # list of places to look for the config
18 config_dirs = [".", "./etc", "/usr/local/muff", "/usr/local/muff/etc", "/etc/muff", "/etc" ]
19
20 # name of the config file
21 config_name = "muff.conf"
22
23 # find the config file
24 for each_dir in config_dirs:
25         config_file = each_dir + "/" + config_name
26         if os.access(config_file, os.R_OK): break
27
28 # read the config
29 config_data = ConfigParser.SafeConfigParser()
30 config_data.read(config_file)
31
32 def get(section, option):
33         """Convenience function to get configuration data."""
34         return config_data.get(section, option)
35
36 def getfloat(section, option):
37         "Convenience function to get floating-point configuration data."""
38         return config_data.getfloat(section, option)
39
40 def getint(section, option):
41         """Convenience function to get integer configuration data."""
42         return config_data.getint(section, option)
43
44 def set(section, option, value):
45         """Convenienve function to set miscellaneous configuration data."""
46         return muffmisc.setlong(config_data, section, option, value)
47