Import Upstream version 2.7.18
This commit is contained in:
BIN
Mac/scripts/BuildApplet.icns
Normal file
BIN
Mac/scripts/BuildApplet.icns
Normal file
Binary file not shown.
55
Mac/scripts/BuildApplet.plist
Normal file
55
Mac/scripts/BuildApplet.plist
Normal file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>py</string>
|
||||
</array>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>PythonSource.icns</string>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>Python Module</string>
|
||||
<key>CFBundleTypeOSTypes</key>
|
||||
<array>
|
||||
<string>TEXT</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Viewer</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>BuildApplet</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>2.5alpha0, (c) 2004 Python Software Foundation.</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>BuildApplet.icns</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.python.buildapplet</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>2.5alpha0, (c) 2004 Python Software Foundation.</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>PythonIDE</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.5alpha0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>Pide</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2.5alpha0</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>LSRequiresCarbon</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>(c) 2004 Python Software Foundation.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
156
Mac/scripts/BuildApplet.py
Normal file
156
Mac/scripts/BuildApplet.py
Normal file
@@ -0,0 +1,156 @@
|
||||
"""Create an applet from a Python script.
|
||||
|
||||
This puts up a dialog asking for a Python source file ('TEXT').
|
||||
The output is a file with the same name but its ".py" suffix dropped.
|
||||
It is created by copying an applet template and then adding a 'PYC '
|
||||
resource named __main__ containing the compiled, marshalled script.
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
sys.stdout = sys.stderr
|
||||
|
||||
import os
|
||||
import MacOS
|
||||
try:
|
||||
import EasyDialogs
|
||||
except ImportError:
|
||||
EasyDialogs = None
|
||||
import buildtools
|
||||
import getopt
|
||||
|
||||
if not sys.executable.startswith(sys.exec_prefix):
|
||||
# Oh, the joys of using a python script to bootstrap applicatin bundles
|
||||
# sys.executable points inside the current application bundle. Because this
|
||||
# path contains blanks (two of them actually) this path isn't usable on
|
||||
# #! lines. Reset sys.executable to point to the embedded python interpreter
|
||||
sys.executable = os.path.join(sys.prefix,
|
||||
'Resources/Python.app/Contents/MacOS/Python')
|
||||
|
||||
# Just in case we're not in a framework:
|
||||
if not os.path.exists(sys.executable):
|
||||
sys.executable = os.path.join(sys.exec_prefix, 'bin/python')
|
||||
|
||||
def main():
|
||||
try:
|
||||
buildapplet()
|
||||
except buildtools.BuildError, detail:
|
||||
if EasyDialogs is None:
|
||||
print detail
|
||||
else:
|
||||
EasyDialogs.Message(detail)
|
||||
|
||||
|
||||
def buildapplet():
|
||||
buildtools.DEBUG=1
|
||||
|
||||
# Find the template
|
||||
# (there's no point in proceeding if we can't find it)
|
||||
|
||||
template = buildtools.findtemplate()
|
||||
|
||||
# Ask for source text if not specified in sys.argv[1:]
|
||||
|
||||
if not sys.argv[1:]:
|
||||
if EasyDialogs is None:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
filename = EasyDialogs.AskFileForOpen(message='Select Python source or applet:',
|
||||
typeList=('TEXT', 'APPL'))
|
||||
if not filename:
|
||||
return
|
||||
tp, tf = os.path.split(filename)
|
||||
if tf[-3:] == '.py':
|
||||
tf = tf[:-3]
|
||||
else:
|
||||
tf = tf + '.applet'
|
||||
dstfilename = EasyDialogs.AskFileForSave(message='Save application as:',
|
||||
savedFileName=tf)
|
||||
if not dstfilename: return
|
||||
cr, tp = MacOS.GetCreatorAndType(filename)
|
||||
if tp == 'APPL':
|
||||
buildtools.update(template, filename, dstfilename)
|
||||
else:
|
||||
buildtools.process(template, filename, dstfilename, 1)
|
||||
else:
|
||||
|
||||
SHORTOPTS = "o:r:ne:v?PR"
|
||||
LONGOPTS=("output=", "resource=", "noargv", "extra=", "verbose", "help", "python=", "destroot=")
|
||||
try:
|
||||
options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
|
||||
except getopt.error:
|
||||
usage()
|
||||
if options and len(args) > 1:
|
||||
sys.stderr.write("Cannot use options when specifying multiple input files")
|
||||
sys.exit(1)
|
||||
dstfilename = None
|
||||
rsrcfilename = None
|
||||
raw = 0
|
||||
extras = []
|
||||
verbose = None
|
||||
destroot = ''
|
||||
for opt, arg in options:
|
||||
if opt in ('-o', '--output'):
|
||||
dstfilename = arg
|
||||
elif opt in ('-r', '--resource'):
|
||||
rsrcfilename = arg
|
||||
elif opt in ('-n', '--noargv'):
|
||||
raw = 1
|
||||
elif opt in ('-e', '--extra'):
|
||||
if ':' in arg:
|
||||
arg = arg.split(':')
|
||||
extras.append(arg)
|
||||
elif opt in ('-P', '--python'):
|
||||
# This is a very dirty trick. We set sys.executable
|
||||
# so that bundlebuilder will use this in the #! line
|
||||
# for the applet bootstrap.
|
||||
sys.executable = arg
|
||||
elif opt in ('-v', '--verbose'):
|
||||
verbose = Verbose()
|
||||
elif opt in ('-?', '--help'):
|
||||
usage()
|
||||
elif opt in ('-d', '--destroot'):
|
||||
destroot = arg
|
||||
# Loop over all files to be processed
|
||||
for filename in args:
|
||||
cr, tp = MacOS.GetCreatorAndType(filename)
|
||||
if tp == 'APPL':
|
||||
buildtools.update(template, filename, dstfilename)
|
||||
else:
|
||||
buildtools.process(template, filename, dstfilename, 1,
|
||||
rsrcname=rsrcfilename, others=extras, raw=raw,
|
||||
progress=verbose, destroot=destroot)
|
||||
|
||||
def usage():
|
||||
print "BuildApplet creates an application from a Python source file"
|
||||
print "Usage:"
|
||||
print " BuildApplet interactive, single file, no options"
|
||||
print " BuildApplet src1.py src2.py ... non-interactive multiple file"
|
||||
print " BuildApplet [options] src.py non-interactive single file"
|
||||
print "Options:"
|
||||
print " --output o Output file; default based on source filename, short -o"
|
||||
print " --resource r Resource file; default based on source filename, short -r"
|
||||
print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only"
|
||||
print " --extra src[:dst] Extra file to put in .app bundle, short -e, OSX only"
|
||||
print " --verbose Verbose, short -v"
|
||||
print " --help This message, short -?"
|
||||
sys.exit(1)
|
||||
|
||||
class Verbose:
|
||||
"""This class mimics EasyDialogs.ProgressBar but prints to stderr"""
|
||||
def __init__(self, *args):
|
||||
if args and args[0]:
|
||||
self.label(args[0])
|
||||
|
||||
def set(self, *args):
|
||||
pass
|
||||
|
||||
def inc(self, *args):
|
||||
pass
|
||||
|
||||
def label(self, str):
|
||||
sys.stderr.write(str+'\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
BIN
Mac/scripts/BuildApplet.rsrc
Normal file
BIN
Mac/scripts/BuildApplet.rsrc
Normal file
Binary file not shown.
56
Mac/scripts/bgenall.py
Normal file
56
Mac/scripts/bgenall.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# bgenall - Generate all bgen-generated modules
|
||||
#
|
||||
import sys
|
||||
import os
|
||||
import string
|
||||
|
||||
def bgenone(dirname, shortname):
|
||||
os.chdir(dirname)
|
||||
print '%s:'%shortname
|
||||
# Sigh, we don't want to lose CVS history, so two
|
||||
# modules have funny names:
|
||||
if shortname == 'carbonevt':
|
||||
modulename = 'CarbonEvtscan'
|
||||
elif shortname == 'ibcarbon':
|
||||
modulename = 'IBCarbonscan'
|
||||
else:
|
||||
modulename = shortname + 'scan'
|
||||
try:
|
||||
m = __import__(modulename)
|
||||
except:
|
||||
print "Error:", shortname, sys.exc_info()[1]
|
||||
return 0
|
||||
try:
|
||||
m.main()
|
||||
except:
|
||||
print "Error:", shortname, sys.exc_info()[1]
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def main():
|
||||
success = []
|
||||
failure = []
|
||||
sys.path.insert(0, os.curdir)
|
||||
if len(sys.argv) > 1:
|
||||
srcdir = sys.argv[1]
|
||||
else:
|
||||
srcdir = os.path.join(os.path.join(sys.prefix, 'Mac'), 'Modules')
|
||||
srcdir = os.path.abspath(srcdir)
|
||||
contents = os.listdir(srcdir)
|
||||
for name in contents:
|
||||
moduledir = os.path.join(srcdir, name)
|
||||
scanmodule = os.path.join(moduledir, name +'scan.py')
|
||||
if os.path.exists(scanmodule):
|
||||
if bgenone(moduledir, name):
|
||||
success.append(name)
|
||||
else:
|
||||
failure.append(name)
|
||||
print 'Done:', string.join(success, ' ')
|
||||
if failure:
|
||||
print 'Failed:', string.join(failure, ' ')
|
||||
return 0
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
rv = main()
|
||||
sys.exit(not rv)
|
||||
484
Mac/scripts/buildpkg.py
Executable file
484
Mac/scripts/buildpkg.py
Executable file
@@ -0,0 +1,484 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""buildpkg.py -- Build OS X packages for Apple's Installer.app.
|
||||
|
||||
This is an experimental command-line tool for building packages to be
|
||||
installed with the Mac OS X Installer.app application.
|
||||
|
||||
It is much inspired by Apple's GUI tool called PackageMaker.app, that
|
||||
seems to be part of the OS X developer tools installed in the folder
|
||||
/Developer/Applications. But apparently there are other free tools to
|
||||
do the same thing which are also named PackageMaker like Brian Hill's
|
||||
one:
|
||||
|
||||
http://personalpages.tds.net/~brian_hill/packagemaker.html
|
||||
|
||||
Beware of the multi-package features of Installer.app (which are not
|
||||
yet supported here) that can potentially screw-up your installation
|
||||
and are discussed in these articles on Stepwise:
|
||||
|
||||
http://www.stepwise.com/Articles/Technical/Packages/InstallerWoes.html
|
||||
http://www.stepwise.com/Articles/Technical/Packages/InstallerOnX.html
|
||||
|
||||
Beside using the PackageMaker class directly, by importing it inside
|
||||
another module, say, there are additional ways of using this module:
|
||||
the top-level buildPackage() function provides a shortcut to the same
|
||||
feature and is also called when using this module from the command-
|
||||
line.
|
||||
|
||||
****************************************************************
|
||||
NOTE: For now you should be able to run this even on a non-OS X
|
||||
system and get something similar to a package, but without
|
||||
the real archive (needs pax) and bom files (needs mkbom)
|
||||
inside! This is only for providing a chance for testing to
|
||||
folks without OS X.
|
||||
****************************************************************
|
||||
|
||||
TODO:
|
||||
- test pre-process and post-process scripts (Python ones?)
|
||||
- handle multi-volume packages (?)
|
||||
- integrate into distutils (?)
|
||||
|
||||
Dinu C. Gherman,
|
||||
gherman@europemail.com
|
||||
November 2001
|
||||
|
||||
!! USE AT YOUR OWN RISK !!
|
||||
"""
|
||||
|
||||
__version__ = 0.2
|
||||
__license__ = "FreeBSD"
|
||||
|
||||
|
||||
import os, sys, glob, fnmatch, shutil, string, copy, getopt
|
||||
from os.path import basename, dirname, join, islink, isdir, isfile
|
||||
|
||||
Error = "buildpkg.Error"
|
||||
|
||||
PKG_INFO_FIELDS = """\
|
||||
Title
|
||||
Version
|
||||
Description
|
||||
DefaultLocation
|
||||
DeleteWarning
|
||||
NeedsAuthorization
|
||||
DisableStop
|
||||
UseUserMask
|
||||
Application
|
||||
Relocatable
|
||||
Required
|
||||
InstallOnly
|
||||
RequiresReboot
|
||||
RootVolumeOnly
|
||||
LongFilenames
|
||||
LibrarySubdirectory
|
||||
AllowBackRev
|
||||
OverwritePermissions
|
||||
InstallFat\
|
||||
"""
|
||||
|
||||
######################################################################
|
||||
# Helpers
|
||||
######################################################################
|
||||
|
||||
# Convenience class, as suggested by /F.
|
||||
|
||||
class GlobDirectoryWalker:
|
||||
"A forward iterator that traverses files in a directory tree."
|
||||
|
||||
def __init__(self, directory, pattern="*"):
|
||||
self.stack = [directory]
|
||||
self.pattern = pattern
|
||||
self.files = []
|
||||
self.index = 0
|
||||
|
||||
|
||||
def __getitem__(self, index):
|
||||
while 1:
|
||||
try:
|
||||
file = self.files[self.index]
|
||||
self.index = self.index + 1
|
||||
except IndexError:
|
||||
# pop next directory from stack
|
||||
self.directory = self.stack.pop()
|
||||
self.files = os.listdir(self.directory)
|
||||
self.index = 0
|
||||
else:
|
||||
# got a filename
|
||||
fullname = join(self.directory, file)
|
||||
if isdir(fullname) and not islink(fullname):
|
||||
self.stack.append(fullname)
|
||||
if fnmatch.fnmatch(file, self.pattern):
|
||||
return fullname
|
||||
|
||||
|
||||
######################################################################
|
||||
# The real thing
|
||||
######################################################################
|
||||
|
||||
class PackageMaker:
|
||||
"""A class to generate packages for Mac OS X.
|
||||
|
||||
This is intended to create OS X packages (with extension .pkg)
|
||||
containing archives of arbitrary files that the Installer.app
|
||||
will be able to handle.
|
||||
|
||||
As of now, PackageMaker instances need to be created with the
|
||||
title, version and description of the package to be built.
|
||||
The package is built after calling the instance method
|
||||
build(root, **options). It has the same name as the constructor's
|
||||
title argument plus a '.pkg' extension and is located in the same
|
||||
parent folder that contains the root folder.
|
||||
|
||||
E.g. this will create a package folder /my/space/distutils.pkg/:
|
||||
|
||||
pm = PackageMaker("distutils", "1.0.2", "Python distutils.")
|
||||
pm.build("/my/space/distutils")
|
||||
"""
|
||||
|
||||
packageInfoDefaults = {
|
||||
'Title': None,
|
||||
'Version': None,
|
||||
'Description': '',
|
||||
'DefaultLocation': '/',
|
||||
'DeleteWarning': '',
|
||||
'NeedsAuthorization': 'NO',
|
||||
'DisableStop': 'NO',
|
||||
'UseUserMask': 'YES',
|
||||
'Application': 'NO',
|
||||
'Relocatable': 'YES',
|
||||
'Required': 'NO',
|
||||
'InstallOnly': 'NO',
|
||||
'RequiresReboot': 'NO',
|
||||
'RootVolumeOnly' : 'NO',
|
||||
'InstallFat': 'NO',
|
||||
'LongFilenames': 'YES',
|
||||
'LibrarySubdirectory': 'Standard',
|
||||
'AllowBackRev': 'YES',
|
||||
'OverwritePermissions': 'NO',
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, title, version, desc):
|
||||
"Init. with mandatory title/version/description arguments."
|
||||
|
||||
info = {"Title": title, "Version": version, "Description": desc}
|
||||
self.packageInfo = copy.deepcopy(self.packageInfoDefaults)
|
||||
self.packageInfo.update(info)
|
||||
|
||||
# variables set later
|
||||
self.packageRootFolder = None
|
||||
self.packageResourceFolder = None
|
||||
self.sourceFolder = None
|
||||
self.resourceFolder = None
|
||||
|
||||
|
||||
def build(self, root, resources=None, **options):
|
||||
"""Create a package for some given root folder.
|
||||
|
||||
With no 'resources' argument set it is assumed to be the same
|
||||
as the root directory. Option items replace the default ones
|
||||
in the package info.
|
||||
"""
|
||||
|
||||
# set folder attributes
|
||||
self.sourceFolder = root
|
||||
if resources is None:
|
||||
self.resourceFolder = root
|
||||
else:
|
||||
self.resourceFolder = resources
|
||||
|
||||
# replace default option settings with user ones if provided
|
||||
fields = self. packageInfoDefaults.keys()
|
||||
for k, v in options.items():
|
||||
if k in fields:
|
||||
self.packageInfo[k] = v
|
||||
elif not k in ["OutputDir"]:
|
||||
raise Error, "Unknown package option: %s" % k
|
||||
|
||||
# Check where we should leave the output. Default is current directory
|
||||
outputdir = options.get("OutputDir", os.getcwd())
|
||||
packageName = self.packageInfo["Title"]
|
||||
self.PackageRootFolder = os.path.join(outputdir, packageName + ".pkg")
|
||||
|
||||
# do what needs to be done
|
||||
self._makeFolders()
|
||||
self._addInfo()
|
||||
self._addBom()
|
||||
self._addArchive()
|
||||
self._addResources()
|
||||
self._addSizes()
|
||||
self._addLoc()
|
||||
|
||||
|
||||
def _makeFolders(self):
|
||||
"Create package folder structure."
|
||||
|
||||
# Not sure if the package name should contain the version or not...
|
||||
# packageName = "%s-%s" % (self.packageInfo["Title"],
|
||||
# self.packageInfo["Version"]) # ??
|
||||
|
||||
contFolder = join(self.PackageRootFolder, "Contents")
|
||||
self.packageResourceFolder = join(contFolder, "Resources")
|
||||
os.mkdir(self.PackageRootFolder)
|
||||
os.mkdir(contFolder)
|
||||
os.mkdir(self.packageResourceFolder)
|
||||
|
||||
def _addInfo(self):
|
||||
"Write .info file containing installing options."
|
||||
|
||||
# Not sure if options in PKG_INFO_FIELDS are complete...
|
||||
|
||||
info = ""
|
||||
for f in string.split(PKG_INFO_FIELDS, "\n"):
|
||||
if self.packageInfo.has_key(f):
|
||||
info = info + "%s %%(%s)s\n" % (f, f)
|
||||
info = info % self.packageInfo
|
||||
base = self.packageInfo["Title"] + ".info"
|
||||
path = join(self.packageResourceFolder, base)
|
||||
f = open(path, "w")
|
||||
f.write(info)
|
||||
|
||||
|
||||
def _addBom(self):
|
||||
"Write .bom file containing 'Bill of Materials'."
|
||||
|
||||
# Currently ignores if the 'mkbom' tool is not available.
|
||||
|
||||
try:
|
||||
base = self.packageInfo["Title"] + ".bom"
|
||||
bomPath = join(self.packageResourceFolder, base)
|
||||
cmd = "mkbom %s %s" % (self.sourceFolder, bomPath)
|
||||
res = os.system(cmd)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def _addArchive(self):
|
||||
"Write .pax.gz file, a compressed archive using pax/gzip."
|
||||
|
||||
# Currently ignores if the 'pax' tool is not available.
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
# create archive
|
||||
os.chdir(self.sourceFolder)
|
||||
base = basename(self.packageInfo["Title"]) + ".pax"
|
||||
self.archPath = join(self.packageResourceFolder, base)
|
||||
cmd = "pax -w -f %s %s" % (self.archPath, ".")
|
||||
res = os.system(cmd)
|
||||
|
||||
# compress archive
|
||||
cmd = "gzip %s" % self.archPath
|
||||
res = os.system(cmd)
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def _addResources(self):
|
||||
"Add Welcome/ReadMe/License files, .lproj folders and scripts."
|
||||
|
||||
# Currently we just copy everything that matches the allowed
|
||||
# filenames. So, it's left to Installer.app to deal with the
|
||||
# same file available in multiple formats...
|
||||
|
||||
if not self.resourceFolder:
|
||||
return
|
||||
|
||||
# find candidate resource files (txt html rtf rtfd/ or lproj/)
|
||||
allFiles = []
|
||||
for pat in string.split("*.txt *.html *.rtf *.rtfd *.lproj", " "):
|
||||
pattern = join(self.resourceFolder, pat)
|
||||
allFiles = allFiles + glob.glob(pattern)
|
||||
|
||||
# find pre-process and post-process scripts
|
||||
# naming convention: packageName.{pre,post}_{upgrade,install}
|
||||
# Alternatively the filenames can be {pre,post}_{upgrade,install}
|
||||
# in which case we prepend the package name
|
||||
packageName = self.packageInfo["Title"]
|
||||
for pat in ("*upgrade", "*install", "*flight"):
|
||||
pattern = join(self.resourceFolder, packageName + pat)
|
||||
pattern2 = join(self.resourceFolder, pat)
|
||||
allFiles = allFiles + glob.glob(pattern)
|
||||
allFiles = allFiles + glob.glob(pattern2)
|
||||
|
||||
# check name patterns
|
||||
files = []
|
||||
for f in allFiles:
|
||||
for s in ("Welcome", "License", "ReadMe"):
|
||||
if string.find(basename(f), s) == 0:
|
||||
files.append((f, f))
|
||||
if f[-6:] == ".lproj":
|
||||
files.append((f, f))
|
||||
elif basename(f) in ["pre_upgrade", "pre_install", "post_upgrade", "post_install"]:
|
||||
files.append((f, packageName+"."+basename(f)))
|
||||
elif basename(f) in ["preflight", "postflight"]:
|
||||
files.append((f, f))
|
||||
elif f[-8:] == "_upgrade":
|
||||
files.append((f,f))
|
||||
elif f[-8:] == "_install":
|
||||
files.append((f,f))
|
||||
|
||||
# copy files
|
||||
for src, dst in files:
|
||||
src = basename(src)
|
||||
dst = basename(dst)
|
||||
f = join(self.resourceFolder, src)
|
||||
if isfile(f):
|
||||
shutil.copy(f, os.path.join(self.packageResourceFolder, dst))
|
||||
elif isdir(f):
|
||||
# special case for .rtfd and .lproj folders...
|
||||
d = join(self.packageResourceFolder, dst)
|
||||
os.mkdir(d)
|
||||
files = GlobDirectoryWalker(f)
|
||||
for file in files:
|
||||
shutil.copy(file, d)
|
||||
|
||||
|
||||
def _addSizes(self):
|
||||
"Write .sizes file with info about number and size of files."
|
||||
|
||||
# Not sure if this is correct, but 'installedSize' and
|
||||
# 'zippedSize' are now in Bytes. Maybe blocks are needed?
|
||||
# Well, Installer.app doesn't seem to care anyway, saying
|
||||
# the installation needs 100+ MB...
|
||||
|
||||
numFiles = 0
|
||||
installedSize = 0
|
||||
zippedSize = 0
|
||||
|
||||
files = GlobDirectoryWalker(self.sourceFolder)
|
||||
for f in files:
|
||||
numFiles = numFiles + 1
|
||||
installedSize = installedSize + os.lstat(f)[6]
|
||||
|
||||
try:
|
||||
zippedSize = os.stat(self.archPath+ ".gz")[6]
|
||||
except OSError: # ignore error
|
||||
pass
|
||||
base = self.packageInfo["Title"] + ".sizes"
|
||||
f = open(join(self.packageResourceFolder, base), "w")
|
||||
format = "NumFiles %d\nInstalledSize %d\nCompressedSize %d\n"
|
||||
f.write(format % (numFiles, installedSize, zippedSize))
|
||||
|
||||
def _addLoc(self):
|
||||
"Write .loc file."
|
||||
base = self.packageInfo["Title"] + ".loc"
|
||||
f = open(join(self.packageResourceFolder, base), "w")
|
||||
f.write('/')
|
||||
|
||||
# Shortcut function interface
|
||||
|
||||
def buildPackage(*args, **options):
|
||||
"A Shortcut function for building a package."
|
||||
|
||||
o = options
|
||||
title, version, desc = o["Title"], o["Version"], o["Description"]
|
||||
pm = PackageMaker(title, version, desc)
|
||||
apply(pm.build, list(args), options)
|
||||
|
||||
|
||||
######################################################################
|
||||
# Tests
|
||||
######################################################################
|
||||
|
||||
def test0():
|
||||
"Vanilla test for the distutils distribution."
|
||||
|
||||
pm = PackageMaker("distutils2", "1.0.2", "Python distutils package.")
|
||||
pm.build("/Users/dinu/Desktop/distutils2")
|
||||
|
||||
|
||||
def test1():
|
||||
"Test for the reportlab distribution with modified options."
|
||||
|
||||
pm = PackageMaker("reportlab", "1.10",
|
||||
"ReportLab's Open Source PDF toolkit.")
|
||||
pm.build(root="/Users/dinu/Desktop/reportlab",
|
||||
DefaultLocation="/Applications/ReportLab",
|
||||
Relocatable="YES")
|
||||
|
||||
def test2():
|
||||
"Shortcut test for the reportlab distribution with modified options."
|
||||
|
||||
buildPackage(
|
||||
"/Users/dinu/Desktop/reportlab",
|
||||
Title="reportlab",
|
||||
Version="1.10",
|
||||
Description="ReportLab's Open Source PDF toolkit.",
|
||||
DefaultLocation="/Applications/ReportLab",
|
||||
Relocatable="YES")
|
||||
|
||||
|
||||
######################################################################
|
||||
# Command-line interface
|
||||
######################################################################
|
||||
|
||||
def printUsage():
|
||||
"Print usage message."
|
||||
|
||||
format = "Usage: %s <opts1> [<opts2>] <root> [<resources>]"
|
||||
print format % basename(sys.argv[0])
|
||||
print
|
||||
print " with arguments:"
|
||||
print " (mandatory) root: the package root folder"
|
||||
print " (optional) resources: the package resources folder"
|
||||
print
|
||||
print " and options:"
|
||||
print " (mandatory) opts1:"
|
||||
mandatoryKeys = string.split("Title Version Description", " ")
|
||||
for k in mandatoryKeys:
|
||||
print " --%s" % k
|
||||
print " (optional) opts2: (with default values)"
|
||||
|
||||
pmDefaults = PackageMaker.packageInfoDefaults
|
||||
optionalKeys = pmDefaults.keys()
|
||||
for k in mandatoryKeys:
|
||||
optionalKeys.remove(k)
|
||||
optionalKeys.sort()
|
||||
maxKeyLen = max(map(len, optionalKeys))
|
||||
for k in optionalKeys:
|
||||
format = " --%%s:%s %%s"
|
||||
format = format % (" " * (maxKeyLen-len(k)))
|
||||
print format % (k, repr(pmDefaults[k]))
|
||||
|
||||
|
||||
def main():
|
||||
"Command-line interface."
|
||||
|
||||
shortOpts = ""
|
||||
keys = PackageMaker.packageInfoDefaults.keys()
|
||||
longOpts = map(lambda k: k+"=", keys)
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], shortOpts, longOpts)
|
||||
except getopt.GetoptError, details:
|
||||
print details
|
||||
printUsage()
|
||||
return
|
||||
|
||||
optsDict = {}
|
||||
for k, v in opts:
|
||||
optsDict[k[2:]] = v
|
||||
|
||||
ok = optsDict.keys()
|
||||
if not (1 <= len(args) <= 2):
|
||||
print "No argument given!"
|
||||
elif not ("Title" in ok and \
|
||||
"Version" in ok and \
|
||||
"Description" in ok):
|
||||
print "Missing mandatory option!"
|
||||
else:
|
||||
apply(buildPackage, args, optsDict)
|
||||
return
|
||||
|
||||
printUsage()
|
||||
|
||||
# sample use:
|
||||
# buildpkg.py --Title=distutils \
|
||||
# --Version=1.0.2 \
|
||||
# --Description="Python distutils package." \
|
||||
# /Users/dinu/Desktop/distutils
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
44
Mac/scripts/cachersrc.py
Normal file
44
Mac/scripts/cachersrc.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Scan the tree passed as argv[0] for .rsrc files, skipping .rsrc.df.rsrc
|
||||
# files, and open these. The effect of this is to create the .rsrc.df.rsrc
|
||||
# cache files if needed.
|
||||
# These are needed on OSX: the .rsrc files are in reality AppleSingle-encoded
|
||||
# files. We decode the resources into a datafork-based resource file.
|
||||
|
||||
import macresource
|
||||
import os
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
class NoArgsError(Exception):
|
||||
pass
|
||||
|
||||
def handler((verbose, force), dirname, fnames):
|
||||
for fn in fnames:
|
||||
if fn[-5:] == '.rsrc' and fn[-13:] != '.rsrc.df.rsrc':
|
||||
if force:
|
||||
try:
|
||||
os.unlink(os.path.join(dirname, fn + '.df.rsrc'))
|
||||
except IOError:
|
||||
pass
|
||||
macresource.open_pathname(os.path.join(dirname, fn), verbose=verbose)
|
||||
|
||||
def main():
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'vf')
|
||||
if not args:
|
||||
raise NoArgsError
|
||||
except (getopt.GetoptError, NoArgsError):
|
||||
sys.stderr.write('Usage: cachersrc.py dirname ...\n')
|
||||
sys.exit(1)
|
||||
verbose = 0
|
||||
force = 0
|
||||
for o, v in opts:
|
||||
if o == '-v':
|
||||
verbose = 1
|
||||
if o == '-f':
|
||||
force = 1
|
||||
for dir in sys.argv[1:]:
|
||||
os.path.walk(dir, handler, (verbose, force))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
1852
Mac/scripts/errors.txt
Normal file
1852
Mac/scripts/errors.txt
Normal file
File diff suppressed because it is too large
Load Diff
52
Mac/scripts/genallsuites.py
Normal file
52
Mac/scripts/genallsuites.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Generate all the standard scripting suite packages.
|
||||
# Note that this module needs *serious* hand-crafting because of all the
|
||||
# absolute paths. It is, however, a great leap forward compared to the time
|
||||
# when this information was only stored in Jack's brain:-)
|
||||
|
||||
import sys
|
||||
import os
|
||||
import gensuitemodule
|
||||
|
||||
verbose=sys.stdout
|
||||
|
||||
DSTDIR="/Users/jack/src/python/Lib/plat-mac/lib-scriptpackages"
|
||||
OS9DISK="/Volumes/Moes"
|
||||
|
||||
APPLESCRIPT=OS9DISK + "/Systeemmap/Extensies/AppleScript"
|
||||
SYSTEMEVENTS="/System/Library/CoreServices/System Events.app"
|
||||
|
||||
CODEWARRIOR=OS9DISK + "/Applications (Mac OS 9)/Metrowerks CodeWarrior 7.0/Metrowerks CodeWarrior/CodeWarrior IDE 4.2.6"
|
||||
EXPLORER="/Applications/Internet Explorer.app"
|
||||
FINDER="/System/Library/CoreServices/Finder.app"
|
||||
NETSCAPE=OS9DISK + "/Applications (Mac OS 9)/Netscape Communicator\xe2\x84\xa2 Folder/Netscape Communicator\xe2\x84\xa2"
|
||||
TERMINAL="/Applications/Utilities/Terminal.app"
|
||||
|
||||
gensuitemodule.processfile_fromresource(APPLESCRIPT,
|
||||
output=os.path.join(DSTDIR, 'StdSuites'),
|
||||
basepkgname='_builtinSuites',
|
||||
edit_modnames=[], verbose=verbose)
|
||||
gensuitemodule.processfile(SYSTEMEVENTS,
|
||||
output=os.path.join(DSTDIR, 'SystemEvents'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[('Disk_2d_Folder_2d_File_Suite', 'Disk_Folder_File_Suite')],
|
||||
verbose=verbose)
|
||||
gensuitemodule.processfile(CODEWARRIOR,
|
||||
output=os.path.join(DSTDIR, 'CodeWarrior'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[], verbose=verbose)
|
||||
gensuitemodule.processfile(EXPLORER,
|
||||
output=os.path.join(DSTDIR, 'Explorer'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[], verbose=verbose)
|
||||
gensuitemodule.processfile(FINDER,
|
||||
output=os.path.join(DSTDIR, 'Finder'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[], verbose=verbose)
|
||||
gensuitemodule.processfile(NETSCAPE,
|
||||
output=os.path.join(DSTDIR, 'Netscape'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[('WorldWideWeb_suite_2c__as_d', 'WorldWideWeb_suite')], verbose=verbose)
|
||||
gensuitemodule.processfile(TERMINAL,
|
||||
output=os.path.join(DSTDIR, 'Terminal'),
|
||||
basepkgname='StdSuites',
|
||||
edit_modnames=[], verbose=verbose)
|
||||
7
Mac/scripts/mkestrres-errno.h
Normal file
7
Mac/scripts/mkestrres-errno.h
Normal file
@@ -0,0 +1,7 @@
|
||||
/* These are defined in MSL errno.h, but unfortunately not documented */
|
||||
#define EFPOS 35 /* File positioning error */
|
||||
#define ESIGPARM 36 /* Signal argument error */
|
||||
#define ENOMEM 37 /* Cannot allocate memory */
|
||||
#define EACCES 38 /* Permission denied */
|
||||
#define ENOENT 39 /* No such file or directory */
|
||||
#define ENOSYS 40 /* Function not implemented */
|
||||
13
Mac/scripts/mkestrres-macerrors.h
Normal file
13
Mac/scripts/mkestrres-macerrors.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/* Errors from InternetConfig.h */
|
||||
icPrefNotFoundErr = -666, /* Internet preference not found */
|
||||
icPermErr = -667, /* cannot set preference */
|
||||
icPrefDataErr = -668, /* problem with preference data */
|
||||
icInternalErr = -669, /* Internet Config internal error */
|
||||
icTruncatedErr = -670, /* more data was present than was returned */
|
||||
icNoMoreWritersErr = -671, /* you cannot begin a write session because someone else is already doing it */
|
||||
icNothingToOverrideErr = -672, /* no component for the override component to capture */
|
||||
icNoURLErr = -673, /* no URL found */
|
||||
icConfigNotFoundErr = -674, /* no internet configuration was found */
|
||||
icConfigInappropriateErr = -675, /* incorrect manufacturer code */
|
||||
icProfileNotFoundErr = -676, /* profile not found */
|
||||
icTooManyProfilesErr = -677 /* too many profiles in database */
|
||||
157
Mac/scripts/mkestrres.py
Normal file
157
Mac/scripts/mkestrres.py
Normal file
@@ -0,0 +1,157 @@
|
||||
"""Parse sys/errno.h and Errors.h and create Estr resource"""
|
||||
|
||||
import re
|
||||
import string
|
||||
from Carbon import Res
|
||||
import os
|
||||
|
||||
READ = 1
|
||||
WRITE = 2
|
||||
smAllScripts = -3
|
||||
|
||||
ERRNO_PROG="#define[ \t]+" \
|
||||
"([A-Z0-9a-z_]+)" \
|
||||
"[ \t]+" \
|
||||
"([0-9]+)" \
|
||||
"[ \t]*/\*[ \t]*" \
|
||||
"(.*)" \
|
||||
"[ \t]*\*/"
|
||||
|
||||
ERRORS_PROG="[ \t]*" \
|
||||
"([A-Z0-9a-z_]+)" \
|
||||
"[ \t]*=[ \t]*" \
|
||||
"([-0-9]+)" \
|
||||
"[, \t]*/\*[ \t]*" \
|
||||
"(.*)" \
|
||||
"[ \t]*\*/"
|
||||
|
||||
ERRORS_PROG_2="[ \t]*" \
|
||||
"([A-Z0-9a-z_]+)" \
|
||||
"[ \t]*=[ \t]*" \
|
||||
"([-0-9]+)" \
|
||||
"[, \t]*"
|
||||
|
||||
def Pstring(str):
|
||||
if len(str) > 255:
|
||||
raise ValueError, 'String too large'
|
||||
return chr(len(str))+str
|
||||
|
||||
def writeestr(dst, edict):
|
||||
"""Create Estr resource file given a dictionary of errors."""
|
||||
|
||||
os.unlink(dst.as_pathname())
|
||||
Res.FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts)
|
||||
output = Res.FSpOpenResFile(dst, WRITE)
|
||||
Res.UseResFile(output)
|
||||
for num in edict.keys():
|
||||
res = Res.Resource(Pstring(edict[num][0]))
|
||||
res.AddResource('Estr', num, '')
|
||||
res.WriteResource()
|
||||
Res.CloseResFile(output)
|
||||
|
||||
def writepython(fp, dict):
|
||||
k = dict.keys()
|
||||
k.sort()
|
||||
for i in k:
|
||||
fp.write("%s\t=\t%d\t#%s\n"%(dict[i][1], i, dict[i][0]))
|
||||
|
||||
|
||||
def parse_errno_h(fp, dict):
|
||||
errno_prog = re.compile(ERRNO_PROG)
|
||||
for line in fp.readlines():
|
||||
m = errno_prog.match(line)
|
||||
if m:
|
||||
number = string.atoi(m.group(2))
|
||||
name = m.group(1)
|
||||
desc = string.strip(m.group(3))
|
||||
|
||||
if not dict.has_key(number):
|
||||
dict[number] = desc, name
|
||||
else:
|
||||
print 'DUPLICATE', number
|
||||
print '\t', dict[number]
|
||||
print '\t', (desc, name)
|
||||
|
||||
def parse_errors_h(fp, dict):
|
||||
errno_prog = re.compile(ERRORS_PROG)
|
||||
errno_prog_2 = re.compile(ERRORS_PROG_2)
|
||||
for line in fp.readlines():
|
||||
match = 0
|
||||
m = errno_prog.match(line)
|
||||
m2 = errno_prog_2.match(line)
|
||||
if m:
|
||||
number = string.atoi(m.group(2))
|
||||
name = m.group(1)
|
||||
desc = string.strip(m.group(3))
|
||||
match=1
|
||||
elif m2:
|
||||
number = string.atoi(m2.group(2))
|
||||
name = m2.group(1)
|
||||
desc = name
|
||||
match=1
|
||||
if match:
|
||||
if number > 0: continue
|
||||
|
||||
if not dict.has_key(number):
|
||||
dict[number] = desc, name
|
||||
else:
|
||||
print 'DUPLICATE', number
|
||||
print '\t', dict[number]
|
||||
print '\t', (desc, name)
|
||||
if len(desc) > len(dict[number][0]):
|
||||
print 'Pick second one'
|
||||
dict[number] = desc, name
|
||||
|
||||
def main():
|
||||
dict = {}
|
||||
pathname = EasyDialogs.AskFileForOpen(message="Where is GUSI sys/errno.h?")
|
||||
if pathname:
|
||||
fp = open(pathname)
|
||||
parse_errno_h(fp, dict)
|
||||
fp.close()
|
||||
|
||||
pathname = EasyDialogs.AskFileForOpen(message="Select cerrno (MSL) or cancel")
|
||||
if pathname:
|
||||
fp = open(pathname)
|
||||
parse_errno_h(fp, dict)
|
||||
fp.close()
|
||||
|
||||
pathname = EasyDialogs.AskFileForOpen(message="Where is MacErrors.h?")
|
||||
if pathname:
|
||||
fp = open(pathname)
|
||||
parse_errors_h(fp, dict)
|
||||
fp.close()
|
||||
|
||||
pathname = EasyDialogs.AskFileForOpen(message="Where is mkestrres-MacErrors.h?")
|
||||
if pathname:
|
||||
fp = open(pathname)
|
||||
parse_errors_h(fp, dict)
|
||||
fp.close()
|
||||
|
||||
if not dict:
|
||||
return
|
||||
|
||||
pathname = EasyDialogs.AskFileForSave(message="Resource output file?", savedFileName="errors.rsrc")
|
||||
if pathname:
|
||||
writeestr(fss, dict)
|
||||
|
||||
pathname = EasyDialogs.AskFileForSave(message="Python output file?", savedFileName="macerrors.py")
|
||||
if pathname:
|
||||
fp = open(pathname, "w")
|
||||
writepython(fp, dict)
|
||||
fp.close()
|
||||
fss.SetCreatorType('Pyth', 'TEXT')
|
||||
|
||||
pathname = EasyDialogs.AskFileForSave(message="Text output file?", savedFileName="errors.txt")
|
||||
if pathname:
|
||||
fp = open(pathname, "w")
|
||||
|
||||
k = dict.keys()
|
||||
k.sort()
|
||||
for i in k:
|
||||
fp.write("%d\t%s\t%s\n"%(i, dict[i][1], dict[i][0]))
|
||||
fp.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
29
Mac/scripts/zappycfiles.py
Executable file
29
Mac/scripts/zappycfiles.py
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
"""Recursively zap all .pyc and .pyo files"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
# set doit true to actually delete files
|
||||
# set doit false to just print what would be deleted
|
||||
doit = 1
|
||||
|
||||
def main():
|
||||
if not sys.argv[1:]:
|
||||
print 'Usage: zappyc dir ...'
|
||||
sys.exit(1)
|
||||
for dir in sys.argv[1:]:
|
||||
zappyc(dir)
|
||||
|
||||
def zappyc(dir):
|
||||
os.path.walk(dir, walker, None)
|
||||
|
||||
def walker(dummy, top, names):
|
||||
for name in names:
|
||||
if name[-4:] in ('.pyc', '.pyo'):
|
||||
path = os.path.join(top, name)
|
||||
print 'Zapping', path
|
||||
if doit:
|
||||
os.unlink(path)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user