annotate Mac/scripts/BuildApplication.py @ 10739:e4ee8ea4e836 legacy-trunk

removed two redundant lines -- jvr
author Just van Rossum <just@lettererror.com>
date Sat, 24 Apr 1999 16:48:34 +0000
parents 44726b058700
children 32a480d0823c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8799
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """Create a standalone application from a Python script.
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 This puts up a dialog asking for a Python source file ('TEXT').
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 The output is a file with the same name but its ".py" suffix dropped.
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 It is created by copying an applet template, all used shared libs and
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 then adding 'PYC ' resources containing compiled versions of all used
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 modules wirrten in Python and the main script itself, as __main__.
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 """
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import sys
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 import string
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 import os
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 import macfs
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 import MacOS
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 import Res
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 import Dlg
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 import EasyDialogs
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 import buildtools
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 # Hmmm...
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 MACFREEZEPATH = os.path.join(sys.prefix, ":Mac:Tools:macfreeze")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 if MACFREEZEPATH not in sys.path:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 sys.path.append(MACFREEZEPATH)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 import macmodulefinder
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 import macgen_bin
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 # dialog, items
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 DLG_ID = 400
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 OK_BUTTON = 1
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 CANCEL_BUTTON = 2
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 GENFAT_BUTTON = 4
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 GENPPC_BUTTON = 5
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 GEN68K_BUTTON = 6
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 try:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 Res.GetResource('DITL', DLG_ID)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 except Res.Error:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 Res.OpenResFile("BuildApplication.rsrc")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 pass # we're an applet
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 def main():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 try:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 buildapplication()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 except buildtools.BuildError, detail:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 EasyDialogs.Message(detail)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 def buildapplication(debug = 0):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 buildtools.DEBUG = debug
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 # Ask for source text if not specified in sys.argv[1:]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 if not sys.argv[1:]:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 srcfss, ok = macfs.PromptGetFile('Select Python source:', 'TEXT')
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 filename = srcfss.as_pathname()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 if sys.argv[2:]:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 raise buildtools.BuildError, "please select one file at a time"
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 filename = sys.argv[1]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 tp, tf = os.path.split(filename)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70 # interact with user
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 architecture, ok = interact(tf)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 if tf[-3:] == '.py':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 tf = tf[:-3]
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 tf = tf + '.app'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 if not ok:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 dstfilename = dstfss.as_pathname()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 macgen_bin.generate(filename, dstfilename, None, architecture, 1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 class radio:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 def __init__(self, dlg, *items):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 self.items = {}
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 for item in items:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 tp, h, rect = dlg.GetDialogItem(item)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 self.items[item] = h.as_Control()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 def set(self, setitem):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 for item, ctl in self.items.items():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 if item == setitem:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 ctl.SetControlValue(1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 else:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 ctl.SetControlValue(0)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 def get(self):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 for item, ctl in self.items.items():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 if ctl.GetControlValue():
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 return item
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 def hasitem(self, item):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 return self.items.has_key(item)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111 def interact(scriptname):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 d = Dlg.GetNewDialog(DLG_ID, -1)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 if not d:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 print "Can't get DLOG resource with id =", DLG_ID
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 return
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 d.SetDialogDefaultItem(OK_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 d.SetDialogCancelItem(CANCEL_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 Dlg.ParamText(scriptname, "", "", "")
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 radiogroup = radio(d, GENFAT_BUTTON, GENPPC_BUTTON, GEN68K_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 radiogroup.set(GENFAT_BUTTON)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 while 1:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 n = Dlg.ModalDialog(None)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 if n == OK_BUTTON or n == CANCEL_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 break
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 elif radiogroup.hasitem(n):
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 radiogroup.set(n)
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130 genitem = radiogroup.get()
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 del radiogroup
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 del d
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 if genitem == GENFAT_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 gentype = 'fat'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 elif genitem == GENPPC_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 gentype = 'pwpc'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 elif genitem == GEN68K_BUTTON:
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 gentype = 'm68k'
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 return gentype, n == OK_BUTTON
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142 if __name__ == '__main__':
44726b058700 Build a full standalone application from a python script (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 main()