2011-02-10 09:29:51 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Setup VIM: ex: noet ts=2 sw=2 :
|
2011-02-10 10:00:19 +01:00
|
|
|
#
|
|
|
|
# Python side Bridge of accessing DokuWiki functions from Python.
|
|
|
|
# See README for details.
|
|
|
|
#
|
2011-02-10 09:29:51 +01:00
|
|
|
# Author: Elan Ruusamäe <glen@pld-linux.org>
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
class DokuWiki:
|
|
|
|
def __init__(self):
|
|
|
|
self.callcache = {}
|
|
|
|
|
2011-02-10 12:57:33 +01:00
|
|
|
def __getattr__(self, method):
|
|
|
|
def wrap(method):
|
|
|
|
def wrapped(*args):
|
|
|
|
return self.__call(method, *args)
|
|
|
|
return wrapped
|
|
|
|
return wrap(method)
|
2011-02-10 11:50:01 +01:00
|
|
|
|
2011-02-10 12:57:33 +01:00
|
|
|
def __call(self, method, *args):
|
2011-02-10 11:50:01 +01:00
|
|
|
args = list(args)
|
2011-02-10 12:57:33 +01:00
|
|
|
key = "%s:%s" % (method, ",".join(args))
|
2011-02-10 09:29:51 +01:00
|
|
|
if not self.callcache.has_key(key):
|
2011-02-10 12:57:33 +01:00
|
|
|
cmd = ['./doku.php', method ] + args
|
2011-02-10 09:29:51 +01:00
|
|
|
res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate()
|
2012-09-18 22:43:59 +02:00
|
|
|
self.callcache[key] = unicode(res[0].decode('utf-8'))
|
|
|
|
print "%s->%s" % (cmd, self.callcache[key])
|
2011-02-10 09:29:51 +01:00
|
|
|
return self.callcache[key]
|