summaryrefslogtreecommitdiffstats
path: root/Mac/Tools/CGI/BuildCGIApplet.py
diff options
context:
space:
mode:
authorJust van Rossum <just@lettererror.com>2000-03-28 12:05:13 (GMT)
committerJust van Rossum <just@lettererror.com>2000-03-28 12:05:13 (GMT)
commit4011723d0d27d96dc82cf42b31576929522477b6 (patch)
tree62b6d59c7b95a32d4eee93d5de75467819435df0 /Mac/Tools/CGI/BuildCGIApplet.py
parentb7a40ba8d3f520ed49a0018272bf25ee67274fca (diff)
downloadcpython-4011723d0d27d96dc82cf42b31576929522477b6.zip
cpython-4011723d0d27d96dc82cf42b31576929522477b6.tar.gz
cpython-4011723d0d27d96dc82cf42b31576929522477b6.tar.bz2
- new version of PythonCGISlave
- new script/applet BuildCGIApplet This largely supercedes :Mac:Demos:cgi, except for the html doc file. Should it move here? Merged with CGI_README.txt? Todo: fullbuild support. (jvr)
Diffstat (limited to 'Mac/Tools/CGI/BuildCGIApplet.py')
-rw-r--r--Mac/Tools/CGI/BuildCGIApplet.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/Mac/Tools/CGI/BuildCGIApplet.py b/Mac/Tools/CGI/BuildCGIApplet.py
new file mode 100644
index 0000000..29783c2
--- /dev/null
+++ b/Mac/Tools/CGI/BuildCGIApplet.py
@@ -0,0 +1,74 @@
+"""BuildCGIApplet.py -- Create a CGI applet from a Python script.
+
+Specilized version of BuildApplet, enabling Python CGI scripts to be
+used under Mac web servers like WebStar. The __main__ program is
+PythonCGISlave.py, which provides a compatibility layer, emulating
+Unix-style CGI scripts. See CGI_README.txt for details.
+"""
+
+import sys
+import os
+import macfs
+import MacOS
+import Res
+import EasyDialogs
+import buildtools
+import py_resource
+
+
+def main():
+ try:
+ buildcgiapplet()
+ except buildtools.BuildError, detail:
+ EasyDialogs.Message(detail)
+
+
+def buildcgiapplet():
+ buildtools.DEBUG=1
+
+ # Find the template
+ # (there's no point in proceeding if we can't find it)
+
+ template = buildtools.findtemplate()
+ wrapper = os.path.join(sys.exec_prefix, ":Mac:Tools:CGI:PythonCGISlave.py")
+
+ # Ask for source text if not specified in sys.argv[1:]
+ if not sys.argv[1:]:
+ srcfss, ok = macfs.PromptGetFile('Select a CGI script:', 'TEXT', 'APPL')
+ if not ok:
+ return
+ filename = srcfss.as_pathname()
+ dstfilename = mkcgifilename(filename)
+ dstfss, ok = macfs.StandardPutFile('Save application as:',
+ os.path.basename(dstfilename))
+ if not ok:
+ return
+ dstfilename = dstfss.as_pathname()
+ buildone(template, wrapper, filename, dstfilename)
+ else:
+ # Loop over all files to be processed
+ for filename in sys.argv[1:]:
+ dstfilename = mkcgifilename(filename)
+ buildone(template, wrapper, filename, dstfilename)
+
+
+def mkcgifilename(filename):
+ if filename[-3:] == '.py':
+ filename = filename[:-3]
+ filename = filename + ".cgi"
+ return filename
+
+
+def buildone(template, wrapper, src, dst):
+ buildtools.process(template, wrapper, dst, 1)
+ # write source as a PYC resource into dst
+ ref = Res.OpenResFile(dst)
+ try:
+ Res.UseResFile(ref)
+ py_resource.frompyfile(src, "CGI_MAIN", preload=1)
+ finally:
+ Res.CloseResFile(ref)
+
+
+if __name__ == '__main__':
+ main()