21 |
__date__ = "Wed Nov 11 2002" |
__date__ = "Wed Nov 11 2002" |
22 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
23 |
|
|
24 |
import ConfigParser, sys, os |
import sys, os |
25 |
|
|
26 |
class Config(ConfigParser.ConfigParser): |
class Config: |
27 |
"""An advanced ConfigParser module with our defaults auto-loaded |
"""An advanced ConfigParser module with our defaults auto-loaded |
28 |
""" |
""" |
29 |
|
|
30 |
# Think about these paths a little bit more, namely the order. |
# Think about these paths a little bit more, namely the order. |
31 |
# All are read in given order. |
# All are read in given order. |
32 |
config_file_paths = [ |
config_file_paths = [ |
33 |
'/etc/circus/circus.cfg', |
'/etc/circus/config.py', |
34 |
os.path.expanduser('~/.circus/circus.cfg') |
os.path.expanduser('~/.circus/config.py') |
35 |
] |
] |
36 |
|
|
|
config_defaults = { |
|
|
"main" : { |
|
|
"circus_home" : '/usr/local/share/circus', |
|
|
"module_path" : '%(circus_home)s/modules', |
|
|
}, |
|
|
"modules" : { |
|
|
"autoload" : "" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
"""Setup some our default values. ConfigParser's standard method |
|
|
of setting defaults is ignored since it is inadequate for our needs""" |
|
|
|
|
|
ConfigParser.ConfigParser.__init__(self) |
|
|
|
|
|
for section in self.config_defaults: |
|
|
self.add_section(section) |
|
|
for key, value in self.config_defaults[section].items(): |
|
|
self.set(section, key, value) |
|
37 |
|
|
|
self.read(self.config_file_paths) |
|
|
|
|
38 |
def update_module_path(self, path = None): |
def update_module_path(self, path = None): |
39 |
"""Add <path> to python's module path list after some error |
"""Add <path> to python's module path list after some error |
40 |
checking. If <path> is not given, then add the path from |
checking. If <path> is not given, then add the path from |
42 |
""" |
""" |
43 |
|
|
44 |
if path == None: |
if path == None: |
45 |
addpath = self.get('main', 'module_path') |
addpath = self.module_path |
46 |
|
|
47 |
# pass over non-existant paths |
# pass over non-existant paths |
48 |
if not os.path.exists(addpath): |
if not os.path.exists(addpath): |
59 |
|
|
60 |
sys.path.append(addpath) |
sys.path.append(addpath) |
61 |
|
|
|
|
|
|
def dump_config(self): |
|
|
for section in self.sections(): |
|
|
sys.stderr.write(section + "\n") |
|
|
for option in self.options(section): |
|
|
sys.stderr.write("-- " + option + "=" + |
|
|
self.get(section, option) + "\n") |
|
|
|
|