Example #1
0
"""macgen_bin - Generate application from shared libraries"""
Example #2
0
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!"
Example #3
0
"""macgen_bin - Generate application from shared libraries"""
Example #4
0
#
Example #5
0
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!"
Example #6
0
#