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 except buildtools
.BuildError
, detail
:
23 EasyDialogs
.Message(detail
)
30 # (there's no point in proceeding if we can't find it)
32 template
= buildtools
.findtemplate()
34 # Ask for source text if not specified in sys.argv[1:]
37 filename
= EasyDialogs
.AskFileForOpen(message
='Select Python source or applet:',
38 typeList
=('TEXT', 'APPL'))
41 tp
, tf
= os
.path
.split(filename
)
46 dstfilename
= EasyDialogs
.AskFileForSave(message
='Save application as:',
48 if not dstfilename
: return
49 cr
, tp
= MacOS
.GetCreatorAndType(filename
)
51 buildtools
.update(template
, filename
, dstfilename
)
53 buildtools
.process(template
, filename
, dstfilename
, 1)
56 SHORTOPTS
= "o:r:ne:v?"
57 LONGOPTS
=("output=", "resource=", "noargv", "extra=", "verbose", "help")
59 options
, args
= getopt
.getopt(sys
.argv
[1:], SHORTOPTS
, LONGOPTS
)
62 if options
and len(args
) > 1:
63 sys
.stderr
.write("Cannot use options when specifying multiple input files")
70 for opt
, arg
in options
:
71 if opt
in ('-o', '--output'):
73 elif opt
in ('-r', '--resource'):
75 elif opt
in ('-n', '--noargv'):
77 elif opt
in ('-e', '--extra'):
79 elif opt
in ('-v', '--verbose'):
81 elif opt
in ('-?', '--help'):
83 # On OS9 always be verbose
84 if sys
.platform
== 'mac' and not verbose
:
86 # Loop over all files to be processed
88 cr
, tp
= MacOS
.GetCreatorAndType(filename
)
90 buildtools
.update(template
, filename
, dstfilename
)
92 buildtools
.process(template
, filename
, dstfilename
, 1,
93 rsrcname
=rsrcfilename
, others
=extras
, raw
=raw
, progress
=verbose
)
96 print "BuildApplet creates an application from a Python source file"
98 print " BuildApplet interactive, single file, no options"
99 print " BuildApplet src1.py src2.py ... non-interactive multiple file"
100 print " BuildApplet [options] src.py non-interactive single file"
102 print " --output o Output file; default based on source filename, short -o"
103 print " --resource r Resource file; default based on source filename, short -r"
104 print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only"
105 print " --extra f Extra file to put in .app bundle, short -e, OSX only"
106 print " --verbose Verbose, short -v"
107 print " --help This message, short -?"
111 """This class mimics EasyDialogs.ProgressBar but prints to stderr"""
112 def __init__(self
, *args
):
116 def set(self
, *args
):
119 def inc(self
, *args
):
122 def label(self
, str):
123 sys
.stderr
.write(str+'\n')
125 if __name__
== '__main__':