diff options
Diffstat (limited to 'Mac/Tools/macfreeze')
-rw-r--r-- | Mac/Tools/macfreeze/directives.py | 47 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macfreeze.py | 86 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macfreezegui.py | 214 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macgen_bin.py | 372 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macgen_info.py | 10 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macgen_rsrc.py | 57 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macgen_src.py | 184 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macgenerate.py | 10 | ||||
-rw-r--r-- | Mac/Tools/macfreeze/macmodulefinder.py | 162 |
9 files changed, 570 insertions, 572 deletions
diff --git a/Mac/Tools/macfreeze/directives.py b/Mac/Tools/macfreeze/directives.py index 3ef9661..7f6142e 100644 --- a/Mac/Tools/macfreeze/directives.py +++ b/Mac/Tools/macfreeze/directives.py @@ -17,27 +17,26 @@ 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 - + 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/macfreeze.py b/Mac/Tools/macfreeze/macfreeze.py index 8a2ca76..b2cf72e 100644 --- a/Mac/Tools/macfreeze/macfreeze.py +++ b/Mac/Tools/macfreeze/macfreeze.py @@ -26,50 +26,50 @@ import macmodulefinder # 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) + 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 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() + main() diff --git a/Mac/Tools/macfreeze/macfreezegui.py b/Mac/Tools/macfreeze/macfreezegui.py index 5dd3435..41d0ec8 100644 --- a/Mac/Tools/macfreeze/macfreezegui.py +++ b/Mac/Tools/macfreeze/macfreezegui.py @@ -30,121 +30,121 @@ 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: () + 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) + # 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) - gentype = ITEM_GENSOURCE - _dialogradiogroup(d, ITEM_GENSOURCE) + # 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) - # 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 + # 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) + 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 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) + 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 index 8735e171..bfcdc8b 100644 --- a/Mac/Tools/macfreeze/macgen_bin.py +++ b/Mac/Tools/macfreeze/macgen_bin.py @@ -14,208 +14,208 @@ 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!" + # 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 + 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 + 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') + # 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 + 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" +## 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: - apply(buildtools.copyres, (input, output) + args, kwargs) - finally: - if openedin: - Res.CloseResFile(input) - if openedout: - Res.CloseResFile(output) + 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: + apply(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) + """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 + 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 index 2d984c1..d2edb92 100644 --- a/Mac/Tools/macfreeze/macgen_info.py +++ b/Mac/Tools/macfreeze/macgen_info.py @@ -1,8 +1,8 @@ """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 + 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 index 03fc0af..34c17ff 100644 --- a/Mac/Tools/macfreeze/macgen_rsrc.py +++ b/Mac/Tools/macfreeze/macgen_rsrc.py @@ -5,33 +5,32 @@ 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) - + 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 - + 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 index 089727a..301e85e 100644 --- a/Mac/Tools/macfreeze/macgen_src.py +++ b/Mac/Tools/macfreeze/macgen_src.py @@ -16,98 +16,98 @@ 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') + 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' + # 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 - - # 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 + 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 index dfa2047..12343c3 100644 --- a/Mac/Tools/macfreeze/macgenerate.py +++ b/Mac/Tools/macfreeze/macgenerate.py @@ -1,8 +1,8 @@ """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 + 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 index 285f51f..3f4e0b7 100644 --- a/Mac/Tools/macfreeze/macmodulefinder.py +++ b/Mac/Tools/macfreeze/macmodulefinder.py @@ -7,40 +7,40 @@ import os import directives try: - # This will work if we are frozen ourselves - import modulefinder + # 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 + # 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' - ] +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' + + 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): @@ -49,64 +49,64 @@ class ModuleFinder(modulefinder.ModuleFinder): 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) + 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 + 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 |