[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters - __init__.py:1.1.2.4

Andreas Jung andreas@digicool.com
Tue, 26 Feb 2002 20:31:21 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters
In directory cvs.zope.org:/tmp/cvs-serv14564/lib/python/Products/PluginIndexes/TextIndexNG/converters

Modified Files:
      Tag: ajung-textindexng-branch
	__init__.py 
Log Message:
code cleanup (thanks to Casey for example code)


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/converters/__init__.py 1.1.2.3 => 1.1.2.4 ===
+# check for converter modules
 
-import os, sys, imp
+import os, 
 
 _converters = {}
 
-oldpath = sys.path
-oldcwd = os.getcwd()
-dirname = os.path.dirname(__file__)
-os.chdir(dirname)
-converters = os.listdir('.')
+converters = os.listdir(__path__[0])
 converters = filter(lambda x: x.endswith('.py') and x!='__init__.py', converters)
 
-sys.path.append(os.getcwd())
-
-
 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()
+    mod = __import__(cv, globals(), globals(), __path__)
+    if hasattr(mod,'convert'):
+        _converters[cv] = mod.convert
 
-sys.path = oldpath
-os.chdir(oldcwd)
+del converters
 
 def getConverter(key):
     return _converters[key]