Browse Source

minor friendliness

David Rose 16 years ago
parent
commit
f94479e13b
3 changed files with 122 additions and 94 deletions
  1. 85 44
      direct/src/p3d/Packager.py
  2. 29 39
      direct/src/p3d/panda3d.pdef
  3. 8 11
      direct/src/showutil/FreezeTool.py

+ 85 - 44
direct/src/p3d/Packager.py

@@ -1792,9 +1792,9 @@ class Packager:
         for keyword, value in kw.items():
         for keyword, value in kw.items():
             self.currentPackage.configs[keyword] = value
             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
         Attempts to install this package will implicitly install the
         named package also.  Files already included in the named
         named package also.  Files already included in the named
@@ -1803,22 +1803,35 @@ class Packager:
         if not self.currentPackage:
         if not self.currentPackage:
             raise OutsideOfPackageError
             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)
+
+        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)
+            self.requirePackage(package)
 
 
     def requirePackage(self, package):
     def requirePackage(self, package):
         """ Indicates a dependency on the indicated package, supplied
         """ Indicates a dependency on the indicated package, supplied
@@ -1842,21 +1855,32 @@ class Packager:
 
 
         self.currentPackage.requirePackage(package)
         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:
         if not self.currentPackage:
             raise OutsideOfPackageError
             raise OutsideOfPackageError
 
 
         self.currentPackage.freezer.addModule(moduleName, newName = newName)
         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. """
         """ Marks the indicated Python module as not to be included. """
 
 
         if not self.currentPackage:
         if not self.currentPackage:
             raise OutsideOfPackageError
             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):
     def do_mainModule(self, moduleName, newName = None, filename = None):
         """ Names the indicated module as the "main" module of the
         """ Names the indicated module as the "main" module of the
@@ -1934,15 +1958,23 @@ class Packager:
         freezer.reset()
         freezer.reset()
         package.mainModule = None
         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,
                 extract = None, executable = None, deleteTemp = False,
                 literal = False):
                 literal = False):
-        """ Adds the indicated arbitrary file to the current package.
 
 
-        The file is placed in the named directory, or the toplevel
-        directory if no directory is specified.
+        """ Adds the indicated arbitrary files to the current package.
 
 
-        The filename may include shell globbing characters.
+        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.
 
 
         Certain special behavior is invoked based on the filename
         Certain special behavior is invoked based on the filename
         extension.  For instance, .py files may be automatically
         extension.  For instance, .py files may be automatically
@@ -1981,28 +2013,34 @@ class Packager:
         if not self.currentPackage:
         if not self.currentPackage:
             raise OutsideOfPackageError
             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
         newName = None
         prefix = ''
         prefix = ''
@@ -2017,8 +2055,11 @@ class Packager:
                     raise PackagerError, message
                     raise PackagerError, message
 
 
         if text:
         if text:
+            if len(files) != 1:
+                message = 'Cannot install text to multiple files'
+                raise PackagerError, message
             if not newName:
             if not newName:
-                newName = filename.cStr()
+                newName = str(filenames[0])
 
 
             tempFile = Filename.temporary('', self.currentPackage.packageName)
             tempFile = Filename.temporary('', self.currentPackage.packageName)
             temp = open(tempFile.toOsSpecific(), 'w')
             temp = open(tempFile.toOsSpecific(), 'w')

+ 29 - 39
direct/src/p3d/panda3d.pdef

@@ -14,7 +14,6 @@
 
 
 
 
 class panda3d(package):
 class panda3d(package):
-
     # The core Panda3D package.  Contains Python and most of the graphics
     # The core Panda3D package.  Contains Python and most of the graphics
     # code in Panda3D.
     # code in Panda3D.
 
 
@@ -26,26 +25,26 @@ class panda3d(package):
 
 
     # These are additional Python modules that are needed by most Panda3D
     # These are additional Python modules that are needed by most Panda3D
     # applications.  It doesn't matter too much if we miss one or two
     # 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
     # automatically be included as well, and we end up with a pretty
     # complete list that way.
     # 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
     # Exclude these GUI toolkits; they're big, and many applications don't
     # use them.  We define them as separate, optional packages, below.
     # 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
     # 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
     # 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,
     # that are also needed, but aren't referenced by any code.  Again,
     # note that the .dll extension is automatically replaced with the
     # note that the .dll extension is automatically replaced with the
     # platform-specific extension for an executable.
     # platform-specific extension for an executable.
-    file('libpandagl.dll')
+    file('libpandagl.dll', 'libtinydisplay.dll')
     if platform.startswith('win'):
     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
     # A basic config file is needed to lay some some fundamental runtime
     # variables.
     # variables.
@@ -97,7 +94,6 @@ default-model-extension .bam
 
 
 
 
 class egg(package):
 class egg(package):
-
     # This package contains the code for reading and operating on egg
     # This package contains the code for reading and operating on egg
     # files.  Since the Packager automatically converts egg files to bam
     # files.  Since the Packager automatically converts egg files to bam
     # files, this is not needed for most Panda3D applications.
     # files, this is not needed for most Panda3D applications.
@@ -116,47 +112,41 @@ class wx(package):
     config(display_name = "wxPython GUI Toolkit")
     config(display_name = "wxPython GUI Toolkit")
     require('panda3d')
     require('panda3d')
 
 
-    module('direct.showbase.WxGlobal')
-    module('wx')
-    module('wx.*')
+    module('direct.showbase.WxGlobal', 'wx', 'wx.*')
 
 
 
 
 class tk(package):
 class tk(package):
     config(display_name = "Tk GUI Toolkit")
     config(display_name = "Tk GUI Toolkit")
     require('panda3d')
     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):
 class packp3d(p3d):
-
     # This application is a command-line convenience for building a p3d
     # This application is a command-line convenience for building a p3d
     # application out of a directory hierarchy on disk.  We build it here
     # 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
     # into its own p3d application, to allow end-users to easily build p3d
     # applications using the appropriate version of Python and Panda for
     # applications using the appropriate version of Python and Panda for
     # the targeted runtime.
     # 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')
     mainModule('direct.p3d.packp3d')
 
 
 
 
 class ppackage(p3d):
 class ppackage(p3d):
-
     # As above, a packaging utility.  This is the fully-general ppackage
     # As above, a packaging utility.  This is the fully-general ppackage
     # utility, which reads pdef files (like this one!) and creates one or
     # utility, which reads pdef files (like this one!) and creates one or
     # more packages or p3d applications.
     # 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')
     mainModule('direct.p3d.ppackage')

+ 8 - 11
direct/src/showutil/FreezeTool.py

@@ -34,6 +34,9 @@ startupModules = [
     'org',
     'org',
     ]
     ]
 
 
+# These are missing modules that we've reported already this session.
+reportedMissing = {}
+
 # Our own Python source trees to watch out for.
 # Our own Python source trees to watch out for.
 sourceTrees = ['direct']
 sourceTrees = ['direct']
 
 
@@ -791,19 +794,13 @@ class Freezer:
                 continue
                 continue
 
 
             prefix = origName.split('.')[0]
             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:
         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):
     def __loadModule(self, mdef):
         """ Adds the indicated module to the modulefinder. """
         """ Adds the indicated module to the modulefinder. """