trashed remoteshell and use plshell instead
[sfa.git] / sfa / plc / plshell.py
index 863472f..ef2abb0 100644 (file)
@@ -1,5 +1,7 @@
 import xmlrpclib
 
+from sfa.util.sfalogging import logger
+
 class PlShell:
     """
     A simple xmlrpc shell to a myplc instance
@@ -25,15 +27,32 @@ class PlShell:
                     }
 
     def __init__ ( self, config ) :
-        self.plauth = {'Username': config.SFA_PLC_USER,
-                       'AuthMethod': 'password',
-                       'AuthString': config.SFA_PLC_PASSWORD}
-        
         self.url = config.SFA_PLC_URL
-        self.plauth = {'Username': 'root@test.onelab.eu',
-                       'AuthMethod': 'password',
-                       'AuthString': 'test++'}
-        self.proxy_server = xmlrpclib.Server(self.url, verbose = 0, allow_none = True)
+        # xxx attempt to use the 'capability' auth mechanism for higher performance
+        # when the PLC db is local
+        # xxx todo
+        is_local = False
+        if is_local:
+            try:
+                import PLC.Shell
+                plc_direct_access=True
+            except:
+                plc_direct_access=False
+        if is_local and plc_direct_access:
+            logger.info('plshell - capability access')
+            self.plauth = { 'AuthMethod': 'capability',
+                            'UserName':   config.SFA_PLC_USER,
+                            'AuthString': config.SFA_PLC_PASSWORD,
+                            }
+            self.proxy = PLC.Shell.Shell ()
+
+        else:
+            logger.info('plshell - xmlrpc access')
+            self.plauth = { 'AuthMethod': 'password',
+                            'Username':   config.SFA_PLC_USER,
+                            'AuthString': config.SFA_PLC_PASSWORD,
+                            }
+            self.proxy = xmlrpclib.Server(self.url, verbose = 0, allow_none = True)
 
     def __getattr__(self, name):
         def func(*args, **kwds):
@@ -42,5 +61,7 @@ class PlShell:
             if name in PlShell.alias_calls: actual_name=PlShell.alias_calls[name]
             if not actual_name:
                 raise Exception, "Illegal method call %s for PL driver"%(name)
-            return getattr(self.proxy_server, actual_name)(self.plauth, *args, **kwds)
+            result=getattr(self.proxy, actual_name)(self.plauth, *args, **kwds)
+            logger.info('%s (%s) returned ... %s'%(name,actual_name,result))
+            return result
         return func