# HG changeset patch # User paulb # Date 1093806553 0 # Node ID 1d51b0705055d85b320b09e34fdc2a839e5f4595 # Parent 0e5b522c1f71ce3ffebe9e3babc2a15661e00192 [project @ 2004-08-29 19:09:13 by paulb] Moved the build.py script and deployment descriptor to the tools directory. Added notes on building the special PyServlet classes (adapted from the Jython versions). diff -r 0e5b522c1f71 -r 1d51b0705055 tools/JavaServlet/NOTES.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/JavaServlet/NOTES.txt Sun Aug 29 19:09:13 2004 +0000 @@ -0,0 +1,4 @@ +Before running build.py, compile the special PyServlet classes: + +CLASSPATH=$CATALINA_HOME/common/lib/servlet.jar:$JYTHON_HOME/jython.jar \ + javac classes/uk/org/boddie/webstack/util/PyServlet.java diff -r 0e5b522c1f71 -r 1d51b0705055 tools/JavaServlet/build.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/JavaServlet/build.py Sun Aug 29 19:09:13 2004 +0000 @@ -0,0 +1,160 @@ +#!/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 get_appname(handler): + return os.path.split(os.path.splitext(handler)[0])[1] + +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 = get_appname(handler) + print "Making", appname + + os.mkdir(appname) + os.mkdir(os.path.join(appname, "WEB-INF")) + 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 special PyServlet classes. + + copy_directory(os.path.join(webstack_home, "tools", "JavaServlet", "classes"), + os.path.join(appname, "WEB-INF")) + + # 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, "tools", "JavaServlet", "web.xml")) + web_xml = f.read() + f.close() + web_xml = web_xml % (jython_home, handler_filename) + + # 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" + print "You can also specify some additional libraries for the application..." + print " eg. $CATALINA_HOME/common/lib/activation.jar" + print " $CATALINA_HOME/common/lib/mail.jar" + sys.exit(1) + + print "Making application directory..." + make_app(sys.argv[1], sys.argv[2], sys.argv[3]) + + if len(sys.argv) > 4: + print "Copying additional libraries..." + appname = get_appname(sys.argv[1]) + for library in sys.argv[4:]: + library_dir, library_name = os.path.split(library) + library_dest = os.path.join(appname, "WEB-INF", "lib", library_name) + copy_file(library, library_dest) + + print "Now copy or move the application directory to your servlet container." + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 0e5b522c1f71 -r 1d51b0705055 tools/JavaServlet/web.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/JavaServlet/web.xml Sun Aug 29 19:09:13 2004 +0000 @@ -0,0 +1,30 @@ + + + + + WebStack application + + An application based on WebStack + + + + pyservlet + uk.org.boddie.webstack.util.PyServlet + + python.home + %s + + + servlet.file + %s + + + + + pyservlet + /* + + +