attempt to use plc sshell before xmlrpc
authorTony Mack <tmack@cs.princeton.edu>
Fri, 9 Jul 2010 20:18:44 +0000 (20:18 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 9 Jul 2010 20:18:44 +0000 (20:18 +0000)
sfa/plc/api.py

index c0c0d13..aac86eb 100644 (file)
@@ -58,11 +58,8 @@ except:
         def __repr__(self):
             return 'defaultdict(%s, %s)' % (self.default_factory,
                                             dict.__repr__(self))
-
-
 ## end of http://code.activestate.com/recipes/523034/ }}}
 
-
 def list_to_dict(recs, key):
     """
     convert a list of dictionaries into a dictionary keyed on the 
@@ -85,7 +82,6 @@ class SfaAPI(BaseAPI):
                          cert_file=cert_file, cache=cache)
  
         self.encoding = encoding
-
         from sfa.util.table import SfaTable
         self.SfaTable = SfaTable
         # Better just be documenting the API
@@ -115,12 +111,16 @@ class SfaAPI(BaseAPI):
         self.plauth = {'Username': self.config.SFA_PLC_USER,
                        'AuthMethod': 'password',
                        'AuthString': self.config.SFA_PLC_PASSWORD}
-
-
-        self.plshell_type = 'xmlrpc' 
-        # connect via xmlrpc
-        url = self.config.SFA_PLC_URL
-        shell = xmlrpclib.Server(url, verbose = 0, allow_none = True)
+        try:
+            sys.path.append(os.path.dirname(os.path.realpath("/usr/bin/plcsh")))
+            self.plshell_type = 'direct'
+            import PLC.Shell
+            shell = PLC.Shell.Shell(globals = globals())
+        except:
+            self.plshell_type = 'xmlrpc' 
+            url = self.config.SFA_PLC_URL
+            shell = xmlrpclib.Server(url, verbose = 0, allow_none = True)
+        
         return shell
 
     def getCredential(self):