diff options
author | tv <tv@nomic.retiolum> | 2013-12-18 16:32:41 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-12-18 16:32:41 +0100 |
commit | b1df5ae25e8bc336bb50ef5a2deb4dd40ee809ed (patch) | |
tree | afc030b7df0d14684b22edecc8fbbf3af8ccce0e /Reaktor/IRC | |
parent | b0545bab3ab04d6177102c15bebeca2910ebab3a (diff) |
Reaktor: s/(config).json/\1.py/
Diffstat (limited to 'Reaktor/IRC')
-rwxr-xr-x | Reaktor/IRC/asybot.py | 26 | ||||
-rw-r--r-- | Reaktor/IRC/getconf.py | 24 |
2 files changed, 30 insertions, 20 deletions
diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index ceebe844..6d19fd09 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -19,13 +19,13 @@ from re import split, search, match from textwrap import TextWrapper import logging,logging.handlers from getconf import make_getconf -getconf = make_getconf('config.json') +getconf = make_getconf('config.py') log = logging.getLogger('asybot') hdlr = logging.handlers.SysLogHandler(facility=logging.handlers.SysLogHandler.LOG_DAEMON) formatter = logging.Formatter( '%(filename)s: %(levelname)s: %(message)s') hdlr.setFormatter(formatter) log.addHandler(hdlr) -logging.basicConfig(level = logging.DEBUG if getconf('main.debug') else logging.INFO) +logging.basicConfig(level = logging.DEBUG if getconf('debug') else logging.INFO) # s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g -- removes color codes @@ -33,14 +33,14 @@ logging.basicConfig(level = logging.DEBUG if getconf('main.debug') else logging. class asybot(asychat): def __init__(self): asychat.__init__(self) - self.server = getconf('irc.server') - self.port = getconf('irc.port') - self.channels = getconf('irc.channels') - self.realname = getconf('irc.nickname') - self.nickname = getconf('irc.nickname') - self.username = getconf('irc.nickname') - self.hostname = getconf('irc.nickname') - self.ircname = getconf('irc.nickname') + self.server = getconf('irc_server') + self.port = getconf('irc_port') + self.channels = getconf('irc_channels') + self.realname = getconf('irc_nickname') + self.nickname = getconf('irc_nickname') + self.username = getconf('irc_nickname') + self.hostname = getconf('irc_nickname') + self.ircname = getconf('irc_nickname') self.data = '' self.set_terminator('\r\n'.encode(encoding='UTF-8')) self.create_socket(AF_INET, SOCK_STREAM) @@ -52,8 +52,8 @@ class asybot(asychat): # When we don't receive data for alarm_timeout seconds then issue a # PING every hammer_interval seconds until kill_timeout seconds have # passed without a message. Any incoming message will reset alarm. - self.alarm_timeout = getconf('irc.alarm_timeout') - self.hammer_interval = getconf('irc.hammer_interval') + self.alarm_timeout = getconf('irc_alarm_timeout') + self.hammer_interval = getconf('irc_hammer_interval') self.kill_timeout = 360 signal(SIGALRM, lambda signum, frame: self.alarm_handler()) self.reset_alarm() @@ -125,7 +125,7 @@ class asybot(asychat): def ME(text): PRIVMSG(('ACTION ' + text + '').encode(encoding='UTF-8')) - for command in getconf('irc.commands'): + for command in getconf('irc_commands'): y = match(command['pattern'], rest) if y: self.execute_command(command, y, PRIVMSG, ME) diff --git a/Reaktor/IRC/getconf.py b/Reaktor/IRC/getconf.py index 5fdd1cdb..d6e9f425 100644 --- a/Reaktor/IRC/getconf.py +++ b/Reaktor/IRC/getconf.py @@ -2,19 +2,29 @@ #getconf(key) -> value #oder error -import json +import imp +import os + def make_getconf(filename): + + config = load_config(filename) + def getconf(prop): prop_split = prop.split('.') string = '' - file = open(filename) - for line in file.readlines(): - string+=line - parsed = json.loads(string) - tmp = parsed + imp.reload(config) + tmp = config.__dict__ for pr in prop_split: tmp = tmp[pr] - return tmp + return getconf + + +def load_config(filename): + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [ dirname ]) + return imp.load_module(modname, file, pathname, description) + |