loading the ifacepath at load time

David Farning dfarning at gmail.com
Wed Nov 22 13:10:00 PST 2006


Gustavo,
     Nice work with all the callbacks.  It makes extending the Gui much
easier than I expected.

  One problem I am having is passing my interface class in at run time
because the iface path is hardcoded to 'smart.interfaces' in
smart.interface.  I am using the following work around. 

Would passing in a interfacepath variable be too intrusive?

Dave 

Index: __init__.py
===================================================================
--- __init__.py (revision 821)
+++ __init__.py (working copy)
@@ -85,7 +85,7 @@
 def init(command=None, argv=None,
          datadir=None, configfile=None,
          gui=False, shell=False, interface=None,
-         forcelocks=False, loglevel=None):
+         interfacepath=None, forcelocks=False, loglevel=None):
     from smart.const import DEBUG, INFO, WARNING, ERROR
     from smart.const import DATADIR, USERDATADIR
     from smart.interface import Interface, createInterface
@@ -119,7 +119,8 @@
         ifacename = interface
     else:
         ifacename = "text"
-    iface.object = createInterface(ifacename, ctrl, command, argv)
+    ifacepath = interfacepath
+    iface.object = createInterface(ifacepath, ifacename, ctrl, command,
argv)
 
     # Python's default to SIGPIPE is SIG_IGN, set by initsigs() in
     # pythonrun.c. As a side effect:
Index: interface.py
===================================================================
--- interface.py        (revision 821)
+++ interface.py        (working copy)
@@ -147,11 +147,12 @@
         return 80
     return struct.unpack('HHHH', x)[1]
 
-def createInterface(name, ctrl, command=None, argv=None):
+def createInterface(path,name, ctrl, command=None, argv=None):
     try:
+        xpath = path.replace('-', '_').lower()
         xname = name.replace('-', '_').lower()
-        smart = __import__("smart.interfaces."+xname)
-        interfaces = getattr(smart, "interfaces")
+        ifaces = __import__(xpath+".interfaces."+xname)
+        interfaces = getattr(ifaces, "interfaces")
         interface = getattr(interfaces, xname)
     except (ImportError, AttributeError):
         if sysconf.get("log-level") == DEBUG:





More information about the Smart mailing list