Exemple #1
0
    def domenu_save_as_applet(self, *args):
        import buildtools

        buildtools.DEBUG = 0    # ouch.

        if self.title[-3:] == ".py":
            destname = self.title[:-3]
        else:
            destname = self.title + ".applet"
        destname = EasyDialogs.AskFileForSave(message='Save as Applet:',
                savedFileName=destname)
        if not destname:
            return 1
        W.SetCursor("watch")
        if self.path:
            filename = self.path
            if filename[-3:] == ".py":
                rsrcname = filename[:-3] + '.rsrc'
            else:
                rsrcname = filename + '.rsrc'
        else:
            filename = self.title
            rsrcname = ""

        pytext = self.editgroup.editor.get()
        pytext = string.split(pytext, '\r')
        pytext = string.join(pytext, '\n') + '\n'
        try:
            code = compile(pytext, filename, "exec")
        except (SyntaxError, EOFError):
            raise buildtools.BuildError, "Syntax error in script %r" % (filename,)

        import tempfile
        tmpdir = tempfile.mkdtemp()

        if filename[-3:] != ".py":
            filename = filename + ".py"
        filename = os.path.join(tmpdir, os.path.split(filename)[1])
        fp = open(filename, "w")
        fp.write(pytext)
        fp.close()

        # Try removing the output file
        try:
            os.remove(destname)
        except os.error:
            pass
        template = buildtools.findtemplate()
        buildtools.process(template, filename, destname, 1, rsrcname=rsrcname, progress=None)
        try:
            os.remove(filename)
            os.rmdir(tmpdir)
        except os.error:
            pass
Exemple #2
0
def build_app(filename):
    template = buildtools.findtemplate()
    dstfilename = None
    rsrcfilename = None
    raw = 0
    extras = []
    verbose = None
    destroot = ''

    buildtools.process(template, filename, dstfilename, 1,
                       rsrcname=rsrcfilename, others=extras, raw=raw,
                       progress=verbose, destroot=destroot)
Exemple #3
0
    def build_app(self, filename):
        print filename
        template = buildtools.findtemplate()
        dstfilename = None
        rsrcfilename = None
        raw = 0
        extras = []
        verbose = None
        destroot = ''

        cr, tp = MacOS.GetCreatorAndType(filename)
        if tp == 'APPL':
            buildtools.update(template, filename, dstfilename)
        else:
            buildtools.process(template, filename, dstfilename, 1,
                               rsrcname=rsrcfilename, others=extras, raw=raw,
                               progress=verbose, destroot=destroot)
Exemple #4
0
    def build_app(self, filename):
        print filename
        template = buildtools.findtemplate()
        dstfilename = None
        rsrcfilename = None
        raw = 0
        extras = []
        verbose = None
        destroot = ''

        cr, tp = MacOS.GetCreatorAndType(filename)
        if tp == 'APPL':
            buildtools.update(template, filename, dstfilename)
        else:
            buildtools.process(template, filename, dstfilename, 1,
                               rsrcname=rsrcfilename, others=extras, raw=raw,
                               progress=verbose, destroot=destroot)
Exemple #5
0
def build_app(filename):
    template = buildtools.findtemplate()
    dstfilename = None
    rsrcfilename = None
    raw = 0
    extras = []
    verbose = None
    destroot = ''

    buildtools.process(template,
                       filename,
                       dstfilename,
                       1,
                       rsrcname=rsrcfilename,
                       others=extras,
                       raw=raw,
                       progress=verbose,
                       destroot=destroot)
Exemple #6
0
"""macgen_bin - Generate application from shared libraries"""
Exemple #7
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 #8
0
# This python script creates Finder aliases for all the
Exemple #9
0
"""macgen_bin - Generate application from shared libraries"""
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 #11
0
"""BuildCGIApplet.py -- Create a CGI applet from a Python script.
Exemple #12
0
"""Create an applet from a Python script.
Exemple #13
0
"""BuildCGIApplet.py -- Create a CGI applet from a Python script.
Exemple #14
0
import sys
import os
import buildtools
from Carbon import Res
import py_resource

buildtools.DEBUG=1

template = buildtools.findtemplate()

ide_home = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")

mainfilename = os.path.join(ide_home, "PythonIDE.py")
dstfilename = os.path.join(sys.exec_prefix, "Python IDE")

buildtools.process(template, mainfilename, dstfilename, 1)

targetref = Res.FSpOpenResFile(dstfilename, 3)
Res.UseResFile(targetref)

files = os.listdir(ide_home)

# skip this script and the main program
files = filter(lambda x: x[-3:] == '.py' and
                x not in ("BuildIDE.py", "PythonIDE.py"), files)

# add the modules as PYC resources
for name in files:
    print "adding", name
    fullpath = os.path.join(ide_home, name)
    id, name = py_resource.frompyfile(fullpath, name[:-3], preload=1,
Exemple #15
0
#
Exemple #16
0
def buildapplet():
    buildtools.DEBUG = 1

    # Find the template
    # (there's no point in proceeding if we can't find it)

    template = buildtools.findtemplate()

    # Ask for source text if not specified in sys.argv[1:]

    if not sys.argv[1:]:
        filename = EasyDialogs.AskFileForOpen(
            message='Select Python source or applet:',
            typeList=('TEXT', 'APPL'))
        if not filename:
            return
        tp, tf = os.path.split(filename)
        if tf[-3:] == '.py':
            tf = tf[:-3]
        else:
            tf = tf + '.applet'
        dstfilename = EasyDialogs.AskFileForSave(
            message='Save application as:', savedFileName=tf)
        if not dstfilename: return
        cr, tp = MacOS.GetCreatorAndType(filename)
        if tp == 'APPL':
            buildtools.update(template, filename, dstfilename)
        else:
            buildtools.process(template, filename, dstfilename, 1)
    else:

        SHORTOPTS = "o:r:ne:v?PR"
        LONGOPTS = ("output=", "resource=", "noargv", "extra=", "verbose",
                    "help", "python=", "destroot=")
        try:
            options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
        except getopt.error:
            usage()
        if options and len(args) > 1:
            sys.stderr.write(
                "Cannot use options when specifying multiple input files")
            sys.exit(1)
        dstfilename = None
        rsrcfilename = None
        raw = 0
        extras = []
        verbose = None
        destroot = ''
        for opt, arg in options:
            if opt in ('-o', '--output'):
                dstfilename = arg
            elif opt in ('-r', '--resource'):
                rsrcfilename = arg
            elif opt in ('-n', '--noargv'):
                raw = 1
            elif opt in ('-e', '--extra'):
                if ':' in arg:
                    arg = arg.split(':')
                extras.append(arg)
            elif opt in ('-P', '--python'):
                # This is a very dirty trick. We set sys.executable
                # so that bundlebuilder will use this in the #! line
                # for the applet bootstrap.
                sys.executable = arg
            elif opt in ('-v', '--verbose'):
                verbose = Verbose()
            elif opt in ('-?', '--help'):
                usage()
            elif opt in ('-d', '--destroot'):
                destroot = arg
        # On OS9 always be verbose
        if sys.platform == 'mac' and not verbose:
            verbose = 'default'
        # Loop over all files to be processed
        for filename in args:
            cr, tp = MacOS.GetCreatorAndType(filename)
            if tp == 'APPL':
                buildtools.update(template, filename, dstfilename)
            else:
                buildtools.process(template,
                                   filename,
                                   dstfilename,
                                   1,
                                   rsrcname=rsrcfilename,
                                   others=extras,
                                   raw=raw,
                                   progress=verbose,
                                   destroot=destroot)
Exemple #17
0
import sys
import os
import buildtools
from Carbon import Res
import py_resource

buildtools.DEBUG = 1

template = buildtools.findtemplate()

ide_home = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")

mainfilename = os.path.join(ide_home, "PythonIDE.py")
dstfilename = os.path.join(sys.exec_prefix, "Python IDE")

buildtools.process(template, mainfilename, dstfilename, 1)

targetref = Res.FSpOpenResFile(dstfilename, 3)
Res.UseResFile(targetref)

files = os.listdir(ide_home)

# skip this script and the main program
files = filter(
    lambda x: x[-3:] == '.py' and x not in ("BuildIDE.py", "PythonIDE.py"),
    files)

# add the modules as PYC resources
for name in files:
    print "adding", name
    fullpath = os.path.join(ide_home, name)
Exemple #18
0
# This python script creates Finder aliases for all the
def buildapplet():
    buildtools.DEBUG=1

    # Find the template
    # (there's no point in proceeding if we can't find it)

    template = buildtools.findtemplate()

    # Ask for source text if not specified in sys.argv[1:]

    if not sys.argv[1:]:
        filename = EasyDialogs.AskFileForOpen(message='Select Python source or applet:',
                typeList=('TEXT', 'APPL'))
        if not filename:
            return
        tp, tf = os.path.split(filename)
        if tf[-3:] == '.py':
            tf = tf[:-3]
        else:
            tf = tf + '.applet'
        dstfilename = EasyDialogs.AskFileForSave(message='Save application as:',
                savedFileName=tf)
        if not dstfilename: return
        cr, tp = MacOS.GetCreatorAndType(filename)
        if tp == 'APPL':
            buildtools.update(template, filename, dstfilename)
        else:
            buildtools.process(template, filename, dstfilename, 1)
    else:

        SHORTOPTS = "o:r:ne:v?PR"
        LONGOPTS=("output=", "resource=", "noargv", "extra=", "verbose", "help", "python=", "destroot=")
        try:
            options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
        except getopt.error:
            usage()
        if options and len(args) > 1:
            sys.stderr.write("Cannot use options when specifying multiple input files")
            sys.exit(1)
        dstfilename = None
        rsrcfilename = None
        raw = 0
        extras = []
        verbose = None
        destroot = ''
        for opt, arg in options:
            if opt in ('-o', '--output'):
                dstfilename = arg
            elif opt in ('-r', '--resource'):
                rsrcfilename = arg
            elif opt in ('-n', '--noargv'):
                raw = 1
            elif opt in ('-e', '--extra'):
                if ':' in arg:
                    arg = arg.split(':')
                extras.append(arg)
            elif opt in ('-P', '--python'):
                # This is a very dirty trick. We set sys.executable
                # so that bundlebuilder will use this in the #! line
                # for the applet bootstrap.
                sys.executable = arg
            elif opt in ('-v', '--verbose'):
                verbose = Verbose()
            elif opt in ('-?', '--help'):
                usage()
            elif opt in ('-d', '--destroot'):
                destroot = arg
        # On OS9 always be verbose
        if sys.platform == 'mac' and not verbose:
            verbose = 'default'
        # Loop over all files to be processed
        for filename in args:
            cr, tp = MacOS.GetCreatorAndType(filename)
            if tp == 'APPL':
                buildtools.update(template, filename, dstfilename)
            else:
                buildtools.process(template, filename, dstfilename, 1,
                        rsrcname=rsrcfilename, others=extras, raw=raw,
                        progress=verbose, destroot=destroot)
Exemple #20
0
#