1 """BuildCGIApplet.py -- Create a CGI applet from a Python script.
3 Specilized version of BuildApplet, enabling Python CGI scripts to be
4 used under Mac web servers like WebStar. The __main__ program is
5 PythonCGISlave.py, which provides a compatibility layer, emulating
6 Unix-style CGI scripts. See CGI_README.txt for details.
13 from Carbon
import Res
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()
33 wrapper
= "PythonCGISlave.py"
34 if not os
.path
.exists("PythonCGISlave.py"):
35 wrapper
= os
.path
.join(sys
.exec_prefix
, ":Mac:Tools:CGI", wrapper
)
37 # Ask for source text if not specified in sys.argv[1:]
39 srcfss
, ok
= macfs
.PromptGetFile('Select a CGI script:', 'TEXT', 'APPL')
42 filename
= srcfss
.as_pathname()
43 dstfilename
= mkcgifilename(filename
)
44 dstfss
, ok
= macfs
.StandardPutFile('Save application as:',
45 os
.path
.basename(dstfilename
))
48 dstfilename
= dstfss
.as_pathname()
49 buildone(template
, wrapper
, filename
, dstfilename
)
51 # Loop over all files to be processed
52 for filename
in sys
.argv
[1:]:
53 dstfilename
= mkcgifilename(filename
)
54 buildone(template
, wrapper
, filename
, dstfilename
)
57 def mkcgifilename(filename
):
58 if filename
[-3:] == '.py':
59 filename
= filename
[:-3]
60 filename
= filename
+ ".cgi"
64 def buildone(template
, wrapper
, src
, dst
):
65 buildtools
.process(template
, wrapper
, dst
, 1)
66 # write source as a PYC resource into dst
67 ref
= Res
.FSpOpenResFile(dst
, 2)
70 py_resource
.frompyfile(src
, "CGI_MAIN", preload
=1)
75 if __name__
== '__main__':