add bridge to call DokuWiki functions from Python

This commit is contained in:
Elan Ruusamäe 2011-02-10 10:29:51 +02:00
parent e2c88692f0
commit 2643fe5d35
2 changed files with 64 additions and 0 deletions

31
doku.py Normal file
View file

@ -0,0 +1,31 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Setup VIM: ex: noet ts=2 sw=2 :
# Bridge for Python code to invoke DokuWiki functions.
#
# Author: Elan Ruusamäe <glen@pld-linux.org>
import sys
import subprocess
class DokuWiki:
def __init__(self):
self.callcache = {}
def __call(self, call, id):
key = "%s-%s" % (call, id)
if not self.callcache.has_key(key):
cmd = ['./doku.php', call, id]
print cmd
res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate()
self.callcache[key] = res[0]
return self.callcache[key]
def wikiFn(self, id):
return self.__call('wikiFn', id)
def mediaFn(self, id):
return self.__call('mediaFn', id)
def getNS(self, id):
return self.__call('getNS', id)