From 350b2aaf3cf081f5430ea6576a0e8c1cd91c11b0 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 23 Jul 2013 17:27:58 +0000 Subject: [PATCH] Add version of execfile() that uses the VFS --- direct/src/p3d/AppRunner.py | 1 + direct/src/stdpy/file.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/direct/src/p3d/AppRunner.py b/direct/src/p3d/AppRunner.py index 17b6a99b2f..47c1a20d65 100644 --- a/direct/src/p3d/AppRunner.py +++ b/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 diff --git a/direct/src/stdpy/file.py b/direct/src/stdpy/file.py index e437293e1b..54ca31af55 100644 --- a/direct/src/stdpy/file.py +++ b/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)