From 353ae928d250bafac18ecc135f779e4d0132d2a5 Mon Sep 17 00:00:00 2001 From: Ed Swartz Date: Mon, 27 Jul 2015 13:51:21 -0500 Subject: [PATCH] Handle packaging user filetypes more extensibly -- Provide includeExtensions(...) method to augment particular kinds of files, allowing them to be packaged by dir() -- Track the count of files, by extension, silently ignored by dir(), and log this -- Allow "-v" option to verbosely log ignored files in dir() --- direct/src/p3d/Packager.py | 75 +++++++++++++++++++++++++++++++++++++- direct/src/p3d/ppackage.py | 11 +++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index 9614e96d59..d2166ec4f8 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -375,6 +375,9 @@ class Packager: # This records the current list of modules we have added so # far. self.freezer = FreezeTool.Freezer(platform = self.packager.platform) + + # Map of extensions to files to number (ignored by dir) + self.ignoredDirFiles = {} def close(self): """ Writes out the contents of the current package. Returns True @@ -385,6 +388,13 @@ class Packager: message = 'Cannot generate packages without an installDir; use -i' raise PackagerError, message + if self.ignoredDirFiles: + exts = list(self.ignoredDirFiles.keys()) + exts.sort() + total = sum([x for x in self.ignoredDirFiles.values()]) + self.notify.warning("excluded %s files not marked for inclusion: %s" \ + % (total, ", ".join(["'" + ext + "'" for ext in exts]))) + if not self.host: self.host = self.packager.host @@ -2185,6 +2195,9 @@ class Packager: # ignoring any request to specify a particular download host, # e.g. for testing and development. self.ignoreSetHost = False + + # Set this to true to verbosely log files ignored by dir(). + self.verbosePrint = False # This will be appended to the basename of any .p3d package, # before the .p3d extension. @@ -2390,6 +2403,14 @@ class Packager: # should be added exactly byte-for-byte as they are. self.unprocessedExtensions = [] + # Files for which warnings should be suppressed when they are + # not handled by dir() + self.suppressWarningForExtensions = ['', 'pyc', 'pyo', + 'p3d', 'pdef', + 'c', 'C', 'cxx', 'cpp', 'h', 'H', + 'hpp', 'pp', 'I', 'pem', 'p12', 'crt', + 'o', 'obj', 'a', 'lib', 'bc', 'll'] + # System files that should never be packaged. For # case-insensitive filesystems (like Windows and OSX), put the # lowercase filename here. Case-sensitive filesystems should @@ -2617,12 +2638,20 @@ class Packager: if dirname.makeTrueCase(): searchPath.appendDirectory(dirname) + def _ensureExtensions(self): + self.knownExtensions = \ + self.imageExtensions + \ + self.modelExtensions + \ + self.textExtensions + \ + self.binaryExtensions + \ + self.uncompressibleExtensions + \ + self.unprocessedExtensions def setup(self): """ Call this method to initialize the class after filling in some of the values in the constructor. """ - self.knownExtensions = self.imageExtensions + self.modelExtensions + self.textExtensions + self.binaryExtensions + self.uncompressibleExtensions + self.unprocessedExtensions + self._ensureExtensions() self.currentPackage = None @@ -3604,6 +3633,43 @@ class Packager: filename = Filename(filename) self.currentPackage.excludeFile(filename) + + def do_includeExtensions(self, executableExtensions = None, extractExtensions = None, + imageExtensions = None, textExtensions = None, + uncompressibleExtensions = None, unprocessedExtensions = None, + suppressWarningForExtensions = None): + """ Ensure that dir() will include files with the given extensions. + The extensions should not have '.' prefixes. + + All except 'suppressWarningForExtensions' allow the given kinds of files + to be packaged with their respective semantics (read the source). + + 'suppressWarningForExtensions' lists extensions *expected* to be ignored, + so no warnings will be emitted for them. + """ + if executableExtensions: + self.executableExtensions += executableExtensions + + if extractExtensions: + self.extractExtensions += extractExtensions + + if imageExtensions: + self.imageExtensions += imageExtensions + + if textExtensions: + self.textExtensions += textExtensions + + if uncompressibleExtensions: + self.uncompressibleExtensions += uncompressibleExtensions + + if unprocessedExtensions: + self.unprocessedExtensions += unprocessedExtensions + + if suppressWarningForExtensions: + self.suppressWarningForExtensions += suppressWarningForExtensions + + self._ensureExtensions() + def do_dir(self, dirname, newDir = None, unprocessed = None): """ Adds the indicated directory hierarchy to the current @@ -3676,7 +3742,12 @@ class Packager: filename.setBinary() self.currentPackage.addFile(filename, newName = newName, explicit = False, unprocessed = unprocessed) - + elif not ext in self.suppressWarningForExtensions: + newCount = self.currentPackage.ignoredDirFiles.get(ext, 0) + 1 + self.currentPackage.ignoredDirFiles[ext] = newCount + + if self.verbosePrint: + self.notify.warning("ignoring file %s" % filename) def readContentsFile(self): """ Reads the contents.xml file at the beginning of diff --git a/direct/src/p3d/ppackage.py b/direct/src/p3d/ppackage.py index 36be497a9f..dc00bdc567 100755 --- a/direct/src/p3d/ppackage.py +++ b/direct/src/p3d/ppackage.py @@ -123,6 +123,10 @@ Options: as such. This only applies to .p3d packages, not to other types of packages! + -v + Emit a warning for any file not recognized by the dir() command + (indicating there may be a need for addExtensions(...)). + -h Display this help """ @@ -151,11 +155,12 @@ allowPythonDev = False universalBinaries = False systemRoot = None ignoreSetHost = False +verbosePrint = False p3dSuffix = '' platforms = [] try: - opts, args = getopt.getopt(sys.argv[1:], 'i:ps:S:DuP:R:Ha:h') + opts, args = getopt.getopt(sys.argv[1:], 'i:ps:S:DuP:R:Ha:hv') except getopt.error, msg: usage(1, msg) @@ -188,6 +193,9 @@ for opt, arg in opts: elif opt == '-a': p3dSuffix = arg + elif opt == '-v': + verbosePrint = True + elif opt == '-h': usage(0) else: @@ -230,6 +238,7 @@ for platform in platforms: packager.allowPythonDev = allowPythonDev packager.systemRoot = systemRoot packager.ignoreSetHost = ignoreSetHost + packager.verbosePrint = verbosePrint packager.p3dSuffix = p3dSuffix try: