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