summaryrefslogtreecommitdiffstats
path: root/Mac/Tools/macfreeze
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-06-08 14:52:47 (GMT)
committerThomas Wouters <thomas@python.org>2006-06-08 14:52:47 (GMT)
commit1ba5b3b425e970ec3e4a19165475aa68fa5ac893 (patch)
tree607d666a002704ccb6a8cc5d1739b729a64cc615 /Mac/Tools/macfreeze
parent4d70c3d9dded0f0fa7a73c67217a71111d05df4d (diff)
downloadcpython-1ba5b3b425e970ec3e4a19165475aa68fa5ac893.zip
cpython-1ba5b3b425e970ec3e4a19165475aa68fa5ac893.tar.gz
cpython-1ba5b3b425e970ec3e4a19165475aa68fa5ac893.tar.bz2
Merged revisions 46607-46608 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r46607 | neal.norwitz | 2006-06-03 06:49:00 +0200 (Sat, 03 Jun 2006) | 1 line Remove Mac OS 9 support (http://mail.python.org/pipermail/python-dev/2006-June/065538.html) ........ r46608 | martin.v.loewis | 2006-06-03 09:37:13 +0200 (Sat, 03 Jun 2006) | 2 lines Port to OpenBSD 3.9. Patch from Aldo Cortesi. ........
Diffstat (limited to 'Mac/Tools/macfreeze')
-rw-r--r--Mac/Tools/macfreeze/directives.py42
-rw-r--r--Mac/Tools/macfreeze/hello/hello.py5
-rw-r--r--Mac/Tools/macfreeze/macfreeze.py75
-rw-r--r--Mac/Tools/macfreeze/macfreeze.rsrcbin1006 -> 0 bytes
-rw-r--r--Mac/Tools/macfreeze/macfreezegui.py150
-rw-r--r--Mac/Tools/macfreeze/macgen_bin.py221
-rw-r--r--Mac/Tools/macfreeze/macgen_info.py8
-rw-r--r--Mac/Tools/macfreeze/macgen_rsrc.py36
-rw-r--r--Mac/Tools/macfreeze/macgen_src.py113
-rw-r--r--Mac/Tools/macfreeze/macgenerate.py8
-rw-r--r--Mac/Tools/macfreeze/macmodulefinder.py112
11 files changed, 0 insertions, 770 deletions
diff --git a/Mac/Tools/macfreeze/directives.py b/Mac/Tools/macfreeze/directives.py
deleted file mode 100644
index 7f6142e..0000000
--- a/Mac/Tools/macfreeze/directives.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import re
-import os
-
-# The regular expression for freeze directives. These are comments with the
-# word macfreeze immedeately followed by a colon, followed by a directive,
-# followed by argument(s)
-#
-# The directives supported are
-# include - Include a module or file
-# exclude - Exclude a module
-# optional - Include a module if it is found, but don't complain if it isn't
-# path - Add sys.path entries. Relative paths are relative to the source file.
-#
-# See the macfreeze.py main program for a real live example.
-#
-DIRECTIVE_RE=r'^\s*#\s*macfreeze:\s*(\S*)\s*(.*)\s*$'
-REPROG=re.compile(DIRECTIVE_RE)
-
-def findfreezedirectives(program):
- extra_modules = []
- exclude_modules = []
- optional_modules = []
- extra_path = []
- progdir, filename = os.path.split(program)
- fp = open(program)
- for line in fp.readlines():
- match = REPROG.match(line)
- if match:
- directive = match.group(1)
- argument = match.group(2)
- if directive == 'include':
- extra_modules.append(argument)
- elif directive == 'exclude':
- exclude_modules.append(argument)
- elif directive == 'optional':
- optional_modules.append(argument)
- elif directive == 'path':
- argument = os.path.join(progdir, argument)
- extra_path.append(argument)
- else:
- print '** Unknown directive', line
- return extra_modules, exclude_modules, optional_modules, extra_path
diff --git a/Mac/Tools/macfreeze/hello/hello.py b/Mac/Tools/macfreeze/hello/hello.py
deleted file mode 100644
index a713733..0000000
--- a/Mac/Tools/macfreeze/hello/hello.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import sys
-
-print 'Hello world'
-print 'Builtin modules:', sys.builtin_module_names
-sys.exit(1)
diff --git a/Mac/Tools/macfreeze/macfreeze.py b/Mac/Tools/macfreeze/macfreeze.py
deleted file mode 100644
index b2cf72e..0000000
--- a/Mac/Tools/macfreeze/macfreeze.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""macfreeze - Main program and GUI
-
-macfreeze allows you to turn Python scripts into fully self-contained
-Mac applications, by including all the Python and C code needed in a single
-executable. Like unix/windows freeze it can produce a config.c allowing you
-to build the application with a development environment (CodeWarrior, to be
-precise), but unlike the standard freeze it is also possible to create frozen
-applications without a development environment, by glueing all the
-shared libraries and extension modules needed together in a single
-executable, using some Code Fragment Manager tricks."""
-
-import macfs
-import sys
-import EasyDialogs
-import string
-
-import macfreezegui
-import macmodulefinder
-
-#
-# Here are the macfreeze directives, used when freezing macfreeze itself
-# (see directives.py for an explanation)
-#
-# macfreeze: path ::::Tools:freeze
-# macfreeze: exclude win32api
-#
-
-def main():
- if len(sys.argv) < 2:
- gentype, program, output, debug = macfreezegui.dialog()
- elif len(sys.argv) == 2:
- gentype, program, output, debug = macfreezegui.dialog(sys.argv[1])
- else:
- EasyDialog.Message(
- "Please pass a single script. Additional modules can be specified with directives")
- sys.exit(0)
- mustwait = process(gentype, program, output, debug=debug)
- if mustwait:
- sys.exit(1)
-
-def process(gentype, program, output, modules=None, module_files=None, debug=0, with_ifdef=0):
- if modules is None:
- modules = []
- if module_files is None:
- module_files = []
- module_dict, missing = macmodulefinder.process(program, modules, module_files, debug)
- if missing:
- missing.sort()
- print '** Missing modules:', string.join(missing, ' ')
- sys.exit(1)
- #
- # And generate
- #
- if gentype == 'info':
- import macgen_info
- macgen_info.generate(output, module_dict)
- return 1 # So the user can inspect it
- elif gentype == 'source':
- import macgen_src
- warnings = macgen_src.generate(output, module_dict, debug, with_ifdef)
- return warnings
- elif gentype == 'resource':
- import macgen_rsrc
- macgen_rsrc.generate(output, module_dict, debug)
- warnings = macgen_rsrc.warnings(module_dict)
- return warnings
- elif gentype == 'applet':
- import macgen_bin
- architecture = 'fat' # user should choose
- macgen_bin.generate(program, output, module_dict, architecture, debug)
- else:
- raise 'unknown gentype', gentype
-
-if __name__ == '__main__':
- main()
diff --git a/Mac/Tools/macfreeze/macfreeze.rsrc b/Mac/Tools/macfreeze/macfreeze.rsrc
deleted file mode 100644
index 2f7e51f..0000000
--- a/Mac/Tools/macfreeze/macfreeze.rsrc
+++ /dev/null
Binary files differ
diff --git a/Mac/Tools/macfreeze/macfreezegui.py b/Mac/Tools/macfreeze/macfreezegui.py
deleted file mode 100644
index 41d0ec8..0000000
--- a/Mac/Tools/macfreeze/macfreezegui.py
+++ /dev/null
@@ -1,150 +0,0 @@
-"""macfreezegui - The GUI for macfreeze"""
-from Carbon import Dlg
-import macfs
-import EasyDialogs
-import sys
-import os
-import string
-from Carbon import Res
-import macresource
-
-ID_MAINDIALOG=512
-
-ITEM_SCRIPTNAME=2
-ITEM_SCRIPTBROWSE=3
-ITEM_GENSOURCE=4
-ITEM_GENSOURCE_ITEMS=(7,)
-ITEM_SOURCEDIRNAME=6
-ITEM_SOURCEDIRBROWSE=7
-ITEM_GENRESOURCE=8
-ITEM_GENRESOURCE_ITEMS=(11,)
-ITEM_RESOURCENAME=10
-ITEM_RESOURCEBROWSE=11
-ITEM_GENAPPLET=12
-ITEM_GENAPPLET_ITEMS=(15,)
-ITEM_APPLETNAME=14
-ITEM_APPLETBROWSE=15
-ITEM_OK=16
-ITEM_CANCEL=17
-ITEM_DEBUG=19
-ITEM_GENINFO=20
-
-RADIO_GROUPING={
- ITEM_GENSOURCE: ITEM_GENSOURCE_ITEMS,
- ITEM_GENRESOURCE: ITEM_GENRESOURCE_ITEMS,
- ITEM_GENAPPLET: ITEM_GENAPPLET_ITEMS,
- ITEM_GENINFO: ()
-}
-
-def dialog(script=None):
-
- # Invent the various names
- if not script:
- fss, ok = macfs.PromptGetFile("Script?", "TEXT")
- if not ok:
- sys.exit(0)
- script = fss.as_pathname()
- basename, ext = os.path.splitext(script)
- if ext:
- appletname = basename
- rsrcname = basename + 'modules.rsrc'
- else:
- appletname = script + '.applet'
- rsrcname = script + 'modules.rsrc'
- dirname, basebase = os.path.split(basename)
- dirname = os.path.join(dirname, 'build.'+basebase)
-
- # Get the dialog, possibly opening the resource file (if needed)
- macresource.need('DLOG', ID_MAINDIALOG, 'macfreeze.rsrc')
- d = Dlg.GetNewDialog(ID_MAINDIALOG, -1)
- if d == None:
- EasyDialogs.Message("Dialog resource not found or faulty")
- sys.exit(1)
-
- # Fill the dialog
- d.SetDialogDefaultItem(ITEM_OK)
- d.SetDialogCancelItem(ITEM_CANCEL)
-
- _dialogsetfile(d, ITEM_SCRIPTNAME, script)
- _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
- _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
- _dialogsetfile(d, ITEM_APPLETNAME, appletname)
-
- gentype = ITEM_GENSOURCE
- _dialogradiogroup(d, ITEM_GENSOURCE)
-
- # Interact
- d.GetDialogWindow().SetWTitle("Standalone application creation options")
- d.GetDialogWindow().ShowWindow()
- d.DrawDialog()
- while 1:
- item = Dlg.ModalDialog(None)
- if item == ITEM_OK:
- break
- elif item == ITEM_CANCEL:
- sys.exit(0)
- elif item in RADIO_GROUPING.keys():
- gentype = item
- _dialogradiogroup(d, item)
- elif item == ITEM_SCRIPTBROWSE:
- fss, ok = macfs.PromptGetFile("Script?")
- if ok:
- script = fss.as_pathname()
- _dialogsetfile(d, ITEM_SCRIPTNAME, script)
- elif item == ITEM_SOURCEDIRBROWSE:
- fss, ok = macfs.StandardPutFile("Output folder name", os.path.split(dirname)[1])
- if ok:
- dirname = fss.as_pathname()
- _dialogsetfile(d, ITEM_SOURCEDIRNAME, dirname)
- elif item == ITEM_RESOURCEBROWSE:
- fss, ok = macfs.StandardPutFile("Resource output file", os.path.split(rsrcname)[1])
- if ok:
- rsrcname = fss.as_pathname()
- _dialogsetfile(d, ITEM_RESOURCENAME, rsrcname)
- elif item == ITEM_APPLETBROWSE:
- fss, ok = macfs.StandardPutFile("Applet output file", os.path.split(appletname)[1])
- if ok:
- appletname = fss.as_pathname()
- _dialogsetfile(d, ITEM_APPLETNAME, appletname)
- else:
- pass
- tp, h, rect = d.GetDialogItem(ITEM_DEBUG)
- debug = Dlg.GetDialogItemText(h)
- try:
- debug = string.atoi(string.strip(debug))
- except ValueError:
- EasyDialogs.Message("Illegal debug value %r, set to zero."%(debug,))
- debug = 0
- if gentype == ITEM_GENSOURCE:
- return 'source', script, dirname, debug
- elif gentype == ITEM_GENRESOURCE:
- return 'resource', script, rsrcname, debug
- elif gentype == ITEM_GENAPPLET:
- return 'applet', script, appletname, debug
- elif gentype == ITEM_GENINFO:
- return 'info', script, '', debug
- raise 'Error in gentype', gentype
-
-def _dialogradiogroup(d, item):
- for k in RADIO_GROUPING.keys():
- subitems = RADIO_GROUPING[k]
- tp, h, rect = d.GetDialogItem(k)
- if k == item:
- h.as_Control().SetControlValue(1)
- for i2 in subitems:
- d.ShowDialogItem(i2)
- else:
- h.as_Control().SetControlValue(0)
- for i2 in subitems:
- d.HideDialogItem(i2)
-
-def _dialogsetfile(d, item, file):
- if len(file) > 32:
- file = '\311:' + os.path.split(file)[1]
- tp, h, rect = d.GetDialogItem(item)
- Dlg.SetDialogItemText(h, file)
-
-if __name__ == '__main__':
- type, script, file, debug = dialog()
- print type, script, file, 'debug=%d'%debug
- sys.exit(1)
diff --git a/Mac/Tools/macfreeze/macgen_bin.py b/Mac/Tools/macfreeze/macgen_bin.py
deleted file mode 100644
index f52e37e..0000000
--- a/Mac/Tools/macfreeze/macgen_bin.py
+++ /dev/null
@@ -1,221 +0,0 @@
-"""macgen_bin - Generate application from shared libraries"""
-
-import os
-import sys
-import string
-import types
-import macfs
-from MACFS import *
-import MacOS
-from Carbon import Res
-import py_resource
-import cfmfile
-import buildtools
-
-
-def generate(input, output, module_dict=None, architecture='fat', debug=0):
- # try to remove old file
- try:
- os.remove(output)
- except:
- pass
-
- if module_dict is None:
- import macmodulefinder
- print "Searching for modules..."
- module_dict, missing = macmodulefinder.process(input, [], [], 1)
- if missing:
- import EasyDialogs
- missing.sort()
- answer = EasyDialogs.AskYesNoCancel("Some modules could not be found; continue anyway?\n(%s)"
- % string.join(missing, ", "))
- if answer <> 1:
- sys.exit(0)
-
- applettemplatepath = buildtools.findtemplate()
- corepath = findpythoncore()
-
- dynamicmodules, dynamicfiles, extraresfiles = findfragments(module_dict, architecture)
-
- print 'Adding "__main__"'
- buildtools.process(applettemplatepath, input, output, 0)
-
- outputref = Res.FSpOpenResFile(output, 3)
- try:
- Res.UseResFile(outputref)
-
- print "Adding Python modules"
- addpythonmodules(module_dict)
-
- print "Adding PythonCore resources"
- copyres(corepath, outputref, ['cfrg', 'Popt', 'GU\267I'], 1)
-
- print "Adding resources from shared libraries"
- for ppcpath, cfm68kpath in extraresfiles:
- if os.path.exists(ppcpath):
- copyres(ppcpath, outputref, ['cfrg'], 1)
- elif os.path.exists(cfm68kpath):
- copyres(cfm68kpath, outputref, ['cfrg'], 1)
-
- print "Fixing sys.path prefs"
- Res.UseResFile(outputref)
- try:
- res = Res.Get1Resource('STR#', 228) # from PythonCore
- except Res.Error: pass
- else:
- res.RemoveResource()
- # setting pref file name to empty string
- res = Res.Get1NamedResource('STR ', "PythonPreferenceFileName")
- res.data = Pstring("")
- res.ChangedResource()
- syspathpref = "$(APPLICATION)"
- res = Res.Resource("\000\001" + Pstring(syspathpref))
- res.AddResource("STR#", 229, "sys.path preference")
-
- print "Creating 'PYD ' resources"
- for modname, (ppcfrag, cfm68kfrag) in dynamicmodules.items():
- res = Res.Resource(Pstring(ppcfrag) + Pstring(cfm68kfrag))
- id = 0
- while id < 128:
- id = Res.Unique1ID('PYD ')
- res.AddResource('PYD ', id, modname)
- finally:
- Res.CloseResFile(outputref)
- print "Merging code fragments"
- cfmfile.mergecfmfiles([applettemplatepath, corepath] + dynamicfiles.keys(),
- output, architecture)
-
- print "done!"
-
-
-def findfragments(module_dict, architecture):
- dynamicmodules = {}
- dynamicfiles = {}
- extraresfiles = []
- for name, module in module_dict.items():
- if module.gettype() <> 'dynamic':
- continue
- path = resolvealiasfile(module.__file__)
- dir, filename = os.path.split(path)
-## ppcfile, cfm68kfile = makefilenames(filename)
- ppcfile = filename
- cfm68kfile = "dummy.cfm68k.slb"
-
- # ppc stuff
- ppcpath = os.path.join(dir, ppcfile)
- if architecture <> 'm68k':
- ppcfrag, dynamicfiles = getfragname(ppcpath, dynamicfiles)
- else:
- ppcfrag = "_no_fragment_"
-
- # 68k stuff
- cfm68kpath = os.path.join(dir, cfm68kfile)
- if architecture <> 'pwpc':
- cfm68kfrag, dynamicfiles = getfragname(cfm68kpath, dynamicfiles)
- else:
- cfm68kfrag = "_no_fragment_"
-
- dynamicmodules[name] = ppcfrag, cfm68kfrag
- if (ppcpath, cfm68kpath) not in extraresfiles:
- extraresfiles.append((ppcpath, cfm68kpath))
- return dynamicmodules, dynamicfiles, extraresfiles
-
-
-def getfragname(path, dynamicfiles):
- if not dynamicfiles.has_key(path):
- if os.path.exists(path):
- lib = cfmfile.CfrgResource(path)
- fragname = lib.fragments[0].name
- else:
- print "shared lib not found:", path
- fragname = "_no_fragment_"
- dynamicfiles[path] = fragname
- else:
- fragname = dynamicfiles[path]
- return fragname, dynamicfiles
-
-
-def addpythonmodules(module_dict):
- # XXX should really use macgen_rsrc.generate(), this does the same, but skips __main__
- items = module_dict.items()
- items.sort()
- for name, module in items:
- mtype = module.gettype()
- if mtype not in ['module', 'package'] or name == "__main__":
- continue
- location = module.__file__
-
- if location[-4:] == '.pyc':
- # Attempt corresponding .py
- location = location[:-1]
- if location[-3:] != '.py':
- print '*** skipping', location
- continue
-
- print 'Adding module "%s"' % name
- id, name = py_resource.frompyfile(location, name, preload=0,
- ispackage=mtype=='package')
-
-def Pstring(str):
- if len(str) > 255:
- raise TypeError, "Str255 must be at most 255 chars long"
- return chr(len(str)) + str
-
-##def makefilenames(name):
-## lname = string.lower(name)
-## pos = string.find(lname, ".ppc.")
-## if pos > 0:
-## return name, name[:pos] + '.CFM68K.' + name[pos+5:]
-## pos = string.find(lname, ".cfm68k.")
-## if pos > 0:
-## return name[:pos] + '.ppc.' + name[pos+8:], name
-## raise ValueError, "can't make ppc/cfm68k filenames"
-
-def copyres(input, output, *args, **kwargs):
- openedin = openedout = 0
- if type(input) == types.StringType:
- input = Res.FSpOpenResFile(input, 1)
- openedin = 1
- if type(output) == types.StringType:
- output = Res.FSpOpenResFile(output, 3)
- openedout = 1
- try:
- buildtools.copyres(input, output, *args, **kwargs)
- finally:
- if openedin:
- Res.CloseResFile(input)
- if openedout:
- Res.CloseResFile(output)
-
-def findpythoncore():
- """find the PythonCore shared library, possibly asking the user if we can't find it"""
-
- try:
- vRefNum, dirID = macfs.FindFolder(kOnSystemDisk, kSharedLibrariesFolderType, 0)
- except macfs.error:
- extpath = ":"
- else:
- extpath = macfs.FSSpec((vRefNum, dirID, "")).as_pathname()
- version = string.split(sys.version)[0]
- if MacOS.runtimemodel == 'carbon':
- corename = "PythonCoreCarbon " + version
- elif MacOS.runtimemodel == 'ppc':
- corename = "PythonCore " + version
- else:
- raise "Unknown MacOS.runtimemodel", MacOS.runtimemodel
- corepath = os.path.join(extpath, corename)
- if not os.path.exists(corepath):
- corepath = EasyDialogs.AskFileForOpen(message="Please locate PythonCore:",
- typeList=("shlb",))
- if not corepath:
- raise KeyboardInterrupt, "cancelled"
- return resolvealiasfile(corepath)
-
-def resolvealiasfile(path):
- try:
- fss, dummy1, dummy2 = macfs.ResolveAliasFile(path)
- except macfs.error:
- pass
- else:
- path = fss.as_pathname()
- return path
diff --git a/Mac/Tools/macfreeze/macgen_info.py b/Mac/Tools/macfreeze/macgen_info.py
deleted file mode 100644
index d2edb92..0000000
--- a/Mac/Tools/macfreeze/macgen_info.py
+++ /dev/null
@@ -1,8 +0,0 @@
-"""macgen_info - Generate informational output"""
-
-def generate(output, module_dict):
- for name in module_dict.keys():
- print 'Include %-20s\t'%name,
- module = module_dict[name]
- print module.gettype(), '\t', repr(module)
- return 0
diff --git a/Mac/Tools/macfreeze/macgen_rsrc.py b/Mac/Tools/macfreeze/macgen_rsrc.py
deleted file mode 100644
index 34c17ff..0000000
--- a/Mac/Tools/macfreeze/macgen_rsrc.py
+++ /dev/null
@@ -1,36 +0,0 @@
-"""macgen_info - Generate PYC resource file only"""
-import EasyDialogs
-import py_resource
-from Carbon import Res
-import sys
-
-def generate(output, module_dict, debug=0, preload=1):
- fsid = py_resource.create(output)
-
- for name, module in module_dict.items():
- mtype = module.gettype()
- if mtype not in ['module', 'package']:
- continue
- location = module.__file__
-
- if location[-4:] == '.pyc':
- # Attempt corresponding .py
- location = location[:-1]
- if location[-3:] != '.py':
- print '*** skipping', location
- continue
-
- id, name = py_resource.frompyfile(location, name, preload=preload,
- ispackage=mtype=='package')
- if debug > 0:
- print 'PYC resource %5d\t%s\t%s'%(id, name, location)
-
- Res.CloseResFile(fsid)
-
-def warnings(module_dict):
- problems = 0
- for name, module in module_dict.items():
- if module.gettype() not in ('builtin', 'module', 'package'):
- problems = problems + 1
- print 'Warning: %s not included: %s %s'%(name, module.gettype(), module)
- return problems
diff --git a/Mac/Tools/macfreeze/macgen_src.py b/Mac/Tools/macfreeze/macgen_src.py
deleted file mode 100644
index 301e85e..0000000
--- a/Mac/Tools/macfreeze/macgen_src.py
+++ /dev/null
@@ -1,113 +0,0 @@
-"""macgen_info - Generate CodeWarrior project, config source, resource file"""
-import EasyDialogs
-import os
-import sys
-import macfs
-import MacOS
-import macostools
-import macgen_rsrc
-# Note: this depends on being frozen, or on sys.path already being
-# modified by macmodulefinder.
-import makeconfig
-
-TEMPLATEDIR=os.path.join(sys.prefix, ':Mac:mwerks:projects:build.macfreeze')
-PROJECT_TEMPLATE=os.path.join(TEMPLATEDIR, ':frozen.prj')
-CONFIG_TEMPLATE=os.path.join(TEMPLATEDIR, ':templatefrozenconfig.c')
-BUNDLE_TEMPLATE=os.path.join(TEMPLATEDIR, ':frozenbundle.rsrc')
-
-def generate(output, module_dict, debug=0, with_ifdef=0):
- problems = 0
- output_created=0
- if not os.path.exists(output):
- print 'Creating project folder', output
- os.mkdir(output)
- output_created = 1
- # Resolve aliases, if needed
- try:
- fss, dummy1, dummy2 = macfs.ResolveAliasFile(output)
- except macfs.error:
- pass
- else:
- newname = fss.as_pathname()
- if newname != output:
- if debug:
- print 'Alias', output
- print 'Resolved to', newname
- output = newname
- # Construct the filenames
- dummy, outfile = os.path.split(output)
- build, ext = os.path.splitext(outfile)
- if build == 'build' and ext[0] == '.':
- # This is probably a good name for the project
- projname = ext[1:]
- else:
- projname = 'frozenapplet.prj'
- config_name = os.path.join(output, ':macfrozenconfig.c')
- project_name = os.path.join(output, ':' + projname + '.prj')
- resource_name = os.path.join(output, ':frozenmodules.rsrc')
- bundle_name = os.path.join(output, ':frozenbundle.rsrc')
-
- # Fill the output folder, if needed.
- if output_created:
- # Create the project, if needed
- if not os.path.exists(project_name):
- print 'Creating project', project_name
- if not os.path.exists(PROJECT_TEMPLATE):
- print '** No template CodeWarrior project found at', PROJECT_TEMPLATE
- print ' To generate standalone Python applications from source you need'
- print ' a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
- print ' for details.'
- problems = 1
- else:
- macostools.copy(PROJECT_TEMPLATE, project_name)
- print 'A template CodeWarrior project has been copied to', project_name
- print 'It is up to you to make the following changes:'
- print '- Change the output file name'
- print '- Change the search path, unless the folder is in the python home'
- print '- Add sourcefiles/libraries for any extension modules used'
- print '- Remove unused sources, to speed up the build process'
- print '- Remove unused resource files (like tcl/tk) for a smaller binary'
- problems = 1
- macostools.copy(BUNDLE_TEMPLATE, bundle_name)
- print 'A template bundle file has also been copied to', bundle_name
- print 'You may want to adapt signature, size resource, etc'
-
-
- # Create the resource file
- macgen_rsrc.generate(resource_name, module_dict, debug=debug)
-
- # Create the config.c file
- if not os.path.exists(CONFIG_TEMPLATE):
- print '** No template config.c found at', PROJECT_TEMPLATE
- print ' To generate standalone Python applications from source you need'
- print ' a full source distribution. Check http://www.cwi.nl/~jack/macpython.html'
- print ' for details.'
- problems = 1
- else:
- # Find elegible modules (builtins and dynamically loaded modules)
- c_modules = []
- for module in module_dict.keys():
- if module_dict[module].gettype() in ('builtin', 'dynamic'):
- # if the module is in a package we have no choice but
- # to put it at the toplevel in the frozen application.
- if '.' in module:
- module = module.split('.')[-1]
- c_modules.append(module)
- ifp = open(CONFIG_TEMPLATE)
- ofp = open(config_name, 'w')
- makeconfig.makeconfig(ifp, ofp, c_modules, with_ifdef)
- ifp.close()
- ofp.close()
- MacOS.SetCreatorAndType(config_name, 'CWIE', 'TEXT')
-
- if warnings(module_dict):
- problems = 1
- return problems
-
-def warnings(module_dict):
- problems = 0
- for name, module in module_dict.items():
- if module.gettype() not in ('builtin', 'module', 'dynamic', 'package'):
- problems = problems + 1
- print 'Warning: %s not included: %s %s'%(name, module.gettype(), module)
- return problems
diff --git a/Mac/Tools/macfreeze/macgenerate.py b/Mac/Tools/macfreeze/macgenerate.py
deleted file mode 100644
index 12343c3..0000000
--- a/Mac/Tools/macfreeze/macgenerate.py
+++ /dev/null
@@ -1,8 +0,0 @@
-"""macgenerate - Generate the out for macfreeze"""
-
-def generate(program, module_dict):
- for name in module_dict.keys():
- print 'Include %-20s\t'%name,
- module = module_dict[name]
- print module.gettype(), '\t', repr(module)
- return 0
diff --git a/Mac/Tools/macfreeze/macmodulefinder.py b/Mac/Tools/macfreeze/macmodulefinder.py
deleted file mode 100644
index 3f4e0b7..0000000
--- a/Mac/Tools/macfreeze/macmodulefinder.py
+++ /dev/null
@@ -1,112 +0,0 @@
-"""macmodulefinder - Find modules used in a script. Only slightly
-mac-specific, really."""
-
-import sys
-import os
-
-import directives
-
-try:
- # This will work if we are frozen ourselves
- import modulefinder
-except ImportError:
- # And this will work otherwise
- _FREEZEDIR=os.path.join(sys.prefix, ':Tools:freeze')
- sys.path.insert(0, _FREEZEDIR)
- import modulefinder
-
-#
-# Modules that must be included, and modules that need not be included
-# (but are if they are found)
-#
-MAC_INCLUDE_MODULES=['site']
-MAC_MAYMISS_MODULES=['posix', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
- 'win32api', 'ce', '_winreg',
- 'nturl2path', 'pwd', 'sitecustomize',
- 'org.python.core',
- 'riscos', 'riscosenviron', 'riscospath'
- ]
-
-# An exception:
-Missing="macmodulefinder.Missing"
-
-class Module(modulefinder.Module):
-
- def gettype(self):
- """Return type of module"""
- if self.__path__:
- return 'package'
- if self.__code__:
- return 'module'
- if self.__file__:
- return 'dynamic'
- return 'builtin'
-
-class ModuleFinder(modulefinder.ModuleFinder):
-
- def add_module(self, fqname):
- if self.modules.has_key(fqname):
- return self.modules[fqname]
- self.modules[fqname] = m = Module(fqname)
- return m
-
-def process(program, modules=None, module_files=None, debug=0):
- if modules is None:
- modules = []
- if module_files is None:
- module_files = []
- missing = []
- #
- # Add the standard modules needed for startup
- #
- modules = modules + MAC_INCLUDE_MODULES
- #
- # search the main source for directives
- #
- extra_modules, exclude_modules, optional_modules, extra_path = \
- directives.findfreezedirectives(program)
- for m in extra_modules:
- if os.sep in m:
- # It is a file
- module_files.append(m)
- else:
- modules.append(m)
- # collect all modules of the program
- path = sys.path[:]
- dir = os.path.dirname(program)
- path[0] = dir # "current dir"
- path = extra_path + path
- #
- # Create the module finder and let it do its work
- #
- modfinder = ModuleFinder(path,
- excludes=exclude_modules, debug=debug)
- for m in modules:
- modfinder.import_hook(m)
- for m in module_files:
- modfinder.load_file(m)
- modfinder.run_script(program)
- module_dict = modfinder.modules
- #
- # Tell the user about missing modules
- #
- maymiss = exclude_modules + optional_modules + MAC_MAYMISS_MODULES
- for m in modfinder.badmodules.keys():
- if not m in maymiss:
- if debug > 0:
- print 'Missing', m
- missing.append(m)
- #
- # Warn the user about unused builtins
- #
- for m in sys.builtin_module_names:
- if m in ('__main__', '__builtin__'):
- pass
- elif not module_dict.has_key(m):
- if debug > 0:
- print 'Unused', m
- elif module_dict[m].gettype() != 'builtin':
- # XXXX Can this happen?
- if debug > 0:
- print 'Conflict', m
- return module_dict, missing