moin2doku/doku.py

33 lines
854 B
Python
Raw Normal View History

#!/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.
#
# 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 12:57:33 +01:00
def __call(self, method, *args):
args = list(args)
2011-02-10 12:57:33 +01:00
key = "%s:%s" % (method, ",".join(args))
if not self.callcache.has_key(key):
2011-02-10 12:57:33 +01:00
cmd = ['./doku.php', method ] + args
res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate()
print "%s->%s" % (cmd, res)
self.callcache[key] = res[0]
return self.callcache[key]