From 029f99a1ccb72b691dcb3b2dd309d498b76fdf26 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 21 Jun 2003 15:08:10 +0000 Subject: [PATCH] make genPyCode work on Linux and non-ctattach platforms --- direct/src/ffi/FFIInterrogateDatabase.py | 6 +++++ direct/src/showbase/pandaSqueezeTool.py | 29 ++++++++++++++++-------- direct/src/showbase/pandaSqueezer.py | 12 ++++++---- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/direct/src/ffi/FFIInterrogateDatabase.py b/direct/src/ffi/FFIInterrogateDatabase.py index a035f56bea..86092be018 100644 --- a/direct/src/ffi/FFIInterrogateDatabase.py +++ b/direct/src/ffi/FFIInterrogateDatabase.py @@ -694,6 +694,12 @@ class FFIInterrogateDatabase: 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 for CModuleName in FFIConstants.CodeModuleNameList: self.generateCodeLib(codeDir, extensionsDir, CModuleName) diff --git a/direct/src/showbase/pandaSqueezeTool.py b/direct/src/showbase/pandaSqueezeTool.py index d235773b1e..fbf51d9319 100755 --- a/direct/src/showbase/pandaSqueezeTool.py +++ b/direct/src/showbase/pandaSqueezeTool.py @@ -330,17 +330,28 @@ exec "import %(start)s" # create bootstrap code 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("""\ #%(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") exec marshal.loads(%(zbegin)sf.read(%(loaderlen)d)%(zend)s) boot("%(app)s",f,%(size)d) diff --git a/direct/src/showbase/pandaSqueezer.py b/direct/src/showbase/pandaSqueezer.py index 7d5da75288..f94648c5ec 100644 --- a/direct/src/showbase/pandaSqueezer.py +++ b/direct/src/showbase/pandaSqueezer.py @@ -3,7 +3,7 @@ import sys import getopt 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: opts, pargs = getopt.getopt(sys.argv[1:], 'O') @@ -22,8 +22,7 @@ for opt in opts: print 'Squeezing pyo files' def getSqueezeableFiles(): - directDir = os.getenv('DIRECT') - fileList = os.listdir(directDir + "\lib\py") + fileList = os.listdir(".") newFileList = [] if fOptimized: targetFileExtension = ".pyo" @@ -32,12 +31,15 @@ def getSqueezeableFiles(): for i in fileList: base,ext = os.path.splitext(i) if (ext == ".py"): - j = directDir + "/lib/py/" + i - newFileList.append(j) + newFileList.append(i) return newFileList def squeezePandaFiles(): l = getSqueezeableFiles() pandaSqueezeTool.squeeze("PandaModules", "PandaModulesUnsqueezed", l) + # Clean up the source files now that they've been squeezed. + for i in l: + os.unlink(i) + squeezePandaFiles()