Some initial work on documenting plugins' controls.
[calf.git] / bigbull / client.py
blob5c6410c67298bb0473ebd5e4ec10179689e9774b
1 import os
2 import sys
3 import fakeserv
4 import types
6 class CommandExec:
7 nextId = 1
9 def __init__(self, type, *args):
10 self.cmdId = CommandExec.nextId
11 self.nextId += 1
12 self.type = type
13 self.args = args
14 self.error = None
15 self.okHandlers = []
16 self.errorHandlers = []
18 def onOK(self, handler):
19 self.okHandlers.append(handler)
21 def onError(self, handler):
22 self.errorHandlers.append(handler)
24 def run(self):
25 fakeserv.queue(self)
27 def calledOnOK(self, result):
28 self.result = result
29 #print "OK: %s(%s) -> %s" % (self.type, self.args, self.result)
30 for h in self.okHandlers:
31 if type(h) is types.FunctionType or type(h) is types.MethodType:
32 h(self)
33 else:
34 h.receiveData(self)
36 def calledOnError(self, message):
37 self.error = message
38 print "Error: %s(%s) -> %s" % (self.type, self.args, message)
39 for h in self.errorHandlers:
40 if type(h) is types.FunctionType or type(h) is types.MethodType:
41 h(self)
42 else:
43 h.receiveError(self)