commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue-common/src/rpc GComm.py


From: Jan Ischebeck
Subject: gnue-common/src/rpc GComm.py
Date: Mon, 22 Sep 2003 18:40:14 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         
Changes by:     Jan Ischebeck <address@hidden>  03/09/22 18:40:13

Modified files:
        src/rpc        : GComm.py 

Log message:
        RPC Directory Structure Change: update GComm.py driver import

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/rpc/GComm.py.diff?tr1=1.24&tr2=1.25&r1=text&r2=text

Patches:
Index: gnue-common/src/rpc/GComm.py
diff -c gnue-common/src/rpc/GComm.py:1.24 gnue-common/src/rpc/GComm.py:1.25
*** gnue-common/src/rpc/GComm.py:1.24   Thu Apr  3 14:38:18 2003
--- gnue-common/src/rpc/GComm.py        Mon Sep 22 18:40:13 2003
***************
*** 27,52 ****
  # NOTES:
  #
  
  from gnue.common.apps import GDebug
  from gnue.common.utils.FileUtils import dyn_import, openResource
  
  
  ##############################################################################
  #
  # Attach to a client driver
  #
  def attach(interface, params):
    try:
!     driver = dyn_import('gnue.common.rpc.drivers.%s' % interface)
    except ImportError, mesg:
      GDebug.printMesg(1, \
         "Unable to import GComm Adapter '%s': \n%s" % (interface,mesg))
      raise InvalidAdapter, mesg
  
-   if not (hasattr(driver,'CLIENT') and driver.CLIENT):
-     tmsg = _("GComm adapter '%s' does not support clients") % interface
-     raise NoClientAdapter, tmsg
- 
    adapter = driver.ClientAdapter(params)
  
    return adapter
--- 27,128 ----
  # NOTES:
  #
  
+ import string
  from gnue.common.apps import GDebug
  from gnue.common.utils.FileUtils import dyn_import, openResource
  
  
+ #####################################################################
+ #
+ # Helper functions to load appropriate driver
+ # 
+ # TODO: add to FileUtils as they are almost the same function as in 
GConnection.py
+ 
+ #
+ # Load the correct driver from gnue/common/datasources/drivers/*/
+ #
+ 
+ from gnue.common.rpc.drivers import DRIVERS as ALLDRIVERS
+ 
+ ###################################################
+ # 
+ #  load driver from path which passes test 'test'
+ #  f.e. _get_driver('xmlrpc','gnue.common.rpc.drivers',lambda x: return 
x.CLIENT==1))
+ 
+ def _get_driver(drivername, baselist, path, test=lambda x:1):
+ 
+   d = drivername.split('.')
+   basedriver = d[0]
+   if len(d) > 1:
+     extradriver = "." + string.join(d[1:],'.')
+   else:
+     extradriver = ""
+ 
+   driver = None
+ 
+   basemodule = _find_base_driver(basedriver, baselist, [path])
+   GDebug.printMesg(1,'Using %s as base driver for %s' %  (basemodule, driver))
+ 
+   if basemodule:
+     driver = _import_driver(basemodule + extradriver, test)
+ 
+   if not driver:
+     tmsg = _("No rpc driver found for provider type '%s'") % drivername
+     raise Exception, tmsg
+ 
+   return driver
+ 
+ def _find_base_driver (driver, modules, path=[]):
+   if driver in modules:
+     return string.join(path + [driver],'.')
+   else:
+     for module in modules:
+       try:
+         m = dyn_import (string.join(path + [module],'.')).DRIVERS
+         rs = _find_base_driver(driver, m, path + [module])
+         if rs:
+           return rs
+       except (AttributeError, ImportError), err:
+         pass
+ 
+ 
+ def _import_driver (drivername,test):
+   driver = None
+   try:
+     driver = dyn_import("%s.Driver" % (drivername))
+   except:
+     GDebug.printMesg(1,'%s is not a dbdriver' % ( drivername))
+     try:
+       drivers = dyn_import("%s" % (drivername)).DRIVERS
+       for d in drivers:
+         driver = _import_driver(drivername + "." + d, test )
+         try:
+           if driver:
+             if test(driver):
+               return driver
+         except Exception,msg:
+           print msg
+     except (ImportError, AttributeError):
+       GDebug.printMesg(1,'%s does not contain drivers' % (drivername))
+   return driver
+ 
+ 
+ 
+ 
  ##############################################################################
  #
  # Attach to a client driver
  #
  def attach(interface, params):
    try:
!     driver = _get_driver(interface, ALLDRIVERS, 
'gnue.common.rpc.drivers',lambda x:x.CLIENT==1 )
!     if driver == None:
!       raise ImportError
    except ImportError, mesg:
      GDebug.printMesg(1, \
         "Unable to import GComm Adapter '%s': \n%s" % (interface,mesg))
      raise InvalidAdapter, mesg
  
    adapter = driver.ClientAdapter(params)
  
    return adapter
***************
*** 105,125 ****
      params = drivers[interface]
  
      try:
!       driver = dyn_import('gnue.common.rpc.drivers.%s' % interface)
      except ImportError, mesg:
        GDebug.printMesg(1, \
!          "Unable to import GComm Adapter '%s': \n%s" % (interface,mesg))
        raise InvalidAdapter, mesg
  
-     if not (hasattr(driver,'SERVER') and driver.SERVER):
-       tmsg = _("GComm adapter '%s' does not support servers") % interface
-       raise NoServerAdapter, tmsg
- 
      adapter = driver.ServerAdapter(mapping, bindings, params)
      servers[interface] = adapter
  
    return servers
  
  #
  # To keep everything that a client/server app will need in this
  # file, any convenience functions from the commdrivers directory.
--- 181,201 ----
      params = drivers[interface]
  
      try:
!       driver = _get_driver(interface, ALLDRIVERS, 
'gnue.common.rpc.drivers',lambda x:x.SERVER==1 )
!       if driver == None:
!         raise ImportError
      except ImportError, mesg:
        GDebug.printMesg(1, \
!                        "Unable to import GComm Adapter '%s': \n%s" % 
(interface,mesg))
        raise InvalidAdapter, mesg
  
      adapter = driver.ServerAdapter(mapping, bindings, params)
      servers[interface] = adapter
  
    return servers
  
+ 
+ 
  #
  # To keep everything that a client/server app will need in this
  # file, any convenience functions from the commdrivers directory.
***************
*** 130,136 ****
  #
  # Load an XML-based interface definition
  #
! from gnue.common.rpc.drivers._parser.Parser import loadDefinition
  
  
  
--- 206,212 ----
  #
  # Load an XML-based interface definition
  #
! from gnue.common.rpc.parser.Parser import loadDefinition
  
  
  
***************
*** 227,232 ****
--- 303,309 ----
  #
  # Some conversion functions to allow a client to describe the type of
  # the argument that should be passed instead of autodetection
+ # TODO: should be moved to GTypeCast
  #
  # i.e. Donutplace.send(base64(photo.jpg))
  
***************
*** 266,272 ****
      self._type='number'
      self._value=value
  
! class string:
    def __init__(self,value):
      self._type='string'
      self._value=value
--- 343,349 ----
      self._type='number'
      self._value=value
  
! class string_type:
    def __init__(self,value):
      self._type='string'
      self._value=value




reply via email to

[Prev in Thread] Current Thread [Next in Thread]