1 """Create an applet from a Python script.
3 This puts up a dialog asking for a Python source file ('TEXT').
4 The output is a file with the same name but its ".py" suffix dropped.
5 It is created by copying an applet template and then adding a 'PYC '
6 resource named __main__ containing the compiled, marshalled script.
11 sys
.stdout
= sys
.stderr
22 if not sys
.executable
.startswith(sys
.exec_prefix
):
23 # Oh, the joys of using a python script to bootstrap applicatin bundles
24 # sys.executable points inside the current application bundle. Because this
25 # path contains blanks (two of them actually) this path isn't usable on
26 # #! lines. Reset sys.executable to point to the embedded python interpreter
27 sys
.executable
= os
.path
.join(sys
.prefix
,
28 'Resources/Python.app/Contents/MacOS/Python')
30 # Just in case we're not in a framework:
31 if not os
.path
.exists(sys
.executable
):
32 sys
.executable
= os
.path
.join(sys
.exec_prefix
, 'bin/python')
37 except buildtools
.BuildError
, detail
:
38 if EasyDialogs
is None:
41 EasyDialogs
.Message(detail
)
48 # (there's no point in proceeding if we can't find it)
50 template
= buildtools
.findtemplate()
52 # Ask for source text if not specified in sys.argv[1:]
55 if EasyDialogs
is None:
59 filename
= EasyDialogs
.AskFileForOpen(message
='Select Python source or applet:',
60 typeList
=('TEXT', 'APPL'))
63 tp
, tf
= os
.path
.split(filename
)
68 dstfilename
= EasyDialogs
.AskFileForSave(message
='Save application as:',
70 if not dstfilename
: return
71 cr
, tp
= MacOS
.GetCreatorAndType(filename
)
73 buildtools
.update(template
, filename
, dstfilename
)
75 buildtools
.process(template
, filename
, dstfilename
, 1)
78 SHORTOPTS
= "o:r:ne:v?PR"
79 LONGOPTS
=("output=", "resource=", "noargv", "extra=", "verbose", "help", "python=", "destroot=")
81 options
, args
= getopt
.getopt(sys
.argv
[1:], SHORTOPTS
, LONGOPTS
)
84 if options
and len(args
) > 1:
85 sys
.stderr
.write("Cannot use options when specifying multiple input files")
93 for opt
, arg
in options
:
94 if opt
in ('-o', '--output'):
96 elif opt
in ('-r', '--resource'):
98 elif opt
in ('-n', '--noargv'):
100 elif opt
in ('-e', '--extra'):
104 elif opt
in ('-P', '--python'):
105 # This is a very dirty trick. We set sys.executable
106 # so that bundlebuilder will use this in the #! line
107 # for the applet bootstrap.
109 elif opt
in ('-v', '--verbose'):
111 elif opt
in ('-?', '--help'):
113 elif opt
in ('-d', '--destroot'):
115 # On OS9 always be verbose
116 if sys
.platform
== 'mac' and not verbose
:
118 # Loop over all files to be processed
119 for filename
in args
:
120 cr
, tp
= MacOS
.GetCreatorAndType(filename
)
122 buildtools
.update(template
, filename
, dstfilename
)
124 buildtools
.process(template
, filename
, dstfilename
, 1,
125 rsrcname
=rsrcfilename
, others
=extras
, raw
=raw
,
126 progress
=verbose
, destroot
=destroot
)
129 print "BuildApplet creates an application from a Python source file"
131 print " BuildApplet interactive, single file, no options"
132 print " BuildApplet src1.py src2.py ... non-interactive multiple file"
133 print " BuildApplet [options] src.py non-interactive single file"
135 print " --output o Output file; default based on source filename, short -o"
136 print " --resource r Resource file; default based on source filename, short -r"
137 print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only"
138 print " --extra src[:dst] Extra file to put in .app bundle, short -e, OSX only"
139 print " --verbose Verbose, short -v"
140 print " --help This message, short -?"
144 """This class mimics EasyDialogs.ProgressBar but prints to stderr"""
145 def __init__(self
, *args
):
149 def set(self
, *args
):
152 def inc(self
, *args
):
155 def label(self
, str):
156 sys
.stderr
.write(str+'\n')
158 if __name__
== '__main__':