1.1 --- a/examples/JavaServlet/build.py Sun Aug 29 19:08:11 2004 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,156 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"A simple Jython-based installer for the Web applications."
1.7 -
1.8 -import os
1.9 -
1.10 -def copy_file(source, destination):
1.11 -
1.12 - """
1.13 - Copy a file from 'source' to 'destination'. Note that 'destination' must
1.14 - include the name of the file - it cannot be a directory name.
1.15 - """
1.16 -
1.17 - print "Copying", source, "to", destination
1.18 -
1.19 - # Do things by the book, since Jython/Java won't copy the file contents in
1.20 - # all cases presumably due to finalisation issues.
1.21 -
1.22 - f = open(source, "rb")
1.23 - s = f.read()
1.24 - f.close()
1.25 -
1.26 - f = open(destination, "wb")
1.27 - f.write(s)
1.28 - f.close()
1.29 -
1.30 -def recurse(dirs_and_files, dirname, names):
1.31 -
1.32 - """
1.33 - A recursive directory and file collector for os.path.walk. The provided
1.34 - 'dirs_and_files' list must contain two lists (one for directory names, one
1.35 - for filenames). The 'dirname' and 'names' parameters are supplied by the
1.36 - os.path.walk mechanism.
1.37 - """
1.38 -
1.39 - if dirname.endswith("/CVS"):
1.40 - return
1.41 - dirs_and_files[0].append(dirname)
1.42 - for name in names:
1.43 - if os.path.isfile(os.path.join(dirname, name)):
1.44 - dirs_and_files[1].append(os.path.join(dirname, name))
1.45 -
1.46 -def copy_directory(source, destination):
1.47 -
1.48 - """
1.49 - Copy a directory found at 'source' in the filesystem to the 'destination'.
1.50 - Note that 'destination' is the parent directory of the newly created
1.51 - directory.
1.52 - """
1.53 -
1.54 - # Remove trailing directory separators.
1.55 -
1.56 - source = os.path.normpath(source)
1.57 - prefix = os.path.split(source)[0]
1.58 - dirs_and_files = [[], []]
1.59 - os.path.walk(source, recurse, dirs_and_files)
1.60 -
1.61 - for dirname in dirs_and_files[0]:
1.62 -
1.63 - # Remove the prefix from the name and create the object under the destination.
1.64 - # NOTE: Joining "" to the path in Jython doesn't add the path separator.
1.65 -
1.66 - new_dirname = dirname[len(os.path.join(prefix, "x")) - 1:]
1.67 - print "Making", new_dirname, "under", destination
1.68 - os.mkdir(os.path.join(destination, new_dirname))
1.69 -
1.70 - for filename in dirs_and_files[1]:
1.71 -
1.72 - # Remove the prefix from the name and create the object under the destination.
1.73 - # NOTE: Joining "" to the path in Jython doesn't add the path separator.
1.74 -
1.75 - new_filename = filename[len(os.path.join(prefix, "x")) - 1:]
1.76 - copy_file(filename, os.path.join(destination, new_filename))
1.77 -
1.78 -def get_appname(handler):
1.79 - return os.path.split(os.path.splitext(handler)[0])[1]
1.80 -
1.81 -def make_app(handler, appdir, webstack_home):
1.82 -
1.83 - """
1.84 - Make the application directory from the given 'handler', application
1.85 - directory 'appdir' and the 'webstack_home' where the WebStack package can be
1.86 - found.
1.87 - """
1.88 -
1.89 - appname = get_appname(handler)
1.90 - print "Making", appname
1.91 -
1.92 - os.mkdir(appname)
1.93 - os.mkdir(os.path.join(appname, "WEB-INF"))
1.94 - os.mkdir(os.path.join(appname, "WEB-INF", "classes"))
1.95 - os.mkdir(os.path.join(appname, "WEB-INF", "jython"))
1.96 - os.mkdir(os.path.join(appname, "WEB-INF", "lib"))
1.97 -
1.98 - # Copy the Jython runtime.
1.99 -
1.100 - jython_home = sys.exec_prefix
1.101 - copy_file(os.path.join(jython_home, "jython.jar"),
1.102 - os.path.join(appname, "WEB-INF", "lib", "jython.jar"))
1.103 -
1.104 - # Copy the WebStack package.
1.105 -
1.106 - copy_directory(os.path.join(webstack_home, "WebStack"),
1.107 - os.path.join(appname, "WEB-INF", "jython"))
1.108 -
1.109 - # Copy the application itself.
1.110 -
1.111 - copy_directory(appdir, os.path.join(appname, "WEB-INF", "jython"))
1.112 -
1.113 - # Copy the handler.
1.114 -
1.115 - handler_filename = os.path.split(handler)[1]
1.116 - copy_file(handler, os.path.join(appname, handler_filename))
1.117 -
1.118 - # Configure the deployment descriptor.
1.119 -
1.120 - f = open(os.path.join(webstack_home, "examples", "JavaServlet", "web.xml"))
1.121 - web_xml = f.read()
1.122 - f.close()
1.123 - web_xml = web_xml % jython_home
1.124 -
1.125 - # Write the deployment descriptor.
1.126 -
1.127 - f = open(os.path.join(appname, "WEB-INF", "web.xml"), "w")
1.128 - f.write(web_xml)
1.129 - f.close()
1.130 -
1.131 -if __name__ == "__main__":
1.132 - import sys
1.133 - if len(sys.argv) < 4:
1.134 - print "Please specify..."
1.135 - print " * The location of the application handler."
1.136 - print " eg. .../WebStack-x.y/examples/JavaServlet/SimpleApp.py"
1.137 - print " * The location of the application."
1.138 - print " eg. .../WebStack-x.y/examples/Common/Simple"
1.139 - print " * The location of the WebStack package distribution."
1.140 - print " eg. .../WebStack-x.y"
1.141 - print "You can also specify some additional libraries for the application..."
1.142 - print " eg. $CATALINA_HOME/common/lib/activation.jar"
1.143 - print " $CATALINA_HOME/common/lib/mail.jar"
1.144 - sys.exit(1)
1.145 -
1.146 - print "Making application directory..."
1.147 - make_app(sys.argv[1], sys.argv[2], sys.argv[3])
1.148 -
1.149 - if len(sys.argv) > 4:
1.150 - print "Copying additional libraries..."
1.151 - appname = get_appname(sys.argv[1])
1.152 - for library in sys.argv[4:]:
1.153 - library_dir, library_name = os.path.split(library)
1.154 - library_dest = os.path.join(appname, "WEB-INF", "lib", library_name)
1.155 - copy_file(library, library_dest)
1.156 -
1.157 - print "Now copy or move the application directory to your servlet container."
1.158 -
1.159 -# vim: tabstop=4 expandtab shiftwidth=4