[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters - __init__.py:1.1.2.2
Andreas Jung
andreas@digicool.com
Tue, 26 Feb 2002 18:46:24 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters
In directory cvs.zope.org:/tmp/cvs-serv20992/converters
Modified Files:
Tag: ajung-textindexng-branch
__init__.py
Log Message:
added registry for converters
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters/__init__.py 1.1.2.1 => 1.1.2.2 ===
+
+import os
+import imp
+
+_converters = {}
+
+oldcwd = os.getcwd()
+dirname = os.path.dirname(__file__)
+os.chdir(dirname)
+converters = os.listdir('.')
+converters = filter(lambda x: x.endswith('.py') and x!='__init__.py', converters)
+
+for cv in converters:
+
+ cv = cv[:-3]
+ fp, pathname, desc = imp.find_module(cv)
+
+ try:
+ mod = imp.load_module(cv, fp, pathname, desc)
+ exec("_converters[cv] = mod.convert")
+ finally:
+ fp.close()
+
+
+os.chdir(oldcwd)
+
+def getConverter(key):
+ return _converters[key]