[Bio] / FigKernelPackages / FIG.py Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIG.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8, Wed Apr 28 21:59:32 2004 UTC revision 1.9, Tue May 4 16:27:45 2004 UTC
# Line 1  Line 1 
1  import urlparse  import urlparse
2  import socket  import socket
3  import os  import os
4    import popen2
5  import sys  import sys
6  import re  import re
7    import xmlrpclib
8    
9  import FIG_Config  import FIG_Config
10    
11  import Clearinghouse  import Clearinghouse
# Line 282  Line 285 
285      id = id.strip()      id = id.strip()
286      return id      return id
287    
288    #
289    # Define a FIG class; this is analagous to the FIG class used in FIG.pm
290    #
291    # It also lets us cache stuff, and use __call__ to map calls to
292    # an XMLRPC server for the perl stuff we don't implement locally.
293    #
294    
295    class FIG:
296    
297        def __init__(self):
298            self.xmlrpc_proxy = None
299            self.xmlrpc_proc = None
300    
301        def __repr__(self):
302            return "FIG instance %s" % ( self)
303    
304        def __str__(self):
305            return "FIG instance %s" % (id(self))
306    
307        def __getattr__(self, name):
308            g = globals()
309            if g.has_key(name) and callable(g[name]):
310                return g[name]
311    
312            if name.startswith("_"):
313                return None
314    
315            #
316            # Not accessible in globals. Return an XMLRPC calling proxy.
317            #
318    
319            return XMLRPCCaller(self, name)
320    
321        def foo(self):
322            print "FOO"
323    
324    
325        def call_xmlrpc(self, name, args):
326    
327            try:
328                if self.xmlrpc_proxy is None:
329                    self.start_xmlrpc_server()
330    
331            except Exception, e:
332                print "Got exception ... ", e
333                return
334    
335            proc = getattr(self.xmlrpc_proxy, name)
336            retval = apply(proc, args)
337            return retval
338    
339        def start_xmlrpc_server(self):
340            server_path = os.path.join(FIG_Config.bin, "fig_xmlrpc2")
341    
342            if not os.access(server_path, os.X_OK):
343                raise Exception, "XMLRPC server path %s not found" % (server_path)
344    
345    
346            proc = self.xmlrpc_proc = popen2.Popen3(server_path, 0)
347    
348            print "Server started ", proc.pid
349    
350            url = proc.fromchild.readline()
351            url = url.strip()
352            print "Read url ", url
353    
354            proc.fromchild.close()
355    
356            self.xmlrpc_proxy = xmlrpclib.ServerProxy(url)
357    
358    class XMLRPCCaller:
359        def __init__(self, fig, name):
360            self.fig = fig
361            self.name = name
362    
363        def __call__(self, *args):
364            return self.fig.call_xmlrpc(self.name, args)
365    
366  if __name__ == "__main__":  if __name__ == "__main__":
367    
368      print get_local_hostname()      print get_local_hostname()

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3