|
@@ -3,49 +3,70 @@ __all__ = ["Dtool_ObjectToDict", "Dtool_funcToMethod", "Dtool_PreloadDLL"]
|
|
|
|
|
|
|
|
import imp,sys,os
|
|
import imp,sys,os
|
|
|
|
|
|
|
|
-is_python_d = False
|
|
|
|
|
|
|
+# The following code exists to work around a problem that exists
|
|
|
|
|
+# with Python 2.5 or greater.
|
|
|
|
|
+
|
|
|
|
|
+# Specifically, Python 2.5 is designed to import files named *.pyd
|
|
|
|
|
+# only; it will not import files named *.dll (or *.so). We work
|
|
|
|
|
+# around this problem by explicitly preloading all of the dll's we
|
|
|
|
|
+# expect to need.
|
|
|
|
|
+
|
|
|
dll_suffix = ''
|
|
dll_suffix = ''
|
|
|
-dll_ext = '.dll'
|
|
|
|
|
-if (sys.platform == "darwin"):
|
|
|
|
|
- dll_ext = '.dylib'
|
|
|
|
|
-
|
|
|
|
|
-if (sys.platform == "win32"):
|
|
|
|
|
- # If we launched from python_d.exe, we need to load libpanda_d.dll, etc.
|
|
|
|
|
- is_python_d = (sys.executable.endswith('_d.exe'))
|
|
|
|
|
- if is_python_d:
|
|
|
|
|
|
|
+if sys.platform == "win32":
|
|
|
|
|
+ # On Windows, dynamic libraries end in ".dll".
|
|
|
|
|
+ dll_ext = '.dll'
|
|
|
|
|
+
|
|
|
|
|
+ # If we launched from python_d.exe, we need to load
|
|
|
|
|
+ # libpanda_d.dll, etc.
|
|
|
|
|
+ if sys.executable.endswith('_d.exe'):
|
|
|
dll_suffix = '_d'
|
|
dll_suffix = '_d'
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+else:
|
|
|
|
|
+ # On OSX or Linux, dynamic libraries end in ".so". OSX also
|
|
|
|
|
+ # provides *.dylib files, but these are apparently not intended to
|
|
|
|
|
+ # be imported directly.
|
|
|
|
|
+ dll_ext = '.so'
|
|
|
|
|
+
|
|
|
|
|
+if sys.platform == "win32":
|
|
|
|
|
+ # On Windows, we must furthermore ensure that the PATH is modified
|
|
|
|
|
+ # to locate all of the DLL files.
|
|
|
|
|
+
|
|
|
|
|
+ # First, search for the directory that contains all of our compiled
|
|
|
|
|
+ # modules.
|
|
|
target = None
|
|
target = None
|
|
|
filename = "libpandaexpress%s%s" % (dll_suffix, dll_ext)
|
|
filename = "libpandaexpress%s%s" % (dll_suffix, dll_ext)
|
|
|
for dir in sys.path + [sys.prefix]:
|
|
for dir in sys.path + [sys.prefix]:
|
|
|
lib = os.path.join(dir, filename)
|
|
lib = os.path.join(dir, filename)
|
|
|
if (os.path.exists(lib)):
|
|
if (os.path.exists(lib)):
|
|
|
target = dir
|
|
target = dir
|
|
|
- if (target == None):
|
|
|
|
|
|
|
+ if target == None:
|
|
|
message = "Cannot find %s" % (filename)
|
|
message = "Cannot find %s" % (filename)
|
|
|
raise message
|
|
raise message
|
|
|
- path=os.environ["PATH"]
|
|
|
|
|
- if (path.startswith(target+";")==0):
|
|
|
|
|
- os.environ["PATH"] = target+";"+path
|
|
|
|
|
|
|
|
|
|
-def Dtool_PreloadDLL(module):
|
|
|
|
|
- """ Preloading solves the problem that python 2.5 on
|
|
|
|
|
- windows can't find DLLs - it can only find PYDs. The
|
|
|
|
|
- preloader is able to find DLLs."""
|
|
|
|
|
|
|
+ # And add that directory to the system path.
|
|
|
|
|
+ path = os.environ["PATH"]
|
|
|
|
|
+ if not path.startswith(target + ";"):
|
|
|
|
|
+ os.environ["PATH"] = target + ";" + path
|
|
|
|
|
|
|
|
- if (sys.platform != "win32" and sys.platform != "darwin"):
|
|
|
|
|
- return
|
|
|
|
|
|
|
+def Dtool_PreloadDLL(module):
|
|
|
if (sys.modules.has_key(module)):
|
|
if (sys.modules.has_key(module)):
|
|
|
return
|
|
return
|
|
|
|
|
+
|
|
|
|
|
+ # Search for the appropriate directory.
|
|
|
target = None
|
|
target = None
|
|
|
|
|
+ filename = module + dll_suffix + dll_ext
|
|
|
for dir in sys.path + [sys.prefix]:
|
|
for dir in sys.path + [sys.prefix]:
|
|
|
- lib = os.path.join(dir, module + dll_suffix + dll_ext)
|
|
|
|
|
|
|
+ lib = os.path.join(dir, filename)
|
|
|
if (os.path.exists(lib)):
|
|
if (os.path.exists(lib)):
|
|
|
target = dir
|
|
target = dir
|
|
|
break
|
|
break
|
|
|
- if (target == None):
|
|
|
|
|
- raise "DLL loader cannot find "+module+"."
|
|
|
|
|
- imp.load_dynamic(module, os.path.join(target, module + dll_suffix + dll_ext))
|
|
|
|
|
|
|
+ if target == None:
|
|
|
|
|
+ message = "DLL loader cannot find %s." % (module)
|
|
|
|
|
+ raise message
|
|
|
|
|
+
|
|
|
|
|
+ # Now import the file explicitly.
|
|
|
|
|
+ pathname = os.path.join(target, filename)
|
|
|
|
|
+ imp.load_dynamic(module, pathname)
|
|
|
|
|
|
|
|
Dtool_PreloadDLL("libpandaexpress")
|
|
Dtool_PreloadDLL("libpandaexpress")
|
|
|
from libpandaexpress import *
|
|
from libpandaexpress import *
|