annotate Mac/scripts/BuildApplet.py @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 6eb5e1a09b95
children 823d5b1f32e1
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 MacOS
5489
2d133280129f Use ProgressBar to show progress in stead of print
Jack Jansen <jack.jansen@cwi.nl>
parents: 4311
diff changeset
15 import EasyDialogs
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
16 import buildtools
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
17 import getopt
3062
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
18
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
19 def main():
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
20 try:
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
21 buildapplet()
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
22 except buildtools.BuildError, detail:
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
23 EasyDialogs.Message(detail)
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
24
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 def buildapplet():
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
27 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
28
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
29 # Find the template
8d5179277858 Slightly reorganized so it is useable from another program, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3045
diff changeset
30 # (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
31
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
32 template = buildtools.findtemplate()
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
33
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 # 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
35
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 if not sys.argv[1:]:
27343
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 26235
diff changeset
37 filename = EasyDialogs.AskFileForOpen(message='Select Python source or applet:',
27404
6eb5e1a09b95 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27343
diff changeset
38 typeList=('TEXT', 'APPL'))
27343
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 26235
diff changeset
39 if not filename:
2873
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 tp, tf = os.path.split(filename)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 if tf[-3:] == '.py':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 tf = tf[:-3]
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 else:
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
45 tf = tf + '.applet'
27343
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 26235
diff changeset
46 dstfilename = EasyDialogs.AskFileForSave(message='Save application as:',
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 26235
diff changeset
47 savedFileName=tf)
412e66e3530e Getting rid of StandardGetFile
Jack Jansen <jack.jansen@cwi.nl>
parents: 26235
diff changeset
48 if not dstfilename: return
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
49 cr, tp = MacOS.GetCreatorAndType(filename)
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
50 if tp == 'APPL':
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
51 buildtools.update(template, filename, dstfilename)
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
52 else:
8798
ca1e5bc5209d Common code used to the buildtools module (Just)
Jack Jansen <jack.jansen@cwi.nl>
parents: 8106
diff changeset
53 buildtools.process(template, filename, dstfilename, 1)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 else:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
56 SHORTOPTS = "o:r:ne:v?"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
57 LONGOPTS=("output=", "resource=", "noargv", "extra=", "verbose", "help")
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
58 try:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
59 options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
60 except getopt.error:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
61 usage()
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
62 if options and len(args) > 1:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
63 sys.stderr.write("Cannot use options when specifying multiple input files")
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
64 sys.exit(1)
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
65 dstfilename = None
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
66 rsrcfilename = None
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
67 raw = 0
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
68 extras = []
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
69 verbose = None
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
70 for opt, arg in options:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
71 if opt in ('-o', '--output'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
72 dstfilename = arg
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
73 elif opt in ('-r', '--resource'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
74 rsrcfilename = arg
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
75 elif opt in ('-n', '--noargv'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
76 raw = 1
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
77 elif opt in ('-e', '--extra'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
78 extras.append(arg)
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
79 elif opt in ('-v', '--verbose'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
80 verbose = Verbose()
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
81 elif opt in ('-?', '--help'):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
82 usage()
24974
7190348d466d For MacPython-OS9 verbose is the default.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23748
diff changeset
83 # On OS9 always be verbose
7190348d466d For MacPython-OS9 verbose is the default.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23748
diff changeset
84 if sys.platform == 'mac' and not verbose:
7190348d466d For MacPython-OS9 verbose is the default.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23748
diff changeset
85 verbose = 'default'
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 # Loop over all files to be processed
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
87 for filename in args:
27404
6eb5e1a09b95 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27343
diff changeset
88 cr, tp = MacOS.GetCreatorAndType(filename)
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
89 if tp == 'APPL':
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
90 buildtools.update(template, filename, dstfilename)
7441
a8059b96bc35 BuildApplet will now also update old applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 5489
diff changeset
91 else:
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
92 buildtools.process(template, filename, dstfilename, 1,
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
93 rsrcname=rsrcfilename, others=extras, raw=raw, progress=verbose)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94
23748
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
95 def usage():
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
96 print "BuildApplet creates an application from a Python source file"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
97 print "Usage:"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
98 print " BuildApplet interactive, single file, no options"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
99 print " BuildApplet src1.py src2.py ... non-interactive multiple file"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
100 print " BuildApplet [options] src.py non-interactive single file"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
101 print "Options:"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
102 print " --output o Output file; default based on source filename, short -o"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
103 print " --resource r Resource file; default based on source filename, short -r"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
104 print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
105 print " --extra f Extra file to put in .app bundle, short -e, OSX only"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
106 print " --verbose Verbose, short -v"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
107 print " --help This message, short -?"
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
108 sys.exit(1)
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
109
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
110 class Verbose:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
111 """This class mimics EasyDialogs.ProgressBar but prints to stderr"""
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
112 def __init__(self, *args):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
113 if args and args[0]:
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
114 self.label(args[0])
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
115
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
116 def set(self, *args):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
117 pass
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
118
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
119 def inc(self, *args):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
120 pass
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
121
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
122 def label(self, str):
2d67a0ba9020 - Better commandline interface to BuildApplet, complete with options,
Jack Jansen <jack.jansen@cwi.nl>
parents: 8798
diff changeset
123 sys.stderr.write(str+'\n')
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 if __name__ == '__main__':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 main()