1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/JavaServlet/build.py Sat Jul 03 16:26:14 2004 +0000
1.3 @@ -0,0 +1,142 @@
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 make_app(handler, appdir, webstack_home):
1.79 +
1.80 + """
1.81 + Make the application directory from the given 'handler', application
1.82 + directory 'appdir' and the 'webstack_home' where the WebStack package can be
1.83 + found.
1.84 + """
1.85 +
1.86 + appname = os.path.split(os.path.splitext(handler)[0])[1]
1.87 + print "Making", appname
1.88 +
1.89 + os.mkdir(appname)
1.90 + os.mkdir(os.path.join(appname, "WEB-INF"))
1.91 + os.mkdir(os.path.join(appname, "WEB-INF", "classes"))
1.92 + os.mkdir(os.path.join(appname, "WEB-INF", "jython"))
1.93 + os.mkdir(os.path.join(appname, "WEB-INF", "lib"))
1.94 +
1.95 + # Copy the Jython runtime.
1.96 +
1.97 + jython_home = sys.exec_prefix
1.98 + copy_file(os.path.join(jython_home, "jython.jar"),
1.99 + os.path.join(appname, "WEB-INF", "lib", "jython.jar"))
1.100 +
1.101 + # Copy the WebStack package.
1.102 +
1.103 + copy_directory(os.path.join(webstack_home, "WebStack"),
1.104 + os.path.join(appname, "WEB-INF", "jython"))
1.105 +
1.106 + # Copy the application itself.
1.107 +
1.108 + copy_directory(appdir, os.path.join(appname, "WEB-INF", "jython"))
1.109 +
1.110 + # Copy the handler.
1.111 +
1.112 + handler_filename = os.path.split(handler)[1]
1.113 + copy_file(handler, os.path.join(appname, handler_filename))
1.114 +
1.115 + # Configure the deployment descriptor.
1.116 +
1.117 + f = open(os.path.join(webstack_home, "examples", "JavaServlet", "web.xml"))
1.118 + web_xml = f.read()
1.119 + f.close()
1.120 + web_xml = web_xml % jython_home
1.121 +
1.122 + # Write the deployment descriptor.
1.123 +
1.124 + f = open(os.path.join(appname, "WEB-INF", "web.xml"), "w")
1.125 + f.write(web_xml)
1.126 + f.close()
1.127 +
1.128 +if __name__ == "__main__":
1.129 + import sys
1.130 + if len(sys.argv) < 4:
1.131 + print "Please specify..."
1.132 + print " * The location of the application handler."
1.133 + print " eg. .../WebStack-x.y/examples/JavaServlet/SimpleApp.py"
1.134 + print " * The location of the application."
1.135 + print " eg. .../WebStack-x.y/examples/Common/Simple"
1.136 + print " * The location of the WebStack package distribution."
1.137 + print " eg. .../WebStack-x.y"
1.138 + sys.exit(1)
1.139 +
1.140 + print "Making application directory..."
1.141 + make_app(sys.argv[1], sys.argv[2], sys.argv[3])
1.142 +
1.143 + print "Now copy or move the application directory to your servlet container."
1.144 +
1.145 +# vim: tabstop=4 expandtab shiftwidth=4