Browse Source

make genPyCode work on Linux and non-ctattach platforms

David Rose 22 years ago
parent
commit
029f99a1cc

+ 6 - 0
direct/src/ffi/FFIInterrogateDatabase.py

@@ -694,6 +694,12 @@ class FFIInterrogateDatabase:
 
 
 
 
     def generateCode(self, codeDir, extensionsDir):
     def generateCode(self, codeDir, extensionsDir):
+        # Empty out the codeDir of unnecessary crud from previous runs
+        # before we begin.
+        for file in os.listdir(codeDir):
+            pathname = os.path.join(codeDir, file)
+            os.unlink(pathname)
+        
         # Import all the C++ modules
         # Import all the C++ modules
         for CModuleName in FFIConstants.CodeModuleNameList:
         for CModuleName in FFIConstants.CodeModuleNameList:
             self.generateCodeLib(codeDir, extensionsDir, CModuleName)
             self.generateCodeLib(codeDir, extensionsDir, CModuleName)

+ 20 - 9
direct/src/showbase/pandaSqueezeTool.py

@@ -330,17 +330,28 @@ exec "import %(start)s"
 		# create bootstrap code
 		# create bootstrap code
 
 
 		fp = open(bootstrap, "w")
 		fp = open(bootstrap, "w")
-		# Note: Jesse Schell changed the following line to be very
-		# panda specific
+		# Note: David Rose adjusted the following to be more general.
 		fp.write("""\
 		fp.write("""\
 #%(localMagic)s %(archiveid)s
 #%(localMagic)s %(archiveid)s
-import ihooks,zlib,marshal,os
-try:
-  directroot = os.environ["DIRECT"]
-except KeyError:
-  print "Warning: environment variable DIRECT is not set."
-  directroot = ""
-archivePath = directroot + "\\lib\\py\\%(archive)s"
+import ihooks,zlib,marshal,os,sys
+
+def searchPath(filename):
+  # Look along the python load path for the indicated filename.
+  # Returns the located pathname, or None if the filename is not
+  # found.
+  for dir in sys.path:
+    pathname = os.path.join(dir, filename)
+    if os.path.exists(pathname):
+      return pathname
+
+  return None
+
+# Look for %(archive)s along the sys.path.
+archiveName = "%(archive)s"
+archivePath = searchPath(archiveName)
+if archivePath == None:
+  raise ImportError, "Could not locate %%s on PYTHONPATH." %% (archiveName)
+
 f=open(archivePath,"rb")
 f=open(archivePath,"rb")
 exec marshal.loads(%(zbegin)sf.read(%(loaderlen)d)%(zend)s)
 exec marshal.loads(%(zbegin)sf.read(%(loaderlen)d)%(zend)s)
 boot("%(app)s",f,%(size)d)
 boot("%(app)s",f,%(size)d)

+ 7 - 5
direct/src/showbase/pandaSqueezer.py

@@ -3,7 +3,7 @@ import sys
 import getopt
 import getopt
 import pandaSqueezeTool
 import pandaSqueezeTool
 
 
-# Assumption: We will be squeezing the files from C:\Panda\lib\py
+# Assumption: We will be squeezing the files from the current directory.
 
 
 try:
 try:
     opts, pargs = getopt.getopt(sys.argv[1:], 'O')
     opts, pargs = getopt.getopt(sys.argv[1:], 'O')
@@ -22,8 +22,7 @@ for opt in opts:
         print 'Squeezing pyo files'
         print 'Squeezing pyo files'
 
 
 def getSqueezeableFiles():
 def getSqueezeableFiles():
-    directDir = os.getenv('DIRECT')
-    fileList = os.listdir(directDir + "\lib\py")
+    fileList = os.listdir(".")
     newFileList = []
     newFileList = []
     if fOptimized:
     if fOptimized:
         targetFileExtension = ".pyo"
         targetFileExtension = ".pyo"
@@ -32,12 +31,15 @@ def getSqueezeableFiles():
     for i in fileList:
     for i in fileList:
         base,ext = os.path.splitext(i)
         base,ext = os.path.splitext(i)
         if (ext == ".py"):
         if (ext == ".py"):
-            j = directDir + "/lib/py/" + i
-            newFileList.append(j)
+            newFileList.append(i)
     return newFileList
     return newFileList
 
 
 def squeezePandaFiles():
 def squeezePandaFiles():
     l = getSqueezeableFiles()
     l = getSqueezeableFiles()
     pandaSqueezeTool.squeeze("PandaModules", "PandaModulesUnsqueezed", l)
     pandaSqueezeTool.squeeze("PandaModules", "PandaModulesUnsqueezed", l)
 
 
+    # Clean up the source files now that they've been squeezed.
+    for i in l:
+        os.unlink(i)
+
 squeezePandaFiles()
 squeezePandaFiles()