split engine/ into manifold/ (backend oriented) and unfold/ (the UI)
[myslice.git] / manifold / manifoldapi.py
1 # Manifold API Python interface
2 import xmlrpclib
3
4 from myslice.config import Config
5
6 debug=True
7
8 class ManifoldAPI:
9
10   def __init__(self, auth=None, cainfo=None):
11
12     config = Config()
13     self.auth = auth
14     self.cainfo = cainfo
15     self.errors = []
16     self.trace = []
17     self.calls = {}
18     self.multicall = False
19     self.url = config.manifold_url
20     self.proxy = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
21
22   def __getattr__(self, methodName):
23       def func(*args, **kwds):
24         result=getattr(self.proxy, methodName)(self.auth, *args, **kwds)
25         ### debug
26         if debug:
27           print '===> backend call',methodName, self.auth, self.url,'->',
28           if not result:                        print "no/empty result"
29           elif isinstance (result,str):         print "result is '%s'"%result
30           elif isinstance (result,list):        print "result is a %d-elts list"%len(result)
31           else:                                 print "dont know how to display result"
32         ###
33         return result
34       return func
35
36   # 4amine : xxx
37   def send_manifold_query (self, manifold_query):
38     (action,method)= (manifold_query.action,manifold_query.method)
39     if action=='get':
40       return self.proxy.Get(self.auth, method, manifold_query.filters, {}, manifold_query.fields)
41     # xxx...
42     elif action=='others':
43       return None
44
45