Run just before rawdog saves the state file and exits.
+### config_option(config, name, value)
+
+Called when rawdog encounters a config file option that it doesn't
+recognise with the given name and value. The rawdoglib.rawdog.parse_*
+functions will probably be useful when dealing with config options. You
+can raise ValueError to have rawdog print an appropriate error message.
+You should return False from this hook if name is an option you
+recognise.
+
+Note that using config.log in this hook will probably not do what you
+want, because the verbose flag may not yet have been turned on.
+
# rawdog can be extended using plugin modules written in Python. This
# option specifies the directories to search for plugins to load. If a
-# directory does not exist or cannot be read, it will be ignored.
+# directory does not exist or cannot be read, it will be ignored. This
+# option must appear before any options that are implemented by plugins.
plugindirs plugins
# The maximum number of articles to show on the generated page.
import os, os.path, imp
-def load_plugins(config):
- count = 0
- for dir in config["plugindirs"]:
- try:
- files = os.listdir(dir)
- except OSError:
- # Ignore directories that can't be read.
- files = []
+plugin_count = 0
- for file in files:
- if file == "" or file[0] == ".":
- continue
+def load_plugins(dir, config):
+ global plugin_count
- desc = None
- for d in imp.get_suffixes():
- if file.endswith(d[0]):
- desc = d
- if desc is None:
- continue
+ try:
+ files = os.listdir(dir)
+ except OSError:
+ # Ignore directories that can't be read.
+ return
- fn = os.path.join(dir, file)
- config.log("Loading plugin ", fn)
- f = open(fn, "r")
- mod = imp.load_module("plugin%d" % (count,), f, fn, desc)
- count += 1
- f.close()
+ for file in files:
+ if file == "" or file[0] == ".":
+ continue
+
+ desc = None
+ for d in imp.get_suffixes():
+ if file.endswith(d[0]) and d[2] == imp.PY_SOURCE:
+ desc = d
+ if desc is None:
+ continue
+
+ fn = os.path.join(dir, file)
+ config.log("Loading plugin ", fn)
+ f = open(fn, "r")
+ mod = imp.load_module("plugin%d" % (plugin_count,), f, fn, desc)
+ plugin_count += 1
+ f.close()
attached = {}
"feedslist" : [],
"feeddefaults" : {},
"defines" : {},
- "plugindirs" : [],
"outputfile" : "output.html",
"maxarticles" : 200,
"maxage" : 0,
raise ConfigError("Bad line in config: " + line)
self["defines"][l[0]] = l[1]
elif l[0] == "plugindirs":
- self["plugindirs"] = parse_list(l[1])
+ for dir in parse_list(l[1]):
+ plugins.load_plugins(dir, self)
elif l[0] == "outputfile":
self["outputfile"] = l[1]
elif l[0] == "maxarticles":
self["changeconfig"] = parse_bool(l[1])
elif l[0] == "include":
self.load(l[1], False)
- else:
+ elif not plugins.call_hook("config_option", self, l[0], l[1]):
raise ConfigError("Unknown config command: " + l[0])
def log(self, *args):
rawdog.sync_from_config(config)
- plugins.load_plugins(config)
plugins.call_hook("startup", rawdog, config)
stats = Stats()