I'm trying to import modules as plugins. I want to import all Plugins
in a specified directory on server-start. This is my Test-import:

import os
import sets
import imp

def find_modules(path="./plugins"):
    """Return names of modules in a directory.

    Returns module names in a list. Filenames that end in ".py" or
    ".pyc" are considered to be modules. The extension is not included
    in the returned list.
    """
    modules = sets.Set()
    for filename in os.listdir(path):
        module = None
        if filename.endswith(".py"):
            module = filename[:-3]
        elif filename.endswith(".pyc"):
            module = filename[:-4]
        if module is not None:
            modules.add(module)
    print modules
    return list(modules)

def load_module(name, path=["./plugins"]):
    """Return a named module found in a given path."""
    (file, pathname, description) = imp.find_module(name, path)
    return imp.load_module(name, file, pathname, description)

def functions_in_module(module):
    functions = []
    for obj in module.__dict__.values():
        if isinstance(obj, types.FunctionType):
            functions.append(obj)
    print functions
    return functions

for name in find_modules():
    print 'importing: '+ name
    temp=load_module(name) #this should be mplug
    temp.testor() #testfunction, should be mplug.testor()
    print temp.bladic #tempdict in testfunction, should be
mplug.bladic


Problem: it imports the module correctly, but ...
I have a plugin called mplug. And I want to access it through
Turbogears (URL: localhost/mplug/Function). It has to be dynamical, so
i don't know the name on import. How can I access it with its "real"
module-name?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to