[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.12, Fri Oct 21 14:50:26 2005 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
12    
13    class NoSubsystemException(Exception):
14        pass
15    
16  def get_clearinghouse(url = None):  def get_clearinghouse(url = None):
17      return Clearinghouse.Clearinghouse(url)      return Clearinghouse.Clearinghouse(url)
18    
19    def get_ss_hierarchy(url = None):
20        return Clearinghouse.SSHierarchy(url)
21    
22    #
23    # Subsystem helper code.
24    #
25    
26    def get_subsystem(name):
27        try:
28            sub = Subsystem(name)
29        except NoSubsystemException:
30            sub = None
31    
32        return sub
33    
34    
35  def get_local_hostname():  def get_local_hostname():
36      #      #
37      # See if there is a FIGdisk/config/hostname file. If there      # See if there is a FIGdisk/config/hostname file. If there
# Line 231  Line 253 
253    
254      return ip      return ip
255    
256    def top_link():
257    
258        #
259        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
260        # just /p2p).
261        #
262    
263        sname = os.getenv("SCRIPT_NAME")
264    
265        if sname is not None:
266            parts = os.getenv("SCRIPT_NAME").split('/');
267    
268            if len(parts) > 2 and parts[-2] == 'FIG':
269                top = '.'
270            elif len(parts) > 3 and parts[-3] == 'FIG':
271                top = '..'
272            else:
273                top = FIG_Config.cgi_base
274        else:
275            top = FIG_Config.cgi_base
276    
277    
278    
279        return top
280    
281  def cgi_url():  def cgi_url():
282      return plug_url(FIG_Config.cgi_url)      return top_link()
283        # return plug_url(FIG_Config.cgi_url)
284    
285  def temp_url():  def temp_url():
286      return plug_url(FIG_Config.temp_url)      return plug_url(FIG_Config.temp_url)
# Line 282  Line 330 
330      id = id.strip()      id = id.strip()
331      return id      return id
332    
333    #
334    # Define a FIG class; this is analagous to the FIG class used in FIG.pm
335    #
336    # It also lets us cache stuff, and use __call__ to map calls to
337    # an XMLRPC server for the perl stuff we don't implement locally.
338    #
339    
340    class FIG:
341    
342        def __init__(self):
343            self.xmlrpc_proxy = None
344            self.xmlrpc_proc = None
345    
346        def __repr__(self):
347            return "FIG instance %s" % ( self)
348    
349        def __str__(self):
350            return "FIG instance %s" % (id(self))
351    
352        def __getattr__(self, name):
353            g = globals()
354            if g.has_key(name) and callable(g[name]):
355                return g[name]
356    
357            if name.startswith("_"):
358                return None
359    
360            #
361            # Not accessible in globals. Return an XMLRPC calling proxy.
362            #
363    
364            return XMLRPCCaller(self, name)
365    
366        def foo(self):
367            print "FOO"
368    
369    
370        def call_xmlrpc(self, name, args):
371    
372            try:
373                if self.xmlrpc_proxy is None:
374                    self.start_xmlrpc_server()
375    
376            except Exception, e:
377                print "Got exception ... ", e
378                return
379    
380            proc = getattr(self.xmlrpc_proxy, name)
381            retval = apply(proc, args)
382            return retval
383    
384        def start_xmlrpc_server(self):
385            server_path = os.path.join(FIG_Config.bin, "fig_xmlrpc_server")
386    
387            if not os.access(server_path, os.X_OK):
388                raise Exception, "XMLRPC server path %s not found" % (server_path)
389    
390    
391            proc = self.xmlrpc_proc = popen2.Popen3(server_path, 0)
392    
393            print "Server started ", proc.pid
394    
395            url = proc.fromchild.readline()
396            url = url.strip()
397            print "Read url ", url
398    
399            proc.fromchild.close()
400    
401            self.xmlrpc_proxy = xmlrpclib.ServerProxy(url)
402    
403    class XMLRPCCaller:
404        def __init__(self, fig, name):
405            self.fig = fig
406            self.name = name
407    
408        def __call__(self, *args):
409            return self.fig.call_xmlrpc(self.name, args)
410    
411    class Subsystem:
412        def __init__(self, name):
413            self.dir = os.path.join(FIG_Config.data, "Subsystems", name.replace(" ","_"))
414    
415            if not os.path.isdir(self.dir):
416                raise NoSubsystemException("Subsystem %s not found" % (name))
417    
418        def get_version(self):
419            try:
420                fh = open(os.path.join(self.dir, "VERSION"))
421                version = fh.readline().strip()
422                try:
423                    local_version = int(version)
424                except TypeError:
425                    local_version = -1
426                fh.close()
427            except:
428                local_version = -1
429    
430            return local_version;
431    
432        def get_curator(self):
433            curator = None
434            try:
435                fh = open(os.path.join(self.dir, "curation.log"))
436                l = fh.readline().strip()
437                fh.close()
438                m = re.match(r"^\d+\t(\S+)\s+started", l)
439                if m:
440                    curator = m.group(1)
441            except:
442                pass
443    
444            return curator
445    
446  if __name__ == "__main__":  if __name__ == "__main__":
447    
448      print get_local_hostname()      print get_local_hostname()

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3