Browse Source

Add version of execfile() that uses the VFS

rdb 12 years ago
parent
commit
350b2aaf3c
2 changed files with 9 additions and 0 deletions
  1. 1 0
      direct/src/p3d/AppRunner.py
  2. 8 0
      direct/src/stdpy/file.py

+ 1 - 0
direct/src/p3d/AppRunner.py

@@ -702,6 +702,7 @@ class AppRunner(DirectObject):
             # the multifile.
             __builtin__.file = file.file
             __builtin__.open = file.open
+            __builtin__.execfile = file.execfile
             os.listdir = file.listdir
             os.walk = file.walk
             os.path.join = file.join

+ 8 - 0
direct/src/stdpy/file.py

@@ -7,6 +7,7 @@ for I/O to complete. """
 __all__ = [
     'file', 'open', 'listdir', 'walk', 'join',
     'isfile', 'isdir', 'exists', 'lexists', 'getmtime', 'getsize',
+    'execfile',
     ]
 
 from pandac import PandaModules as pm
@@ -360,3 +361,10 @@ def getsize(path):
         raise os.error
     return file.getFileSize()
 
+def execfile(path, globals=None, locals=None):
+    file = _vfs.getFile(pm.Filename.fromOsSpecific(path), True)
+    if not file:
+        raise os.error
+
+    data = file.readFile(False)
+    exec(data, globals, locals)