Exemple #1
0
    def close(self):
        if self.closed:
            return
        Res.UseResFile(self.resref)
        try:
            res = Res.Get1NamedResource('sfnt', self.fullname)
        except Res.Error:
            pass
        else:
            res.RemoveResource()
        res = Res.Resource(self.file.getvalue())
        if self.res_id is None:
            self.res_id = Res.Unique1ID('sfnt')
        res.AddResource('sfnt', self.res_id, self.fullname)
        res.ChangedResource()

        self.createFond()
        del self.ttFont
        Res.CloseResFile(self.resref)
        self.file.close()
        self.closed = 1
Exemple #2
0
def process_common(template,
                   progress,
                   code,
                   rsrcname,
                   destname,
                   is_update,
                   copy_codefragment,
                   raw=0,
                   others=[],
                   filename=None,
                   destroot=""):
    if MacOS.runtimemodel == 'macho':
        return process_common_macho(template, progress, code, rsrcname,
                                    destname, is_update, raw, others, filename,
                                    destroot)
    if others:
        raise BuildError, "Extra files only allowed for MachoPython applets"
    # Create FSSpecs for the various files
    template_fsr, d1, d2 = Carbon.File.FSResolveAliasFile(template, 1)
    template = template_fsr.as_pathname()

    # Copy data (not resources, yet) from the template
    if progress:
        progress.label("Copy data fork...")
        progress.set(10)

    if copy_codefragment:
        tmpl = open(template, "rb")
        dest = open(destname, "wb")
        data = tmpl.read()
        if data:
            dest.write(data)
        dest.close()
        tmpl.close()
        del dest
        del tmpl

    # Open the output resource fork

    if progress:
        progress.label("Copy resources...")
        progress.set(20)
    try:
        output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)
    except MacOS.Error:
        destdir, destfile = os.path.split(destname)
        Res.FSCreateResourceFile(destdir, unicode(destfile),
                                 RESOURCE_FORK_NAME)
        output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME, WRITE)

    # Copy the resources from the target specific resource template, if any
    typesfound, ownertype = [], None
    try:
        input = Res.FSOpenResourceFile(rsrcname, RESOURCE_FORK_NAME, READ)
    except (MacOS.Error, ValueError):
        pass
        if progress:
            progress.inc(50)
    else:
        if is_update:
            skip_oldfile = ['cfrg']
        else:
            skip_oldfile = []
        typesfound, ownertype = copyres(input, output, skip_oldfile, 0,
                                        progress)
        Res.CloseResFile(input)

    # Check which resource-types we should not copy from the template
    skiptypes = []
    if 'vers' in typesfound: skiptypes.append('vers')
    if 'SIZE' in typesfound: skiptypes.append('SIZE')
    if 'BNDL' in typesfound:
        skiptypes = skiptypes + [
            'BNDL', 'FREF', 'icl4', 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#'
        ]
    if not copy_codefragment:
        skiptypes.append('cfrg')


##  skipowner = (ownertype <> None)

# Copy the resources from the template

    input = Res.FSOpenResourceFile(template, RESOURCE_FORK_NAME, READ)
    dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)

    Res.CloseResFile(input)
    ##  if ownertype == None:
    ##      raise BuildError, "No owner resource found in either resource file or template"
    # Make sure we're manipulating the output resource file now

    Res.UseResFile(output)

    if ownertype == None:
        # No owner resource in the template. We have skipped the
        # Python owner resource, so we have to add our own. The relevant
        # bundle stuff is already included in the interpret/applet template.
        newres = Res.Resource('\0')
        newres.AddResource(DEFAULT_APPLET_CREATOR, 0, "Owner resource")
        ownertype = DEFAULT_APPLET_CREATOR

    if code:
        # Delete any existing 'PYC ' resource named __main__

        try:
            res = Res.Get1NamedResource(RESTYPE, RESNAME)
            res.RemoveResource()
        except Res.Error:
            pass

        # Create the raw data for the resource from the code object
        if progress:
            progress.label("Write PYC resource...")
            progress.set(120)

        data = marshal.dumps(code)
        del code
        data = (MAGIC + '\0\0\0\0') + data

        # Create the resource and write it

        id = 0
        while id < 128:
            id = Res.Unique1ID(RESTYPE)
        res = Res.Resource(data)
        res.AddResource(RESTYPE, id, RESNAME)
        attrs = res.GetResAttrs()
        attrs = attrs | 0x04  # set preload
        res.SetResAttrs(attrs)
        res.WriteResource()
        res.ReleaseResource()

    # Close the output file

    Res.CloseResFile(output)

    # Now set the creator, type and bundle bit of the destination.
    # Done with FSSpec's, FSRef FInfo isn't good enough yet (2.3a1+)
    dest_fss = Carbon.File.FSSpec(destname)
    dest_finfo = dest_fss.FSpGetFInfo()
    dest_finfo.Creator = ownertype
    dest_finfo.Type = 'APPL'
    dest_finfo.Flags = dest_finfo.Flags | Carbon.Files.kHasBundle | Carbon.Files.kIsShared
    dest_finfo.Flags = dest_finfo.Flags & ~Carbon.Files.kHasBeenInited
    dest_fss.FSpSetFInfo(dest_finfo)

    macostools.touched(destname)
    if progress:
        progress.label("Done.")
        progress.inc(0)
Exemple #3
0
"""macgen_bin - Generate application from shared libraries"""
Exemple #4
0
def process_common(template,
                   progress,
                   code,
                   rsrcname,
                   destname,
                   is_update,
                   copy_codefragment,
                   raw=0,
                   others=[],
                   filename=None,
                   destroot=''):
    if MacOS.runtimemodel == 'macho':
        return process_common_macho(template, progress, code, rsrcname,
                                    destname, is_update, raw, others, filename,
                                    destroot)
    else:
        if others:
            raise BuildError, 'Extra files only allowed for MachoPython applets'
        template_fsr, d1, d2 = Carbon.File.FSResolveAliasFile(template, 1)
        template = template_fsr.as_pathname()
        if progress:
            progress.label('Copy data fork...')
            progress.set(10)
        if copy_codefragment:
            tmpl = open(template, 'rb')
            dest = open(destname, 'wb')
            data = tmpl.read()
            if data:
                dest.write(data)
            dest.close()
            tmpl.close()
            del dest
            del tmpl
        if progress:
            progress.label('Copy resources...')
            progress.set(20)
        try:
            output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME,
                                            WRITE)
        except MacOS.Error:
            destdir, destfile = os.path.split(destname)
            Res.FSCreateResourceFile(destdir, unicode(destfile),
                                     RESOURCE_FORK_NAME)
            output = Res.FSOpenResourceFile(destname, RESOURCE_FORK_NAME,
                                            WRITE)

        typesfound, ownertype = [], None
        try:
            input = Res.FSOpenResourceFile(rsrcname, RESOURCE_FORK_NAME, READ)
        except (MacOS.Error, ValueError):
            if progress:
                progress.inc(50)
        else:
            if is_update:
                skip_oldfile = ['cfrg']
            else:
                skip_oldfile = []
            typesfound, ownertype = copyres(input, output, skip_oldfile, 0,
                                            progress)
            Res.CloseResFile(input)

        skiptypes = []
        if 'vers' in typesfound:
            skiptypes.append('vers')
        if 'SIZE' in typesfound:
            skiptypes.append('SIZE')
        if 'BNDL' in typesfound:
            skiptypes = skiptypes + [
                'BNDL', 'FREF', 'icl4', 'icl8', 'ics4', 'ics8', 'ICN#', 'ics#'
            ]
        if not copy_codefragment:
            skiptypes.append('cfrg')
        input = Res.FSOpenResourceFile(template, RESOURCE_FORK_NAME, READ)
        dummy, tmplowner = copyres(input, output, skiptypes, 1, progress)
        Res.CloseResFile(input)
        Res.UseResFile(output)
        if ownertype is None:
            newres = Res.Resource('\x00')
            newres.AddResource(DEFAULT_APPLET_CREATOR, 0, 'Owner resource')
            ownertype = DEFAULT_APPLET_CREATOR
        if code:
            try:
                res = Res.Get1NamedResource(RESTYPE, RESNAME)
                res.RemoveResource()
            except Res.Error:
                pass

            if progress:
                progress.label('Write PYC resource...')
                progress.set(120)
            data = marshal.dumps(code)
            del code
            data = MAGIC + '\x00\x00\x00\x00' + data
            id = 0
            while id < 128:
                id = Res.Unique1ID(RESTYPE)

            res = Res.Resource(data)
            res.AddResource(RESTYPE, id, RESNAME)
            attrs = res.GetResAttrs()
            attrs = attrs | 4
            res.SetResAttrs(attrs)
            res.WriteResource()
            res.ReleaseResource()
        Res.CloseResFile(output)
        dest_fss = Carbon.File.FSSpec(destname)
        dest_finfo = dest_fss.FSpGetFInfo()
        dest_finfo.Creator = ownertype
        dest_finfo.Type = 'APPL'
        dest_finfo.Flags = dest_finfo.Flags | Carbon.Files.kHasBundle | Carbon.Files.kIsShared
        dest_finfo.Flags = dest_finfo.Flags & ~Carbon.Files.kHasBeenInited
        dest_fss.FSpSetFInfo(dest_finfo)
        macostools.touched(destname)
        if progress:
            progress.label('Done.')
            progress.inc(0)
        return
Exemple #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!"
Exemple #6
0
"""tools for BuildApplet and BuildApplication"""