annotate Mac/scripts/BuildApplet.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents ca1e5bc5209d
children 2d67a0ba9020
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """Create an applet from a Python script.
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 This puts up a dialog asking for a Python source file ('TEXT').
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 The output is a file with the same name but its ".py" suffix dropped.
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 It is created by copying an applet template and then adding a 'PYC '
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 resource named __main__ containing the compiled, marshalled script.
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 """
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8
3062
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
9
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 import sys
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 sys.stdout = sys.stderr
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 import os
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 import macfs
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 import MacOS
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
16 import EasyDialogs
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
17 import buildtools
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18
3062
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
19
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
20 def main():
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
21 try:
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
22 buildapplet()
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
23 except buildtools.BuildError, detail:
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
24 EasyDialogs.Message(detail)
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
25
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
26
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
27 def buildapplet():
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
28 buildtools.DEBUG=1
3062
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
29
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
30 # Find the template
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
31 # (there's no point in proceeding if we can't find it)
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
32
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
33 template = buildtools.findtemplate()
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
34
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 # Ask for source text if not specified in sys.argv[1:]
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 if not sys.argv[1:]:
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
38 srcfss, ok = macfs.PromptGetFile('Select Python source or applet:', 'TEXT', 'APPL')
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 if not ok:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 return
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 filename = srcfss.as_pathname()
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 tp, tf = os.path.split(filename)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 if tf[-3:] == '.py':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 tf = tf[:-3]
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 else:
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
46 tf = tf + '.applet'
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 if not ok: return
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
49 dstfilename = dstfss.as_pathname()
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
50 cr, tp = MacOS.GetCreatorAndType(filename)
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
51 if tp == 'APPL':
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
52 buildtools.update(template, filename, dstfilename)
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
53 else:
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
54 buildtools.process(template, filename, dstfilename, 1)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 else:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 # Loop over all files to be processed
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 for filename in sys.argv[1:]:
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
59 cr, tp = MacOS.GetCreatorAndType(filename)
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
60 if tp == 'APPL':
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
61 buildtools.update(template, filename, '')
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
62 else:
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
63 buildtools.process(template, filename, '', 1)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 if __name__ == '__main__':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 main()