2 import ConfigParser, StringIO
4 def read_config(rootDir = None, defaults = None, nick="octofuss"):
6 Read octofuss configuration, returning a ConfigParser object
9 rootDir = os.environ.get(nick.upper() + "_CONFDIR", "/etc/" + nick)
12 if os.path.exists(path):
15 # Start with the main config file
16 trytouse(os.path.join(rootDir, nick + ".conf"))
18 # Add snippets found in rc.d style directory
19 subdir = os.path.join(rootDir, nick + ".conf.d")
20 if os.path.isdir(subdir):
21 for file in sorted(os.listdir(subdir)):
22 if file.startswith('#'): continue
23 if file.startswith('.'): continue
24 if file.endswith('~'): continue
25 if file.endswith('.bak'): continue
26 trytouse(os.path.join(subdir, file))
28 config = ConfigParser.ConfigParser()
30 infile = StringIO.StringIO(defaults)
31 config.readfp(infile, "defaults")