summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1998-07-31 09:44:58 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1998-07-31 09:44:58 (GMT)
commitb44f1cca6c9d4b7902b91abd9953a5b0a405e477 (patch)
tree789c0e1a1bb4397a2b41793fb1b9dd9ed6f73d91 /Mac
parent015b70ec93fea7e65a3bda83455afe74f169d111 (diff)
downloadcpython-b44f1cca6c9d4b7902b91abd9953a5b0a405e477.zip
cpython-b44f1cca6c9d4b7902b91abd9953a5b0a405e477.tar.gz
cpython-b44f1cca6c9d4b7902b91abd9953a5b0a405e477.tar.bz2
Build a full standalone application from a python script (Just)
Diffstat (limited to 'Mac')
-rw-r--r--Mac/scripts/BuildApplication.py145
-rw-r--r--Mac/scripts/BuildApplication.rsrc.hqx44
2 files changed, 189 insertions, 0 deletions
diff --git a/Mac/scripts/BuildApplication.py b/Mac/scripts/BuildApplication.py
new file mode 100644
index 0000000..957bf6c
--- /dev/null
+++ b/Mac/scripts/BuildApplication.py
@@ -0,0 +1,145 @@
+"""Create a standalone application from a Python script.
+
+This puts up a dialog asking for a Python source file ('TEXT').
+The output is a file with the same name but its ".py" suffix dropped.
+It is created by copying an applet template, all used shared libs and
+then adding 'PYC ' resources containing compiled versions of all used
+modules wirrten in Python and the main script itself, as __main__.
+"""
+
+
+import sys
+
+import string
+import os
+import macfs
+import MacOS
+import Res
+import Dlg
+import EasyDialogs
+import buildtools
+
+# Hmmm...
+MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze")
+if MACFREEZEPATH not in sys.path:
+ sys.path.append(MACFREEZEPATH)
+
+import macmodulefinder
+import macgen_bin
+
+# dialog, items
+DLG_ID = 400
+OK_BUTTON = 1
+CANCEL_BUTTON = 2
+GENFAT_BUTTON = 4
+GENPPC_BUTTON = 5
+GEN68K_BUTTON = 6
+
+
+try:
+ Res.GetResource('DITL', DLG_ID)
+except Res.Error:
+ Res.OpenResFile("BuildApplication.rsrc")
+else:
+ pass # we're an applet
+
+
+def main():
+ try:
+ buildapplication()
+ except buildtools.BuildError, detail:
+ EasyDialogs.Message(detail)
+
+
+def buildapplication(debug = 0):
+ buildtools.DEBUG = debug
+
+ # Ask for source text if not specified in sys.argv[1:]
+
+ if not sys.argv[1:]:
+ srcfss, ok = macfs.PromptGetFile('Select Python source:', 'TEXT')
+ if not ok:
+ return
+ filename = srcfss.as_pathname()
+ else:
+ if sys.argv[2:]:
+ raise buildtools.BuildError, "please select one file at a time"
+ filename = sys.argv[1]
+ tp, tf = os.path.split(filename)
+
+ # interact with user
+ architecture, ok = interact(tf)
+ if not ok:
+ return
+ if tf[-3:] == '.py':
+ tf = tf[:-3]
+ logfile = tf[:-3] + '.log'
+ else:
+ tf = tf + '.app'
+ logfile = tf + '.log'
+
+ dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
+ if not ok:
+ return
+ dstfilename = dstfss.as_pathname()
+
+ macgen_bin.generate(filename, dstfilename, None, architecture, 1)
+
+
+class radio:
+
+ def __init__(self, dlg, *items):
+ self.items = {}
+ for item in items:
+ tp, h, rect = dlg.GetDialogItem(item)
+ self.items[item] = h.as_Control()
+
+ def set(self, setitem):
+ for item, ctl in self.items.items():
+ if item == setitem:
+ ctl.SetControlValue(1)
+ else:
+ ctl.SetControlValue(0)
+
+ def get(self):
+ for item, ctl in self.items.items():
+ if ctl.GetControlValue():
+ return item
+
+ def hasitem(self, item):
+ return self.items.has_key(item)
+
+
+def interact(scriptname):
+ d = Dlg.GetNewDialog(DLG_ID, -1)
+ if not d:
+ print "Can't get DLOG resource with id =", DLG_ID
+ return
+ d.SetDialogDefaultItem(OK_BUTTON)
+ d.SetDialogCancelItem(CANCEL_BUTTON)
+ Dlg.ParamText(scriptname, "", "", "")
+
+ radiogroup = radio(d, GENFAT_BUTTON, GENPPC_BUTTON, GEN68K_BUTTON)
+ radiogroup.set(GENFAT_BUTTON)
+
+ gentype = 'fat'
+ while 1:
+ n = Dlg.ModalDialog(None)
+ if n == OK_BUTTON or n == CANCEL_BUTTON:
+ break
+ elif radiogroup.hasitem(n):
+ radiogroup.set(n)
+ genitem = radiogroup.get()
+ del radiogroup
+ del d
+ if genitem == GENFAT_BUTTON:
+ gentype = 'fat'
+ elif genitem == GENPPC_BUTTON:
+ gentype = 'pwpc'
+ elif genitem == GEN68K_BUTTON:
+ gentype = 'm68k'
+ return gentype, n == OK_BUTTON
+
+
+if __name__ == '__main__':
+ main()
diff --git a/Mac/scripts/BuildApplication.rsrc.hqx b/Mac/scripts/BuildApplication.rsrc.hqx
new file mode 100644
index 0000000..a4daf83
--- /dev/null
+++ b/Mac/scripts/BuildApplication.rsrc.hqx
@@ -0,0 +1,44 @@
+(This file must be converted with BinHex 4.0)
+
+:&8*eD@aN3A"`E'PMBA4TEfiZFR0bB`"bFh*M8P0&4!%!N!F-R2!m!*!%!3!!!!Y
+(!!!+4`!!!98f&#"8)'J!&#"3I4'`D"%!1J&R*K)[$%kk!J`-1J"DH49#G@PXC%&
+`F'aTBf&dD@pZ,R*cFQ-#!!!!8'&bG&0*!!"3BA*d8dP8)3#3',(QTJ-!N!B-R2m
+4`+KT!4e!%Irc%h!!%#lrmlh5%@B386Dq9@X"!8*%[D'q9@X"!6"4-J&R(N39$!!
+!('85F!!3,N-9$!!!(f)'F!&J!!%"!LaD9#dZ4,d"!"Xm!@B`*e8q'NU!)&-#+!#
+r!#iL!1d*!J%!3)-Sfc36UGF[$%kk!3P+CfX"!+CA3cS!!!%!N!Y!!!!!S!!!!9!
+!!!+S!!!%9!!!#53!!"+8!!2rr`!%!!#!!rrr!!%!!J!"!!)!!3!$!!%!!q!"!!-
+J!3!#)!%!!L!$rrmZ"!!![J2rr`i!V!3!!Di)!!(q%!!!%#!!!!K!!!!%J!!!!`#
+3'%!!!!$J!!!"m!!!!rJ!!!Im!!!2r!!!(r`!!rrr!!Irri!$rrm!!Irq!!(rrJ!
+"rrm!!Irri!(rrb!"rriJ!Irq)!2rr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