From f94479e13b98ff693ecba0c7c6840c6b42366f02 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 23 Aug 2009 23:21:48 +0000 Subject: [PATCH] minor friendliness --- direct/src/p3d/Packager.py | 129 ++++++++++++++++++++---------- direct/src/p3d/panda3d.pdef | 68 +++++++--------- direct/src/showutil/FreezeTool.py | 19 ++--- 3 files changed, 122 insertions(+), 94 deletions(-) diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index b46a94753d..af02509fe1 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -1792,9 +1792,9 @@ class Packager: for keyword, value in kw.items(): self.currentPackage.configs[keyword] = value - def do_require(self, packageName, version = None, host = None): - """ Indicates a dependency on the named package, supplied as - a name. + def do_require(self, *args, **kw): + """ Indicates a dependency on the named package(s), supplied + as a name. Attempts to install this package will implicitly install the named package also. Files already included in the named @@ -1803,22 +1803,35 @@ class Packager: if not self.currentPackage: raise OutsideOfPackageError - # A special case when requiring the "panda3d" package. We - # supply the version number what we've been compiled with as a - # default. - if packageName == 'panda3d': - if version is None: - version = PandaSystem.getPackageVersionString() - if host is None: - host = PandaSystem.getPackageHostUrl() - - package = self.findPackage(packageName, version = version, host = host, - requires = self.currentPackage.requires) - if not package: - message = 'Unknown package %s, version "%s"' % (packageName, version) - raise PackagerError, message + version = kw.get('version', None) + host = kw.get('host', None) - self.requirePackage(package) + for key in ['version', 'host']: + if key in kw: + del kw['version'] + if kw: + message = "do_require() got an unexpected keyword argument '%s'" % (kw.keys()[0]) + raise TypeError, message + + for packageName in args: + # A special case when requiring the "panda3d" package. We + # supply the version number what we've been compiled with as a + # default. + pversion = version + phost = host + if packageName == 'panda3d': + if pversion is None: + pversion = PandaSystem.getPackageVersionString() + if phost is None: + phost = PandaSystem.getPackageHostUrl() + + package = self.findPackage(packageName, version = pversion, host = phost, + requires = self.currentPackage.requires) + if not package: + message = 'Unknown package %s, version "%s"' % (packageName, version) + raise PackagerError, message + + self.requirePackage(package) def requirePackage(self, package): """ Indicates a dependency on the indicated package, supplied @@ -1842,21 +1855,32 @@ class Packager: self.currentPackage.requirePackage(package) - def do_module(self, moduleName, newName = None): - """ Adds the indicated Python module to the current package. """ + def do_module(self, *args): + """ Adds the indicated Python module(s) to the current package. """ + + if not self.currentPackage: + raise OutsideOfPackageError + + for moduleName in args: + self.currentPackage.freezer.addModule(moduleName) + + def do_renameModule(self, moduleName, newName): + """ Adds the indicated Python module to the current package, + renaming to a new name. """ if not self.currentPackage: raise OutsideOfPackageError self.currentPackage.freezer.addModule(moduleName, newName = newName) - def do_excludeModule(self, moduleName, forbid = False): + def do_excludeModule(self, *args): """ Marks the indicated Python module as not to be included. """ if not self.currentPackage: raise OutsideOfPackageError - self.currentPackage.freezer.excludeModule(moduleName, forbid = forbid) + for moduleName in args: + self.currentPackage.freezer.excludeModule(moduleName) def do_mainModule(self, moduleName, newName = None, filename = None): """ Names the indicated module as the "main" module of the @@ -1934,16 +1958,24 @@ class Packager: freezer.reset() package.mainModule = None - def do_file(self, filename, text = None, newNameOrDir = None, + def do_file(self, *args, **kw): + """ Adds the indicated file or files to the current package. + See addFiles(). """ + + self.addFiles(args, **kw) + + def addFiles(self, filenames, text = None, newNameOrDir = None, extract = None, executable = None, deleteTemp = False, literal = False): - """ Adds the indicated arbitrary file to the current package. - The file is placed in the named directory, or the toplevel + """ Adds the indicated arbitrary files to the current package. + + filenames is a list of Filename or string objects, and each + may include shell globbing characters. + + Each file is placed in the named directory, or the toplevel directory if no directory is specified. - The filename may include shell globbing characters. - Certain special behavior is invoked based on the filename extension. For instance, .py files may be automatically compiled and stored as Python modules. @@ -1981,28 +2013,34 @@ class Packager: if not self.currentPackage: raise OutsideOfPackageError - filename = Filename(filename) + files = [] + explicit = True + + for filename in filenames: + filename = Filename(filename) - if literal: - files = [filename.toOsSpecific()] + if literal: + thisFiles = [filename.toOsSpecific()] - else: - ext = filename.getExtension() + else: + ext = filename.getExtension() - # A special case, since OSX and Linux don't have a - # standard extension for program files. - if executable is None and ext == 'exe': - executable = True + # A special case, since OSX and Linux don't have a + # standard extension for program files. + if executable is None and ext == 'exe': + executable = True - newExt = self.remapExtensions.get(ext, None) - if newExt is not None: - filename.setExtension(newExt) + newExt = self.remapExtensions.get(ext, None) + if newExt is not None: + filename.setExtension(newExt) - files = glob.glob(filename.toOsSpecific()) - if not files: - files = [filename.toOsSpecific()] + thisFiles = glob.glob(filename.toOsSpecific()) + if not thisFiles: + thisFiles = [filename.toOsSpecific()] - explicit = (len(files) == 1) + if len(thisFiles) > 1: + explicit = False + files += thisFiles newName = None prefix = '' @@ -2017,8 +2055,11 @@ class Packager: raise PackagerError, message if text: + if len(files) != 1: + message = 'Cannot install text to multiple files' + raise PackagerError, message if not newName: - newName = filename.cStr() + newName = str(filenames[0]) tempFile = Filename.temporary('', self.currentPackage.packageName) temp = open(tempFile.toOsSpecific(), 'w') diff --git a/direct/src/p3d/panda3d.pdef b/direct/src/p3d/panda3d.pdef index ecc933adf2..38e7e58dfc 100755 --- a/direct/src/p3d/panda3d.pdef +++ b/direct/src/p3d/panda3d.pdef @@ -14,7 +14,6 @@ class panda3d(package): - # The core Panda3D package. Contains Python and most of the graphics # code in Panda3D. @@ -26,26 +25,26 @@ class panda3d(package): # These are additional Python modules that are needed by most Panda3D # applications. It doesn't matter too much if we miss one or two - # here, since any module('imported by any of this code will') + # here, since any module imported by any of this code will # automatically be included as well, and we end up with a pretty # complete list that way. - module('direct.directbase.DirectStart') - module('direct.showbase.*') - module('direct.actor.Actor') - module('direct.fsm.FSM') - module('direct.interval.IntervalGlobal') - module('direct.particles.ParticleEffect') - module('direct.directutil.Mopath') + module('direct.directbase.DirectStart', + 'direct.showbase.*', + 'direct.actor.Actor', + 'direct.fsm.FSM', + 'direct.interval.IntervalGlobal', + 'direct.particles.ParticleEffect', + 'direct.directutil.Mopath') # Exclude these GUI toolkits; they're big, and many applications don't # use them. We define them as separate, optional packages, below. - excludeModule('wx') - excludeModule('direct.showbase.WxGlobal') + excludeModule('wx', + 'direct.showbase.WxGlobal') - excludeModule('Tkinter') - excludeModule('direct.showbase.TkGlobal') - excludeModule('direct.tkpanels') - excludeModule('direct.tkwidgets') + excludeModule('Tkinter', + 'direct.showbase.TkGlobal', + 'direct.tkpanels', + 'direct.tkwidgets') # Bind all of the above Python code into a frozen DLL. This makes the # Python code available when the DLL is imported. It is actually @@ -69,11 +68,9 @@ class panda3d(package): # that are also needed, but aren't referenced by any code. Again, # note that the .dll extension is automatically replaced with the # platform-specific extension for an executable. - file('libpandagl.dll') + file('libpandagl.dll', 'libtinydisplay.dll') if platform.startswith('win'): - file('libpandadx8.dll') - file('libpandadx9.dll') - file('libtinydisplay.dll') + file('libpandadx8.dll', 'libpandadx9.dll') # A basic config file is needed to lay some some fundamental runtime # variables. @@ -97,7 +94,6 @@ default-model-extension .bam class egg(package): - # This package contains the code for reading and operating on egg # files. Since the Packager automatically converts egg files to bam # files, this is not needed for most Panda3D applications. @@ -116,47 +112,41 @@ class wx(package): config(display_name = "wxPython GUI Toolkit") require('panda3d') - module('direct.showbase.WxGlobal') - module('wx') - module('wx.*') + module('direct.showbase.WxGlobal', 'wx', 'wx.*') class tk(package): config(display_name = "Tk GUI Toolkit") require('panda3d') - module('Tkinter') - module('direct.showbase.TkGlobal') - module('direct.tkpanels') - module('direct.tkwidgets') + module('Tkinter', + 'direct.showbase.TkGlobal', + 'direct.tkpanels', + 'direct.tkwidgets') class packp3d(p3d): - # This application is a command-line convenience for building a p3d # application out of a directory hierarchy on disk. We build it here # into its own p3d application, to allow end-users to easily build p3d # applications using the appropriate version of Python and Panda for # the targeted runtime. - config(display_name = "Panda3D Application Packer") - config(full_disk_access = True) - config(hidden = True) - require('panda3d') - require('egg') + config(display_name = "Panda3D Application Packer", + full_disk_access = True, + hidden = True) + require('panda3d', 'egg') mainModule('direct.p3d.packp3d') class ppackage(p3d): - # As above, a packaging utility. This is the fully-general ppackage # utility, which reads pdef files (like this one!) and creates one or # more packages or p3d applications. - config(display_name = "Panda3D General Package Utility") - config(full_disk_access = True) - config(hidden = True) - require('panda3d') - require('egg') + config(display_name = "Panda3D General Package Utility", + full_disk_access = True, + hidden = True) + require('panda3d', 'egg') mainModule('direct.p3d.ppackage') diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index 241079e82b..92aed1ef44 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -34,6 +34,9 @@ startupModules = [ 'org', ] +# These are missing modules that we've reported already this session. +reportedMissing = {} + # Our own Python source trees to watch out for. sourceTrees = ['direct'] @@ -791,19 +794,13 @@ class Freezer: continue prefix = origName.split('.')[0] - if prefix not in sourceTrees: - # If it's in not one of our standard source trees, assume - # it's some wacky system file we don't need. - print "ignoring missing %s" % (origName) - continue - - missing.append(origName) + if origName not in reportedMissing: + missing.append(origName) + reportedMissing[origName] = True if missing: - error = "There are some missing modules: %r" % missing - print error - print "previous = %s" % (self.previousModules,) - raise StandardError, error + missing.sort() + print "There are some missing modules: %r" % missing def __loadModule(self, mdef): """ Adds the indicated module to the modulefinder. """