use __getattr__ to make object any symbol callable
This commit is contained in:
parent
24b16768d3
commit
51b92a1ebf
1 changed files with 9 additions and 15 deletions
24
doku.py
24
doku.py
|
@ -14,22 +14,16 @@ class DokuWiki:
|
|||
def __init__(self):
|
||||
self.callcache = {}
|
||||
|
||||
def __call(self, call, id):
|
||||
key = "%s-%s" % (call, id)
|
||||
def __getattr__(self, callback):
|
||||
self.callback = callback
|
||||
return self.__dokucall
|
||||
|
||||
def __dokucall(self, *args):
|
||||
args = list(args)
|
||||
key = "%s:%s" % (self.callback, ",".join(args))
|
||||
if not self.callcache.has_key(key):
|
||||
cmd = ['./doku.php', call, id]
|
||||
cmd = ['./doku.php', self.callback ] + 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]
|
||||
|
||||
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)
|
||||
|
||||
def cleanID(self, id):
|
||||
return self.__call('cleanID', id)
|
||||
|
|
Loading…
Reference in a new issue