summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-30 18:06:04 (GMT)
committer sand <daniel@spatof.org>2013-05-30 18:11:19 (GMT)
commitc15e3515750254d83af00ab157b597abc3863f5d (patch)
treeb5dfdb95c6f79d3479c5440ba93c4a5ff3b2f942
parent76eeae8fe016e48e937a19b4919e7e3ba8c0c1e4 (diff)
nuovo formato configurazione
-rw-r--r--pinolo/config.py60
-rw-r--r--pinolo/database.py6
-rw-r--r--pinolo/irc.py9
-rw-r--r--setup.py2
4 files changed, 29 insertions, 48 deletions
diff --git a/pinolo/config.py b/pinolo/config.py
index 7817818..fc2f316 100644
--- a/pinolo/config.py
+++ b/pinolo/config.py
@@ -8,49 +8,25 @@
:copyright: (c) 2013 Daniel Kertesz
:license: BSD, see LICENSE for more details.
"""
-import re
-import codecs
-from ConfigParser import SafeConfigParser
-
-
-r_comma = re.compile(r'\s*,\s+')
+import sys
+import os
+import coil
def read_config_file(filename):
- cfp = SafeConfigParser()
- with codecs.open(filename, 'r', 'utf-8') as fd:
- cfp.readfp(fd, filename)
-
- config = dict(cfp.items("general"))
- config['servers'] = {}
-
- for opt in ('nicknames', 'disabled_plugins'):
- if opt in config:
- config[opt] = r_comma.split(config[opt])
-
- for section in cfp.sections():
- if not section.startswith("server:"):
- continue
-
- server_name = section.split(':')[1]
- server_config = dict(cfp.items(section))
-
- for opt in ('port',):
- server_config[opt] = int(server_config[opt])
-
- for opt in ('channels',):
- server_config[opt] = r_comma.split(server_config[opt])
-
- for opt in ('ssl', 'ssl_verify'):
- if not opt in server_config:
- server_config[opt] = False
- continue
-
- if server_config[opt] in ("true", "1", "True"):
- server_config[opt] = True
- else:
- server_config[opt] = False
-
- config['servers'][server_name] = server_config
-
+ """Read a configuration file in coil format and returns a Struct
+ object (dict-like)"""
+
+ def fatal(msg):
+ sys.stderr.write("%s\n" % msg)
+ sys.exit(1)
+
+ config = coil.parse_file(filename, encoding="utf-8")
+
+ if config.get("@root.datadir") is None:
+ fatal("Config error: empty 'datadir' parameter")
+ else:
+ if config["datadir"].startswith("~"):
+ config.set("datadir", os.path.expanduser(config["datadir"]))
+
return config
diff --git a/pinolo/database.py b/pinolo/database.py
index f0a92a9..fbaa33b 100644
--- a/pinolo/database.py
+++ b/pinolo/database.py
@@ -1,13 +1,19 @@
+# -*- coding: utf-8 -*-
+import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
+
+log = logging.getLogger(__name__)
+
Session = scoped_session(sessionmaker())
Base = declarative_base()
Base.query = Session.query_property()
def init_db(uri, echo=False):
+ log.info("Initializing database at %s" % uri)
engine = create_engine(uri, echo=echo)
Session.configure(bind=engine)
Base.metadata.create_all(engine)
diff --git a/pinolo/irc.py b/pinolo/irc.py
index dc8c677..47847c1 100644
--- a/pinolo/irc.py
+++ b/pinolo/irc.py
@@ -146,7 +146,7 @@ class IRCConnection(object):
self.connected = False
self.active = True
# nickname handling
- self.nicknames = self.bot.config['nicknames']
+ self.nicknames = self.config['nicknames']
self.nicknames_id = 0
self.current_nickname = None
# la queue per i thread
@@ -185,7 +185,7 @@ class IRCConnection(object):
self.socket.setblocking(False)
try:
- self.socket.connect((self.config['hostname'], self.config['port']))
+ self.socket.connect((self.config['host'], self.config['port']))
except socket.error, e:
if isinstance(e, str):
raise
@@ -194,7 +194,7 @@ class IRCConnection(object):
else:
raise
except socket.gaierror as err:
- print "Unknown host: %s (%s)" % (self.config['hostname'], str(err))
+ print "Unknown host: %s (%s)" % (self.config['host'], str(err))
raise
self.nick()
@@ -339,8 +339,7 @@ class IRCConnection(object):
Note: user mode '8' means "invisible"
"""
self.send(u"USER {0} 8 * :{1}".format(
- self.bot.config['ident'],
- self.bot.config['realname']))
+ self.config["ident"], self.config["realname"]))
def join(self, channel, key=None):
"""Join a single channel"""
diff --git a/setup.py b/setup.py
index ac03696..c58fe8d 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup(
name="pinolo",
- version="0.10.1",
+ version="0.10.2",
description="Pinolo, the naughty chat bot",
author="sand",
author_email="daniel@spatof.org",