Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 75 lines (64 sloc) 2.27 KB
#!/usr/bin/env python3
__name__ = "rpcbug"
__description__ = 'Dummy plugin highlighting a bug in ikiwiki RPC'
__version__ = '0.1'
__author__ = 'Louis Paternault <spalax@gresille.org>'
__copyright__ = 'Copyright © ' + __author__
__licence__ = 'GPL version 3 or later'
from proxy import IkiWikiProcedureProxy
def preprocess(proxy, *args):
"""Process ikiwiki directive ``[[!rpcbug]]``."""
text = ""
text += "<br/>* Calling `srcfile(foo)`: " + proxy.rpc("srcfile", "foo")
text += "<br/>* Calling `srcfile(README.md)`: " + proxy.rpc("srcfile", "README.md")
return text
def _to_dict(args):
"""Return arguments, as given by Ikiwiki, as a dictionary.
args is a list paired by key, value, so we turn it into a dict
"""
return dict((k, v) for k, v in zip(*[iter(args)]*2))
def getsetup(proxy, *args):
"""Set default setup for this plugin."""
# pylint: disable=unused-argument
return 'plugin', {'safe' : 1, 'rebuild' : 1, 'section' : 'format'}
def checkconfig(proxy, *args):
"""Check plugin configuration."""
# pylint: disable=unused-argument
if proxy.rpc("getvar", "config", "verbose") is None:
LOGGER.setLevel(logging.WARNING)
else:
LOGGER.setLevel(logging.INFO)
def format(proxy, *args):
kwargs = _to_dict(args)
return kwargs['content']
def debug(*args, **kwargs):
"""Print debugging information."""
import inspect
import sys
frame = inspect.getouterframes(inspect.currentframe())[1]
sys.stderr.write("{module}:{line}:{function}:".format(
module=__name__,
line=frame[3],
function=frame[2],
))
if args:
sys.stderr.write(" {args}\n".format(
args=" ".join([str(item) for item in args]),
))
if kwargs:
sys.stderr.write(" {{{kwargs}}}\n".format(
kwargs=", ".join([
"'{key}': '{value}'".format(str(key), str(value))
for (key, value)
in kwargs.items()
])
))
if not (args or kwargs):
sys.stderr.write("\n")
sys.stderr.flush()
# pylint: disable=invalid-name
ikiproxy = IkiWikiProcedureProxy(__name__, debug_fn=None)
ikiproxy.hook('getsetup', getsetup)
ikiproxy.hook('preprocess', preprocess)
ikiproxy.hook('format', format)
ikiproxy.run()