summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pinolo/bot.py10
-rw-r--r--pinolo/config.py13
-rw-r--r--pinolo/plugins/markov.py4
-rw-r--r--pinolo/plugins/quotes2.py12
-rw-r--r--sample_config.coil5
5 files changed, 30 insertions, 14 deletions
diff --git a/pinolo/bot.py b/pinolo/bot.py
index 6eb31ae..7690b3b 100644
--- a/pinolo/bot.py
+++ b/pinolo/bot.py
@@ -24,6 +24,7 @@ import pinolo.plugins
from pinolo.signals import SignalDispatcher
from pinolo.irc import IRCConnection, COMMAND_ALIASES
from pinolo.database import init_db
+from pinolo.config import empty_config
log = logging.getLogger()
@@ -278,12 +279,17 @@ class Bot(SignalDispatcher):
def activate_plugins(self):
"""Call the activate method on all loaded plugins"""
- for plugin_name, plugin_class in pinolo.plugins.registry:
+ def basename(s):
+ return s.split(".")[-1]
+
+ for _, plugin_class in pinolo.plugins.registry:
+ plugin_name = basename(plugin_class.__module__)
log.info("Activating plugin %s" % plugin_name)
if plugin_name in self.config["plugins"]:
plugin_config = self.config["plugins"][plugin_name]
else:
- plugin_config = {}
+ plugin_config = empty_config(self.config, plugin_name)
+
p_obj = plugin_class(self, plugin_config)
p_obj.activate()
self.plugins.append(p_obj)
diff --git a/pinolo/config.py b/pinolo/config.py
index fc2f316..6801a2d 100644
--- a/pinolo/config.py
+++ b/pinolo/config.py
@@ -25,8 +25,15 @@ def read_config_file(filename):
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"]))
+
+ to_expand = ("@root.datadir", "@root.plugins.quotes2.db_path",
+ "@root.plugins.markov.db_file")
+ for name in to_expand:
+ path = config.get(name)
+ if path is not None and path.startswith("~"):
+ config.set(name, os.path.expanduser(path))
return config
+
+def empty_config(root, name):
+ return coil.struct.Struct(container=root["plugins"], name=name)
diff --git a/pinolo/plugins/markov.py b/pinolo/plugins/markov.py
index 07871b2..7bf3dd9 100644
--- a/pinolo/plugins/markov.py
+++ b/pinolo/plugins/markov.py
@@ -165,9 +165,7 @@ class MarkovBrain(object):
class MarkovPlugin(Plugin):
def activate(self):
- self.db_file = os.path.join(self.config.get("@root.datadir"),
- "markov.pickle")
- self.markov = MarkovBrain(self.db_file)
+ self.markov = MarkovBrain(self.config["db_file"])
self._counter = 0
self.markov.load()
diff --git a/pinolo/plugins/quotes2.py b/pinolo/plugins/quotes2.py
index 1f10734..80ba25d 100644
--- a/pinolo/plugins/quotes2.py
+++ b/pinolo/plugins/quotes2.py
@@ -62,27 +62,27 @@ class QuotesPlugin(Plugin):
def __init__(self, bot, config, enabled=True):
super(QuotesPlugin, self).__init__(bot, config, enabled)
- self.db_path = os.path.join(self.config.get("@root.datadir"),
- "whoosh")
self.to_be_indexed = False
self.init_whoosh()
def init_whoosh(self):
- if os.path.exists(self.db_path):
- self.ix = index.open_dir(self.db_path)
+ log.info("Opening Whoosh database %s" % self.config["db_path"])
+ if os.path.exists(self.config["db_path"]):
+ self.ix = index.open_dir(self.config["db_path"])
else:
schema = Schema(author=TEXT(),
quote=TEXT(analyzer=my_analyzer),
creation_date=DATETIME(),
id=NUMERIC(stored=True))
- os.mkdir(self.db_path)
- self.ix = index.create_in(self.db_path, schema)
+ os.mkdir(self.config["db_path"])
+ self.ix = index.create_in(self.config["db_path"], schema)
self.to_be_indexed = True
def activate(self):
if not self.to_be_indexed:
return
+ log.info("Indexing the quotes database for the first time")
session = Session()
writer = self.ix.writer()
for quote in Session.query(Quote).all():
diff --git a/sample_config.coil b/sample_config.coil
index a7daedb..dc46a27 100644
--- a/sample_config.coil
+++ b/sample_config.coil
@@ -27,5 +27,10 @@ plugins: {
markov: {
verbosity: 95
save_every: 50
+ db_file: "${@root.datadir}/markov.pickle"
+ }
+
+ quotes2: {
+ db_path: "${@root.datadir}/whoosh"
}
} \ No newline at end of file