# HG changeset patch # User paulb # Date 1093806527 0 # Node ID 0e5b522c1f71ce3ffebe9e3babc2a15661e00192 # Parent 8283b2d7776d5c3bf01238246c1312b16f6874c3 [project @ 2004-08-29 19:08:47 by paulb] Moved the build.py script and deployment descriptor to the tools directory. diff -r 8283b2d7776d -r 0e5b522c1f71 examples/JavaServlet/build.py --- a/examples/JavaServlet/build.py Sun Aug 29 19:08:11 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,156 +0,0 @@ -#!/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", "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" - 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 8283b2d7776d -r 0e5b522c1f71 examples/JavaServlet/web.xml --- a/examples/JavaServlet/web.xml Sun Aug 29 19:08:11 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ - - - - - WebStack application - - An application based on WebStack - - - - pyservlet - org.python.util.PyServlet - - python.home - %s - - - - - pyservlet - *.py - - -