-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigMgr.py
34 lines (24 loc) · 918 Bytes
/
ConfigMgr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import ConfigParser
class BotConfig(object):
"""Read IrcBot configuration and answer queries for config keys.
"""
def __init__(self, file, section):
self.cfg = ConfigParser.RawConfigParser()
self.cfg.readfp(file)
self.main = section
def get(self, domain, name, optional=False):
try:
res = self.cfg.get(domain, name)
except ConfigParser.NoOptionError:
if not optional:
raise
else:
res = None
return res
def param(self, name):
return self.cfg.get(self.main, name)
def channel_list(self, section):
return [ (item.strip(), self.get(item.strip(), "name")) for item in self.get(self.main, section).split(",") ]
def channel_name(self, section):
"note: inconsistent naming of channel section names. fixme!"
return self.get(section, "name")