mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
VFSImporter.reload_packages()
This commit is contained in:
parent
e10b5111d3
commit
3002e8b571
@ -208,6 +208,11 @@ read_index() {
|
|||||||
s._start = read_uint32();
|
s._start = read_uint32();
|
||||||
s._length = read_uint32();
|
s._length = read_uint32();
|
||||||
unsigned int flags = read_uint16();
|
unsigned int flags = read_uint16();
|
||||||
|
if ((flags & 0x18) != 0) {
|
||||||
|
// Skip over the uncompressed length.
|
||||||
|
read_uint32();
|
||||||
|
}
|
||||||
|
|
||||||
s._timestamp = read_uint32();
|
s._timestamp = read_uint32();
|
||||||
size_t name_length = read_uint16();
|
size_t name_length = read_uint16();
|
||||||
char *buffer = new char[name_length];
|
char *buffer = new char[name_length];
|
||||||
|
@ -702,7 +702,7 @@ start_p3dpython(P3DInstance *inst) {
|
|||||||
const char *keep[] = {
|
const char *keep[] = {
|
||||||
"TMP", "TEMP", "HOME", "USER",
|
"TMP", "TEMP", "HOME", "USER",
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
"SYSTEMROOT", "USERPROFILE",
|
"SYSTEMROOT", "USERPROFILE", "COMSPEC",
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,7 @@ import imp
|
|||||||
import struct
|
import struct
|
||||||
import __builtin__
|
import __builtin__
|
||||||
|
|
||||||
__all__ = ['register']
|
__all__ = ['register', 'reload_from', 'reload_packages']
|
||||||
|
|
||||||
vfs = VirtualFileSystem.getGlobalPtr()
|
vfs = VirtualFileSystem.getGlobalPtr()
|
||||||
|
|
||||||
@ -274,3 +274,43 @@ def register():
|
|||||||
_registered = True
|
_registered = True
|
||||||
sys.path_hooks.insert(0, VFSImporter)
|
sys.path_hooks.insert(0, VFSImporter)
|
||||||
|
|
||||||
|
def reload_from(root_path, moduleName):
|
||||||
|
""" Reloads the named module from the indicated root directory,
|
||||||
|
merging it with the module already loaded, if any. This is
|
||||||
|
particularly useful for merging a VFS-mounted package with a
|
||||||
|
previously-frozen package. It allows you to release the initial
|
||||||
|
version of a package via the freeze mechanism, while still
|
||||||
|
allowing new additions to be added later via multifile.
|
||||||
|
|
||||||
|
See also reload_packages(), which is a convenience function
|
||||||
|
wrapped around this one. """
|
||||||
|
|
||||||
|
path = root_path + '/' + '/'.join(moduleName.split('.')[:-1])
|
||||||
|
importer = VFSImporter(path)
|
||||||
|
loader = importer.find_module(moduleName)
|
||||||
|
if loader:
|
||||||
|
loader.load_module(moduleName)
|
||||||
|
|
||||||
|
def reload_packages(multifile, root_path):
|
||||||
|
""" Walks the multifile and looks for Python packages that already
|
||||||
|
exist as frozen modules. For any such packages found, calls
|
||||||
|
reload_from() to merge them with the preloaded frozen package. """
|
||||||
|
|
||||||
|
for i in range(multifile.getNumSubfiles()):
|
||||||
|
filename = multifile.getSubfileName(i)
|
||||||
|
isInit = False
|
||||||
|
for ext in ['py'] + compiledExtensions:
|
||||||
|
if filename.endswith('/__init__.' + ext):
|
||||||
|
isInit = True
|
||||||
|
break
|
||||||
|
if not isInit:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Found a package.
|
||||||
|
moduleName = '.'.join(filename.split('/')[:-1])
|
||||||
|
module = sys.modules.get(moduleName, None)
|
||||||
|
if module:
|
||||||
|
file = getattr(module, '__file__', None)
|
||||||
|
if file == '<frozen>':
|
||||||
|
# It's a frozen module; replace it.
|
||||||
|
reload_from(root_path, moduleName)
|
||||||
|
@ -720,7 +720,7 @@ class Freezer:
|
|||||||
for mdef in autoIncludes:
|
for mdef in autoIncludes:
|
||||||
try:
|
try:
|
||||||
self.__loadModule(mdef)
|
self.__loadModule(mdef)
|
||||||
# Since it succesfully loaded, it's no longer a guess.
|
# Since it successfully loaded, it's no longer a guess.
|
||||||
mdef.guess = False
|
mdef.guess = False
|
||||||
except:
|
except:
|
||||||
# Something went wrong, guess it's not an importable
|
# Something went wrong, guess it's not an importable
|
||||||
|
@ -132,7 +132,13 @@ def main(appRunner):
|
|||||||
""" This function is called when this module is invoked as
|
""" This function is called when this module is invoked as
|
||||||
packp3d.p3d. """
|
packp3d.p3d. """
|
||||||
|
|
||||||
makePackedApp(appRunner.argv[1:])
|
print "args = %s" % (appRunner.argv,)
|
||||||
|
try:
|
||||||
|
makePackedApp(appRunner.argv[1:])
|
||||||
|
except ArgumentError, e:
|
||||||
|
print e.args[0]
|
||||||
|
sys.exit(1)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
|
@ -300,6 +300,7 @@ class AppRunner(DirectObject):
|
|||||||
|
|
||||||
# Mount the Multifile under /mf, by convention.
|
# Mount the Multifile under /mf, by convention.
|
||||||
vfs.mount(mf, MultifileRoot, vfs.MFReadOnly)
|
vfs.mount(mf, MultifileRoot, vfs.MFReadOnly)
|
||||||
|
VFSImporter.reload_packages(mf, MultifileRoot)
|
||||||
|
|
||||||
# Load any prc files in the root. We have to load them
|
# Load any prc files in the root. We have to load them
|
||||||
# explicitly, since the ConfigPageManager can't directly look
|
# explicitly, since the ConfigPageManager can't directly look
|
||||||
|
Loading…
x
Reference in New Issue
Block a user