moin2doku/doku.py
2016-01-07 18:29:51 +01:00

34 lines
910 B
Python
Executable file

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