Merge pull request #46 from eswartz/pr_packager_extensions

Handle packaging user filetypes more extensibly
This commit is contained in:
rdb 2015-07-28 15:28:47 +02:00
commit 29ccfc4103
2 changed files with 83 additions and 3 deletions

View File

@ -375,6 +375,9 @@ class Packager:
# This records the current list of modules we have added so # This records the current list of modules we have added so
# far. # far.
self.freezer = FreezeTool.Freezer(platform = self.packager.platform) self.freezer = FreezeTool.Freezer(platform = self.packager.platform)
# Map of extensions to files to number (ignored by dir)
self.ignoredDirFiles = {}
def close(self): def close(self):
""" Writes out the contents of the current package. Returns True """ 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' message = 'Cannot generate packages without an installDir; use -i'
raise PackagerError, message 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: if not self.host:
self.host = self.packager.host self.host = self.packager.host
@ -2185,6 +2195,9 @@ class Packager:
# ignoring any request to specify a particular download host, # ignoring any request to specify a particular download host,
# e.g. for testing and development. # e.g. for testing and development.
self.ignoreSetHost = False 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, # This will be appended to the basename of any .p3d package,
# before the .p3d extension. # before the .p3d extension.
@ -2390,6 +2403,14 @@ class Packager:
# should be added exactly byte-for-byte as they are. # should be added exactly byte-for-byte as they are.
self.unprocessedExtensions = [] 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 # System files that should never be packaged. For
# case-insensitive filesystems (like Windows and OSX), put the # case-insensitive filesystems (like Windows and OSX), put the
# lowercase filename here. Case-sensitive filesystems should # lowercase filename here. Case-sensitive filesystems should
@ -2617,12 +2638,20 @@ class Packager:
if dirname.makeTrueCase(): if dirname.makeTrueCase():
searchPath.appendDirectory(dirname) searchPath.appendDirectory(dirname)
def _ensureExtensions(self):
self.knownExtensions = \
self.imageExtensions + \
self.modelExtensions + \
self.textExtensions + \
self.binaryExtensions + \
self.uncompressibleExtensions + \
self.unprocessedExtensions
def setup(self): def setup(self):
""" Call this method to initialize the class after filling in """ Call this method to initialize the class after filling in
some of the values in the constructor. """ 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 self.currentPackage = None
@ -3604,6 +3633,43 @@ class Packager:
filename = Filename(filename) filename = Filename(filename)
self.currentPackage.excludeFile(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): def do_dir(self, dirname, newDir = None, unprocessed = None):
""" Adds the indicated directory hierarchy to the current """ Adds the indicated directory hierarchy to the current
@ -3676,7 +3742,12 @@ class Packager:
filename.setBinary() filename.setBinary()
self.currentPackage.addFile(filename, newName = newName, self.currentPackage.addFile(filename, newName = newName,
explicit = False, unprocessed = unprocessed) 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): def readContentsFile(self):
""" Reads the contents.xml file at the beginning of """ Reads the contents.xml file at the beginning of

View File

@ -123,6 +123,10 @@ Options:
as such. This only applies to .p3d packages, not to other types as such. This only applies to .p3d packages, not to other types
of packages! of packages!
-v
Emit a warning for any file not recognized by the dir() command
(indicating there may be a need for addExtensions(...)).
-h -h
Display this help Display this help
""" """
@ -151,11 +155,12 @@ allowPythonDev = False
universalBinaries = False universalBinaries = False
systemRoot = None systemRoot = None
ignoreSetHost = False ignoreSetHost = False
verbosePrint = False
p3dSuffix = '' p3dSuffix = ''
platforms = [] platforms = []
try: 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: except getopt.error, msg:
usage(1, msg) usage(1, msg)
@ -188,6 +193,9 @@ for opt, arg in opts:
elif opt == '-a': elif opt == '-a':
p3dSuffix = arg p3dSuffix = arg
elif opt == '-v':
verbosePrint = True
elif opt == '-h': elif opt == '-h':
usage(0) usage(0)
else: else:
@ -230,6 +238,7 @@ for platform in platforms:
packager.allowPythonDev = allowPythonDev packager.allowPythonDev = allowPythonDev
packager.systemRoot = systemRoot packager.systemRoot = systemRoot
packager.ignoreSetHost = ignoreSetHost packager.ignoreSetHost = ignoreSetHost
packager.verbosePrint = verbosePrint
packager.p3dSuffix = p3dSuffix packager.p3dSuffix = p3dSuffix
try: try: