From d315933ac5f974a1fe27f41161411d792eb990f5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 21 Aug 2009 01:35:00 +0000 Subject: [PATCH] package -> plugin, and other minor changes --- direct/src/configfiles/panda3d.pdef | 3 ++ direct/src/plugin_npapi/ppInstance.cxx | 20 +++++----- direct/src/plugin_npapi/ppInstance.h | 2 +- direct/src/plugin_standalone/panda3d.cxx | 20 +++++----- direct/src/plugin_standalone/panda3d.h | 2 +- direct/src/showutil/make_contents.py | 47 +++++++++++++++++------- direct/src/showutil/runp3d.py | 33 +++++++---------- 7 files changed, 71 insertions(+), 56 deletions(-) diff --git a/direct/src/configfiles/panda3d.pdef b/direct/src/configfiles/panda3d.pdef index e8035c5211..b31543d88a 100755 --- a/direct/src/configfiles/panda3d.pdef +++ b/direct/src/configfiles/panda3d.pdef @@ -78,10 +78,13 @@ file libtinydisplay.dll # variables. inline_file Config.prc extract=1 <<- plugin-path $PANDA3D_ROOT + aux-display pandagl aux-display pandadx9 aux-display pandadx8 aux-display tinydisplay + + default-model-extension .bam end_package panda3d diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index e0140cd51d..97c94bf32a 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -712,23 +712,23 @@ read_contents_file(const string &contents_filename) { TiXmlElement *xcontents = doc.FirstChildElement("contents"); if (xcontents != NULL) { - TiXmlElement *xpackage = xcontents->FirstChildElement("package"); - while (xpackage != NULL) { - const char *name = xpackage->Attribute("name"); + TiXmlElement *xplugin = xcontents->FirstChildElement("plugin"); + while (xplugin != NULL) { + const char *name = xplugin->Attribute("name"); if (name != NULL && strcmp(name, "coreapi") == 0) { - const char *platform = xpackage->Attribute("platform"); + const char *platform = xplugin->Attribute("platform"); if (platform != NULL && strcmp(platform, DTOOL_PLATFORM) == 0) { - get_core_api(xpackage); + get_core_api(xplugin); return true; } } - xpackage = xpackage->NextSiblingElement("package"); + xplugin = xplugin->NextSiblingElement("plugin"); } } - // Couldn't find the coreapi package description. - nout << "No coreapi package defined in contents file for " + // Couldn't find the coreapi plugin description. + nout << "No coreapi plugin defined in contents file for " << DTOOL_PLATFORM << "\n"; return false; } @@ -828,8 +828,8 @@ feed_file(PPDownloadRequest *req, const string &filename) { // if necessary. //////////////////////////////////////////////////////////////////// void PPInstance:: -get_core_api(TiXmlElement *xpackage) { - _core_api_dll.load_xml(xpackage); +get_core_api(TiXmlElement *xplugin) { + _core_api_dll.load_xml(xplugin); if (_core_api_dll.quick_verify(_root_dir)) { // The DLL file is good. Just load it. diff --git a/direct/src/plugin_npapi/ppInstance.h b/direct/src/plugin_npapi/ppInstance.h index 157c1a9119..d02178fcfd 100644 --- a/direct/src/plugin_npapi/ppInstance.h +++ b/direct/src/plugin_npapi/ppInstance.h @@ -72,7 +72,7 @@ private: void feed_file(PPDownloadRequest *req, const string &filename); bool read_contents_file(const string &contents_filename); - void get_core_api(TiXmlElement *xpackage); + void get_core_api(TiXmlElement *xplugin); void downloaded_plugin(const string &filename); void do_load_plugin(); diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index 9c56de5b22..17a9e58b3a 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -370,23 +370,23 @@ read_contents_file(Filename contents_filename, const string &download_url, TiXmlElement *xcontents = doc.FirstChildElement("contents"); if (xcontents != NULL) { - TiXmlElement *xpackage = xcontents->FirstChildElement("package"); - while (xpackage != NULL) { - const char *name = xpackage->Attribute("name"); + TiXmlElement *xplugin = xcontents->FirstChildElement("plugin"); + while (xplugin != NULL) { + const char *name = xplugin->Attribute("name"); if (name != NULL && strcmp(name, "coreapi") == 0) { - const char *xplatform = xpackage->Attribute("platform"); + const char *xplatform = xplugin->Attribute("platform"); if (xplatform != NULL && strcmp(xplatform, this_platform.c_str()) == 0) { return get_core_api(contents_filename, download_url, this_platform, - xpackage); + xplugin); } } - xpackage = xpackage->NextSiblingElement("package"); + xplugin = xplugin->NextSiblingElement("plugin"); } } - // Couldn't find the coreapi package description. - cerr << "No coreapi package defined in contents file for " + // Couldn't find the coreapi plugin description. + cerr << "No coreapi plugin defined in contents file for " << this_platform << "\n"; return false; } @@ -401,8 +401,8 @@ read_contents_file(Filename contents_filename, const string &download_url, //////////////////////////////////////////////////////////////////// bool Panda3D:: get_core_api(const Filename &contents_filename, const string &download_url, - const string &this_platform, TiXmlElement *xpackage) { - _core_api_dll.load_xml(xpackage); + const string &this_platform, TiXmlElement *xplugin) { + _core_api_dll.load_xml(xplugin); if (!_core_api_dll.quick_verify(_root_dir)) { // The DLL file needs to be downloaded. Go get it. diff --git a/direct/src/plugin_standalone/panda3d.h b/direct/src/plugin_standalone/panda3d.h index f695b3798f..8085337f9f 100755 --- a/direct/src/plugin_standalone/panda3d.h +++ b/direct/src/plugin_standalone/panda3d.h @@ -49,7 +49,7 @@ private: const string &this_platform); bool get_core_api(const Filename &contents_filename, const string &download_url, const string &this_platform, - TiXmlElement *xpackage); + TiXmlElement *xplugin); void run_getters(); void handle_request(P3D_request *request); void make_parent_window(P3D_window_handle &parent_window, diff --git a/direct/src/showutil/make_contents.py b/direct/src/showutil/make_contents.py index c665a2fa3d..19791c3fe7 100755 --- a/direct/src/showutil/make_contents.py +++ b/direct/src/showutil/make_contents.py @@ -23,7 +23,12 @@ Options: import sys import getopt import os -import md5 + +try: + import hashlib +except ImportError: + # Legacy Python support + import md5 as hashlib class ArgumentError(AttributeError): pass @@ -40,7 +45,7 @@ class FileSpec: self.size = s.st_size self.timestamp = int(s.st_mtime) - m = md5.new() + m = hashlib.md5() m.update(open(pathname, 'rb').read()) self.hash = m.hexdigest() @@ -70,9 +75,9 @@ class ContentsMaker: print >> f, '' print >> f, '' print >> f, '' - for packageName, packagePlatform, packageVersion, file in self.packages: - print >> f, ' ' % ( - packageName, packagePlatform or '', packageVersion, file.getParams()) + for type, packageName, packagePlatform, packageVersion, file in self.packages: + print >> f, ' <%s name="%s" platform="%s" version="%s" %s />' % ( + type, packageName, packagePlatform or '', packageVersion, file.getParams()) print >> f, '' f.close() @@ -93,12 +98,15 @@ class ContentsMaker: localpath = dirpath[len(prefix):].replace(os.sep, '/') + '/' xml = dirpath[len(prefix):].replace(os.sep, '_') + '.xml' + type = 'package' + # A special case: the "plugin" and "coreapi" directories # don't have xml files, just dll's. if xml.startswith('plugin_') or xml.startswith('coreapi_'): if filenames: assert len(filenames) == 1 xml = filenames[0] + type = 'plugin' if xml not in filenames: continue @@ -106,17 +114,28 @@ class ContentsMaker: if localpath.count('/') == 2: packageName, packageVersion, junk = localpath.split('/') packagePlatform = None - file = FileSpec(localpath + xml, - os.path.join(self.installDir, localpath + xml)) - print file.filename - self.packages.append((packageName, packagePlatform, packageVersion, file)) - if localpath.count('/') == 3: + elif localpath.count('/') == 3: packageName, packagePlatform, packageVersion, junk = localpath.split('/') - file = FileSpec(localpath + xml, - os.path.join(self.installDir, localpath + xml)) - print file.filename - self.packages.append((packageName, packagePlatform, packageVersion, file)) + else: + continue + + file = FileSpec(localpath + xml, + os.path.join(self.installDir, localpath + xml)) + print file.filename + self.packages.append((type, packageName, packagePlatform, packageVersion, file)) + + if type == 'package': + # Look for an _import.xml file, too. + xml = xml[:-4] + '_import.xml' + try: + file = FileSpec(localpath + xml, + os.path.join(self.installDir, localpath + xml)) + except OSError: + file = None + if file: + print file.filename + self.packages.append(('import', packageName, packagePlatform, packageVersion, file)) def makeContents(args): diff --git a/direct/src/showutil/runp3d.py b/direct/src/showutil/runp3d.py index 6f7807c9a9..7a47216baf 100755 --- a/direct/src/showutil/runp3d.py +++ b/direct/src/showutil/runp3d.py @@ -35,15 +35,6 @@ import os import types import __builtin__ -MultifileRoot = '/mf' - -# This defines the default prc file that is implicitly loaded with an -# application. -AppPrcFilename = 'App.prc' -AppPrc = """ -default-model-extension .bam -""" - class ArgumentError(AttributeError): pass @@ -76,6 +67,11 @@ class AppRunner(DirectObject): # TODO: we need one of these per instance, not per session. self.instanceId = None + # The mount point for the multifile. For now, this is always + # the same, but when we move to multiple-instance sessions, it + # may have to be different for each instance. + self.multifileRoot = '/mf' + # The attributes of this object will be exposed as attributes # of the plugin instance in the DOM. self.attributes = ScriptAttributes() @@ -177,13 +173,10 @@ class AppRunner(DirectObject): # Now set up Python to import this stuff. VFSImporter.register() - sys.path = [ MultifileRoot ] + sys.path + sys.path = [ self.multifileRoot ] + sys.path - # Put our root directory on the model-path and prc-path, too. - getModelPath().prependDirectory(MultifileRoot) - - # Load the implicit App.prc file. - loadPrcFileData(AppPrcFilename, AppPrc) + # Put our root directory on the model-path, too. + getModelPath().prependDirectory(self.multifileRoot) # Replace the builtin open and file symbols so user code will get # our versions by default, which can open and read files out of @@ -196,7 +189,7 @@ class AppRunner(DirectObject): if not self.fullDiskAccess: # Make "/mf" our "current directory", for running the multifiles # we plan to mount there. - vfs.chdir(MultifileRoot) + vfs.chdir(self.multifileRoot) def startIfReady(self): if self.started: @@ -223,7 +216,7 @@ class AppRunner(DirectObject): if mainName: moduleName = mainName - root = MultifileRoot + root = self.multifileRoot if '.' in moduleName: root += '/' + '/'.join(moduleName.split('.')[:-1]) v = VFSImporter.VFSImporter(root) @@ -308,8 +301,8 @@ class AppRunner(DirectObject): self.initPackedAppEnvironment() # Mount the Multifile under /mf, by convention. - vfs.mount(mf, MultifileRoot, vfs.MFReadOnly) - VFSImporter.freeze_new_modules(mf, MultifileRoot) + vfs.mount(mf, self.multifileRoot, vfs.MFReadOnly) + VFSImporter.freeze_new_modules(mf, self.multifileRoot) # Load any prc files in the root. We have to load them # explicitly, since the ConfigPageManager can't directly look @@ -319,7 +312,7 @@ class AppRunner(DirectObject): for f in mf.getSubfileNames(): fn = Filename(f) if fn.getDirname() == '' and fn.getExtension() == 'prc': - pathname = '%s/%s' % (MultifileRoot, f) + pathname = '%s/%s' % (self.multifileRoot, f) data = open(pathname, 'r').read() loadPrcFileData(pathname, data)