[Zodb-checkins] CVS: Packages/ZEO - fap.py:1.4

Jim Fulton jim@digicool.com
Thu, 5 Apr 2001 19:33:42 -0400 (EDT)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv23788

Modified Files:
	fap.py 
Log Message:
Redid ZServer search to use package path info.



--- Updated File fap.py in package Packages/ZEO --
--- fap.py	2001/04/04 17:54:04	1.3
+++ fap.py	2001/04/05 23:33:39	1.4
@@ -88,41 +88,41 @@
 Try to fix up the imports of these to make these dependencies work,
 localizing the hacks^H^H^H^H^Hchanges here.
 """
-import sys
+import sys, os
 
 def whiff(where):
     if not where: return 0
-    import os, imp
+    import imp
     try: m=imp.find_module('ZServer', [where])
     except: return 0
     else: return 1
     
 
-def fap(where=''):
+def fap():
     # if we are using an old version of Python, our asyncore is likely to
     # be out of date.  If ZServer is sitting around, we can get a current
     # version of ayncore from it. In any case, if we are going to be used
     # with Zope, it's important to use the version from Zope.
     try:
-        from ZServer.medusa import asyncore 
+        import ZServer
     except:
         # Try a little harder to import ZServer
         import os, imp
+        
+        location = package_home()
+        location = os.path.split(location)[0]
+        location = os.path.split(location)[0]
+        location = os.path.split(location)[0]
+        
+        if whiff(location):
+            sys.path.append(location)
+            try:
+                import ZServer
+            except:
+                pass
 
-        asyncore = None
+    import asyncore
 
-        for location in where, '.', os.path.join('..','..'):
-            if whiff(location):
-                sys.path.append(location)
-                try: 
-                    from ZServer.medusa import asyncore 
-                except:
-                    import asyncore
-                break
-
-        if asyncore is None:
-            import asyncore
-
     if sys.version[:1] < '2' and asyncore.loop.func_code.co_argcount < 3:
         raise ImportError, 'Cannot import an up-to-date asyncore'
 
@@ -146,3 +146,16 @@
     except:
         raise ImportError, 'Cannot import an up-to-date cPickle'
 
+
+def package_home():
+    m=sys.modules[__name__]
+    if hasattr(m,'__path__'):
+        r=m.__path__[0]
+    elif "." in __name__:
+        from string import rfind
+        r=sys.modules[__name__[:rfind(__name__,'.')]].__path__[0]
+    else:
+        r=__name__
+    return os.path.join(os.getcwd(), r)
+
+fap()