From 623a770f4bd8dc02c41d03d832300dde3558155c Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Wed, 7 Feb 2001 18:08:15 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/showbase/Finder.py | 36 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/direct/src/showbase/Finder.py b/direct/src/showbase/Finder.py index 2e4e2723f6..f9d159c5ea 100644 --- a/direct/src/showbase/Finder.py +++ b/direct/src/showbase/Finder.py @@ -52,7 +52,7 @@ def findClass(namespace, className): def rebindClass(builtins, filename): - file = open(filename) + file = open(filename, 'r') lines = file.readlines() curLine = 0 found = 0 @@ -82,41 +82,33 @@ def rebindClass(builtins, filename): if not found: print 'error: className not found' - return None + return # Store the original real class res = findClass(builtins, className) if res: realClass, realNameSpace = res else: - print ('Error redinifing class: could not find class: ' + className) - return None - - # Make a temp file in the home directory to execfile from - tmpfilename = os.path.join(os.getenv('HOME'), 'tmp_py_file') - tmpfile = open(tmpfilename, 'w') - - # now write the class back to the file with the new class name - for i in range(len(lines)): -# if (i == foundLine): -# tmpfile.write(newline) -# else: - tmpfile.write(lines[i]) - - file.close() - tmpfile.close() + print ('Warning: could not find class, defining new class in builtins: ' + className) + # Now execute that class def + execfile(filename, builtins) + # Remove that temp file + file.close() + os.remove(filename) + return # Now execute that class def - execfile(tmpfilename, realNameSpace) + execfile(filename, realNameSpace) # Remove that temp file - os.remove(tmpfilename) + file.close() + os.remove(filename) res = findClass(realNameSpace, className) if res: tmpClass, tmpNameSpace = res else: - print ('Error redinifing class: could not find temp class') - return None + print ('Internal error redefining class: could not find temp class') + return # Copy the functions that we just redefined into the real class copyFuncs(tmpClass, realClass)