aboutsummaryrefslogtreecommitdiffstats
path: root/IRC
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2013-12-18 16:32:41 +0100
committertv <tv@nomic.retiolum>2013-12-18 16:32:41 +0100
commitaa7cd8834b21a064e4fe0440b956f6c174949ed2 (patch)
tree4e9a17a838dc3c6cec28954ad69a9b84057da33c /IRC
parent8a9c41f399dd874b246818bb81f4c9edbf9a9549 (diff)
Reaktor: s/(config).json/\1.py/
Diffstat (limited to 'IRC')
-rwxr-xr-xIRC/asybot.py26
-rw-r--r--IRC/getconf.py24
2 files changed, 30 insertions, 20 deletions
diff --git a/IRC/asybot.py b/IRC/asybot.py
index ceebe84..6d19fd0 100755
--- a/IRC/asybot.py
+++ b/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/IRC/getconf.py b/IRC/getconf.py
index 5fdd1cd..d6e9f42 100644
--- a/IRC/getconf.py
+++ b/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)
+