package -> plugin, and other minor changes

This commit is contained in:
David Rose 2009-08-21 01:35:00 +00:00
parent d9986dad01
commit d315933ac5
7 changed files with 71 additions and 56 deletions

View File

@ -78,10 +78,13 @@ file libtinydisplay.dll
# variables. # variables.
inline_file Config.prc extract=1 <<- <EOF> inline_file Config.prc extract=1 <<- <EOF>
plugin-path $PANDA3D_ROOT plugin-path $PANDA3D_ROOT
aux-display pandagl aux-display pandagl
aux-display pandadx9 aux-display pandadx9
aux-display pandadx8 aux-display pandadx8
aux-display tinydisplay aux-display tinydisplay
default-model-extension .bam
<EOF> <EOF>
end_package panda3d end_package panda3d

View File

@ -712,23 +712,23 @@ read_contents_file(const string &contents_filename) {
TiXmlElement *xcontents = doc.FirstChildElement("contents"); TiXmlElement *xcontents = doc.FirstChildElement("contents");
if (xcontents != NULL) { if (xcontents != NULL) {
TiXmlElement *xpackage = xcontents->FirstChildElement("package"); TiXmlElement *xplugin = xcontents->FirstChildElement("plugin");
while (xpackage != NULL) { while (xplugin != NULL) {
const char *name = xpackage->Attribute("name"); const char *name = xplugin->Attribute("name");
if (name != NULL && strcmp(name, "coreapi") == 0) { 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) { if (platform != NULL && strcmp(platform, DTOOL_PLATFORM) == 0) {
get_core_api(xpackage); get_core_api(xplugin);
return true; return true;
} }
} }
xpackage = xpackage->NextSiblingElement("package"); xplugin = xplugin->NextSiblingElement("plugin");
} }
} }
// Couldn't find the coreapi package description. // Couldn't find the coreapi plugin description.
nout << "No coreapi package defined in contents file for " nout << "No coreapi plugin defined in contents file for "
<< DTOOL_PLATFORM << "\n"; << DTOOL_PLATFORM << "\n";
return false; return false;
} }
@ -828,8 +828,8 @@ feed_file(PPDownloadRequest *req, const string &filename) {
// if necessary. // if necessary.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PPInstance:: void PPInstance::
get_core_api(TiXmlElement *xpackage) { get_core_api(TiXmlElement *xplugin) {
_core_api_dll.load_xml(xpackage); _core_api_dll.load_xml(xplugin);
if (_core_api_dll.quick_verify(_root_dir)) { if (_core_api_dll.quick_verify(_root_dir)) {
// The DLL file is good. Just load it. // The DLL file is good. Just load it.

View File

@ -72,7 +72,7 @@ private:
void feed_file(PPDownloadRequest *req, const string &filename); void feed_file(PPDownloadRequest *req, const string &filename);
bool read_contents_file(const string &contents_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 downloaded_plugin(const string &filename);
void do_load_plugin(); void do_load_plugin();

View File

@ -370,23 +370,23 @@ read_contents_file(Filename contents_filename, const string &download_url,
TiXmlElement *xcontents = doc.FirstChildElement("contents"); TiXmlElement *xcontents = doc.FirstChildElement("contents");
if (xcontents != NULL) { if (xcontents != NULL) {
TiXmlElement *xpackage = xcontents->FirstChildElement("package"); TiXmlElement *xplugin = xcontents->FirstChildElement("plugin");
while (xpackage != NULL) { while (xplugin != NULL) {
const char *name = xpackage->Attribute("name"); const char *name = xplugin->Attribute("name");
if (name != NULL && strcmp(name, "coreapi") == 0) { 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) { if (xplatform != NULL && strcmp(xplatform, this_platform.c_str()) == 0) {
return get_core_api(contents_filename, download_url, this_platform, 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. // Couldn't find the coreapi plugin description.
cerr << "No coreapi package defined in contents file for " cerr << "No coreapi plugin defined in contents file for "
<< this_platform << "\n"; << this_platform << "\n";
return false; return false;
} }
@ -401,8 +401,8 @@ read_contents_file(Filename contents_filename, const string &download_url,
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool Panda3D:: bool Panda3D::
get_core_api(const Filename &contents_filename, const string &download_url, get_core_api(const Filename &contents_filename, const string &download_url,
const string &this_platform, TiXmlElement *xpackage) { const string &this_platform, TiXmlElement *xplugin) {
_core_api_dll.load_xml(xpackage); _core_api_dll.load_xml(xplugin);
if (!_core_api_dll.quick_verify(_root_dir)) { if (!_core_api_dll.quick_verify(_root_dir)) {
// The DLL file needs to be downloaded. Go get it. // The DLL file needs to be downloaded. Go get it.

View File

@ -49,7 +49,7 @@ private:
const string &this_platform); const string &this_platform);
bool get_core_api(const Filename &contents_filename, bool get_core_api(const Filename &contents_filename,
const string &download_url, const string &this_platform, const string &download_url, const string &this_platform,
TiXmlElement *xpackage); TiXmlElement *xplugin);
void run_getters(); void run_getters();
void handle_request(P3D_request *request); void handle_request(P3D_request *request);
void make_parent_window(P3D_window_handle &parent_window, void make_parent_window(P3D_window_handle &parent_window,

View File

@ -23,7 +23,12 @@ Options:
import sys import sys
import getopt import getopt
import os import os
import md5
try:
import hashlib
except ImportError:
# Legacy Python support
import md5 as hashlib
class ArgumentError(AttributeError): class ArgumentError(AttributeError):
pass pass
@ -40,7 +45,7 @@ class FileSpec:
self.size = s.st_size self.size = s.st_size
self.timestamp = int(s.st_mtime) self.timestamp = int(s.st_mtime)
m = md5.new() m = hashlib.md5()
m.update(open(pathname, 'rb').read()) m.update(open(pathname, 'rb').read())
self.hash = m.hexdigest() self.hash = m.hexdigest()
@ -70,9 +75,9 @@ class ContentsMaker:
print >> f, '<?xml version="1.0" ?>' print >> f, '<?xml version="1.0" ?>'
print >> f, '' print >> f, ''
print >> f, '<contents>' print >> f, '<contents>'
for packageName, packagePlatform, packageVersion, file in self.packages: for type, packageName, packagePlatform, packageVersion, file in self.packages:
print >> f, ' <package name="%s" platform="%s" version="%s" %s />' % ( print >> f, ' <%s name="%s" platform="%s" version="%s" %s />' % (
packageName, packagePlatform or '', packageVersion, file.getParams()) type, packageName, packagePlatform or '', packageVersion, file.getParams())
print >> f, '</contents>' print >> f, '</contents>'
f.close() f.close()
@ -93,12 +98,15 @@ class ContentsMaker:
localpath = dirpath[len(prefix):].replace(os.sep, '/') + '/' localpath = dirpath[len(prefix):].replace(os.sep, '/') + '/'
xml = dirpath[len(prefix):].replace(os.sep, '_') + '.xml' xml = dirpath[len(prefix):].replace(os.sep, '_') + '.xml'
type = 'package'
# A special case: the "plugin" and "coreapi" directories # A special case: the "plugin" and "coreapi" directories
# don't have xml files, just dll's. # don't have xml files, just dll's.
if xml.startswith('plugin_') or xml.startswith('coreapi_'): if xml.startswith('plugin_') or xml.startswith('coreapi_'):
if filenames: if filenames:
assert len(filenames) == 1 assert len(filenames) == 1
xml = filenames[0] xml = filenames[0]
type = 'plugin'
if xml not in filenames: if xml not in filenames:
continue continue
@ -106,17 +114,28 @@ class ContentsMaker:
if localpath.count('/') == 2: if localpath.count('/') == 2:
packageName, packageVersion, junk = localpath.split('/') packageName, packageVersion, junk = localpath.split('/')
packagePlatform = None 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('/') packageName, packagePlatform, packageVersion, junk = localpath.split('/')
else:
continue
file = FileSpec(localpath + xml, file = FileSpec(localpath + xml,
os.path.join(self.installDir, localpath + xml)) os.path.join(self.installDir, localpath + xml))
print file.filename print file.filename
self.packages.append((packageName, packagePlatform, packageVersion, file)) 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): def makeContents(args):

View File

@ -35,15 +35,6 @@ import os
import types import types
import __builtin__ 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): class ArgumentError(AttributeError):
pass pass
@ -76,6 +67,11 @@ class AppRunner(DirectObject):
# TODO: we need one of these per instance, not per session. # TODO: we need one of these per instance, not per session.
self.instanceId = None 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 # The attributes of this object will be exposed as attributes
# of the plugin instance in the DOM. # of the plugin instance in the DOM.
self.attributes = ScriptAttributes() self.attributes = ScriptAttributes()
@ -177,13 +173,10 @@ class AppRunner(DirectObject):
# Now set up Python to import this stuff. # Now set up Python to import this stuff.
VFSImporter.register() 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. # Put our root directory on the model-path, too.
getModelPath().prependDirectory(MultifileRoot) getModelPath().prependDirectory(self.multifileRoot)
# Load the implicit App.prc file.
loadPrcFileData(AppPrcFilename, AppPrc)
# Replace the builtin open and file symbols so user code will get # Replace the builtin open and file symbols so user code will get
# our versions by default, which can open and read files out of # our versions by default, which can open and read files out of
@ -196,7 +189,7 @@ class AppRunner(DirectObject):
if not self.fullDiskAccess: if not self.fullDiskAccess:
# Make "/mf" our "current directory", for running the multifiles # Make "/mf" our "current directory", for running the multifiles
# we plan to mount there. # we plan to mount there.
vfs.chdir(MultifileRoot) vfs.chdir(self.multifileRoot)
def startIfReady(self): def startIfReady(self):
if self.started: if self.started:
@ -223,7 +216,7 @@ class AppRunner(DirectObject):
if mainName: if mainName:
moduleName = mainName moduleName = mainName
root = MultifileRoot root = self.multifileRoot
if '.' in moduleName: if '.' in moduleName:
root += '/' + '/'.join(moduleName.split('.')[:-1]) root += '/' + '/'.join(moduleName.split('.')[:-1])
v = VFSImporter.VFSImporter(root) v = VFSImporter.VFSImporter(root)
@ -308,8 +301,8 @@ class AppRunner(DirectObject):
self.initPackedAppEnvironment() self.initPackedAppEnvironment()
# Mount the Multifile under /mf, by convention. # Mount the Multifile under /mf, by convention.
vfs.mount(mf, MultifileRoot, vfs.MFReadOnly) vfs.mount(mf, self.multifileRoot, vfs.MFReadOnly)
VFSImporter.freeze_new_modules(mf, MultifileRoot) VFSImporter.freeze_new_modules(mf, self.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
@ -319,7 +312,7 @@ class AppRunner(DirectObject):
for f in mf.getSubfileNames(): for f in mf.getSubfileNames():
fn = Filename(f) fn = Filename(f)
if fn.getDirname() == '' and fn.getExtension() == 'prc': if fn.getDirname() == '' and fn.getExtension() == 'prc':
pathname = '%s/%s' % (MultifileRoot, f) pathname = '%s/%s' % (self.multifileRoot, f)
data = open(pathname, 'r').read() data = open(pathname, 'r').read()
loadPrcFileData(pathname, data) loadPrcFileData(pathname, data)