diff options
author | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2007-09-20 15:08:27 -0400 |
---|---|---|
committer | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2007-09-20 15:08:27 -0400 |
commit | 733df2df42180487608688951acf1a83e079a86c (patch) | |
tree | 01917e26d60194ac294008a95394d18029522b32 /server/module_loader.py | |
parent | d96d4b72aebee6dc1089dd260705c23cb1b9cd27 (diff) | |
download | third_party-func-733df2df42180487608688951acf1a83e079a86c.tar.gz third_party-func-733df2df42180487608688951acf1a83e079a86c.tar.xz third_party-func-733df2df42180487608688951acf1a83e079a86c.zip |
initial code drop
module_loader from the virt-factory node server
xmlrpc server from the virt-factory-server code and some test modules
no ssl support yet, no init scripts, no packagin etc
Diffstat (limited to 'server/module_loader.py')
-rwxr-xr-x | server/module_loader.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/server/module_loader.py b/server/module_loader.py new file mode 100755 index 0000000..10631fe --- /dev/null +++ b/server/module_loader.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + + +import distutils.sysconfig +import os +import sys +import glob +from rhpl.translate import _, N_, textdomain, utf8 + +module_file_path="modules/" +mod_path="server/" +sys.path.insert(0, mod_path) + +def load_modules(module_path=module_file_path, blacklist=None): + filenames = glob.glob("%s/*.py" % module_file_path) + filenames = filenames + glob.glob("%s/*.pyc" % module_file_path) + filesnames = filenames + glob.glob("%s/*.pyo" % module_file_path) + + mods = {} + + print sys.path + + for fn in filenames: + basename = os.path.basename(fn) + if basename == "__init__.py": + continue + if basename[-3:] == ".py": + modname = basename[:-3] + elif basename[-4:] in [".pyc", ".pyo"]: + modname = basename[:-4] + + + try: + blip = __import__("modules.%s" % ( modname), globals(), locals(), [modname]) + if not hasattr(blip, "register_rpc"): + errmsg = _("%(module_path)s/%(modname)s module not a proper module") + print errmsg % {'module_path': module_path, 'modname':modname} + continue + mods[modname] = blip + except ImportError, e: + # shouldn't this be fatal? + print e + raise + + return mods + + + + +if __name__ == "__main__": + print load_modules(module_path) + + |