# HG changeset patch
# User paulb
# Date 1088871974 0
# Node ID 8a18f94c5e53865feb5ee8f0e1a46fea24710754
# Parent bd434c81cf2a9d7c24a83fe9ee69cb0e141aa29d
[project @ 2004-07-03 16:26:14 by paulb]
Added a build script for making Jython/Java Web application directories.
Changed the deployment descriptor so that it can be configured with the
appropriate Jython "home".
diff -r bd434c81cf2a -r 8a18f94c5e53 examples/JavaServlet/build.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/JavaServlet/build.py Sat Jul 03 16:26:14 2004 +0000
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+
+"A simple Jython-based installer for the Web applications."
+
+import os
+
+def copy_file(source, destination):
+
+ """
+ Copy a file from 'source' to 'destination'. Note that 'destination' must
+ include the name of the file - it cannot be a directory name.
+ """
+
+ print "Copying", source, "to", destination
+
+ # Do things by the book, since Jython/Java won't copy the file contents in
+ # all cases presumably due to finalisation issues.
+
+ f = open(source, "rb")
+ s = f.read()
+ f.close()
+
+ f = open(destination, "wb")
+ f.write(s)
+ f.close()
+
+def recurse(dirs_and_files, dirname, names):
+
+ """
+ A recursive directory and file collector for os.path.walk. The provided
+ 'dirs_and_files' list must contain two lists (one for directory names, one
+ for filenames). The 'dirname' and 'names' parameters are supplied by the
+ os.path.walk mechanism.
+ """
+
+ if dirname.endswith("/CVS"):
+ return
+ dirs_and_files[0].append(dirname)
+ for name in names:
+ if os.path.isfile(os.path.join(dirname, name)):
+ dirs_and_files[1].append(os.path.join(dirname, name))
+
+def copy_directory(source, destination):
+
+ """
+ Copy a directory found at 'source' in the filesystem to the 'destination'.
+ Note that 'destination' is the parent directory of the newly created
+ directory.
+ """
+
+ # Remove trailing directory separators.
+
+ source = os.path.normpath(source)
+ prefix = os.path.split(source)[0]
+ dirs_and_files = [[], []]
+ os.path.walk(source, recurse, dirs_and_files)
+
+ for dirname in dirs_and_files[0]:
+
+ # Remove the prefix from the name and create the object under the destination.
+ # NOTE: Joining "" to the path in Jython doesn't add the path separator.
+
+ new_dirname = dirname[len(os.path.join(prefix, "x")) - 1:]
+ print "Making", new_dirname, "under", destination
+ os.mkdir(os.path.join(destination, new_dirname))
+
+ for filename in dirs_and_files[1]:
+
+ # Remove the prefix from the name and create the object under the destination.
+ # NOTE: Joining "" to the path in Jython doesn't add the path separator.
+
+ new_filename = filename[len(os.path.join(prefix, "x")) - 1:]
+ copy_file(filename, os.path.join(destination, new_filename))
+
+def make_app(handler, appdir, webstack_home):
+
+ """
+ Make the application directory from the given 'handler', application
+ directory 'appdir' and the 'webstack_home' where the WebStack package can be
+ found.
+ """
+
+ appname = os.path.split(os.path.splitext(handler)[0])[1]
+ print "Making", appname
+
+ os.mkdir(appname)
+ os.mkdir(os.path.join(appname, "WEB-INF"))
+ os.mkdir(os.path.join(appname, "WEB-INF", "classes"))
+ os.mkdir(os.path.join(appname, "WEB-INF", "jython"))
+ os.mkdir(os.path.join(appname, "WEB-INF", "lib"))
+
+ # Copy the Jython runtime.
+
+ jython_home = sys.exec_prefix
+ copy_file(os.path.join(jython_home, "jython.jar"),
+ os.path.join(appname, "WEB-INF", "lib", "jython.jar"))
+
+ # Copy the WebStack package.
+
+ copy_directory(os.path.join(webstack_home, "WebStack"),
+ os.path.join(appname, "WEB-INF", "jython"))
+
+ # Copy the application itself.
+
+ copy_directory(appdir, os.path.join(appname, "WEB-INF", "jython"))
+
+ # Copy the handler.
+
+ handler_filename = os.path.split(handler)[1]
+ copy_file(handler, os.path.join(appname, handler_filename))
+
+ # Configure the deployment descriptor.
+
+ f = open(os.path.join(webstack_home, "examples", "JavaServlet", "web.xml"))
+ web_xml = f.read()
+ f.close()
+ web_xml = web_xml % jython_home
+
+ # Write the deployment descriptor.
+
+ f = open(os.path.join(appname, "WEB-INF", "web.xml"), "w")
+ f.write(web_xml)
+ f.close()
+
+if __name__ == "__main__":
+ import sys
+ if len(sys.argv) < 4:
+ print "Please specify..."
+ print " * The location of the application handler."
+ print " eg. .../WebStack-x.y/examples/JavaServlet/SimpleApp.py"
+ print " * The location of the application."
+ print " eg. .../WebStack-x.y/examples/Common/Simple"
+ print " * The location of the WebStack package distribution."
+ print " eg. .../WebStack-x.y"
+ sys.exit(1)
+
+ print "Making application directory..."
+ make_app(sys.argv[1], sys.argv[2], sys.argv[3])
+
+ print "Now copy or move the application directory to your servlet container."
+
+# vim: tabstop=4 expandtab shiftwidth=4
diff -r bd434c81cf2a -r 8a18f94c5e53 examples/JavaServlet/web.xml
--- a/examples/JavaServlet/web.xml Fri Jul 02 18:06:05 2004 +0000
+++ b/examples/JavaServlet/web.xml Sat Jul 03 16:26:14 2004 +0000
@@ -12,6 +12,10 @@
pyservlet
org.python.util.PyServlet
+
+ python.home
+ %s
+