1.1 --- a/tools/JavaServlet/build.py Fri Jun 09 22:59:35 2006 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,162 +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, web_xml_template_name):
1.82 -
1.83 - """
1.84 - Make the application directory from the given 'handler', application
1.85 - directory 'appdir', the 'webstack_home' where the WebStack package can be
1.86 - found, and the deployment descriptor with the given 'web_xml_template_name'.
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", "jython"))
1.95 - os.mkdir(os.path.join(appname, "WEB-INF", "lib"))
1.96 -
1.97 - # Copy the Jython runtime.
1.98 -
1.99 - jython_home = sys.exec_prefix
1.100 - copy_file(os.path.join(jython_home, "jython.jar"),
1.101 - os.path.join(appname, "WEB-INF", "lib", "jython.jar"))
1.102 -
1.103 - # Copy the special PyServlet classes.
1.104 -
1.105 - copy_directory(os.path.join(webstack_home, "tools", "JavaServlet", "classes"),
1.106 - os.path.join(appname, "WEB-INF"))
1.107 -
1.108 - # Copy the WebStack package.
1.109 -
1.110 - copy_directory(os.path.join(webstack_home, "WebStack"),
1.111 - os.path.join(appname, "WEB-INF", "jython"))
1.112 -
1.113 - # Copy the application itself.
1.114 -
1.115 - copy_directory(appdir, os.path.join(appname, "WEB-INF", "jython"))
1.116 -
1.117 - # Copy the handler.
1.118 -
1.119 - handler_filename = os.path.split(handler)[1]
1.120 - copy_file(handler, os.path.join(appname, handler_filename))
1.121 -
1.122 - # Configure the deployment descriptor.
1.123 -
1.124 - f = open(os.path.join(webstack_home, "tools", "JavaServlet", web_xml_template_name))
1.125 - web_xml = f.read()
1.126 - f.close()
1.127 - web_xml = web_xml % (jython_home, handler_filename)
1.128 -
1.129 - # Write the deployment descriptor.
1.130 -
1.131 - f = open(os.path.join(appname, "WEB-INF", "web.xml"), "w")
1.132 - f.write(web_xml)
1.133 - f.close()
1.134 -
1.135 -if __name__ == "__main__":
1.136 - import sys
1.137 - if len(sys.argv) < 5:
1.138 - print "Please specify..."
1.139 - print " * The location of the application handler."
1.140 - print " eg. .../WebStack-x.y/examples/JavaServlet/SimpleApp.py"
1.141 - print " * The location of the application."
1.142 - print " eg. .../WebStack-x.y/examples/Common/Simple"
1.143 - print " * The location of the WebStack package distribution."
1.144 - print " eg. .../WebStack-x.y"
1.145 - print " * The name of the deployment descriptor template."
1.146 - print " eg. web.xml"
1.147 - print "You can also specify some additional libraries for the application..."
1.148 - print " eg. $CATALINA_HOME/common/lib/activation.jar"
1.149 - print " $CATALINA_HOME/common/lib/mail.jar"
1.150 - sys.exit(1)
1.151 -
1.152 - print "Making application directory..."
1.153 - make_app(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
1.154 -
1.155 - if len(sys.argv) > 5:
1.156 - print "Copying additional libraries..."
1.157 - appname = get_appname(sys.argv[1])
1.158 - for library in sys.argv[5:]:
1.159 - library_dir, library_name = os.path.split(library)
1.160 - library_dest = os.path.join(appname, "WEB-INF", "lib", library_name)
1.161 - copy_file(library, library_dest)
1.162 -
1.163 - print "Now copy or move the application directory to your servlet container."
1.164 -
1.165 -# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tools/JavaServlet/webstack_java_build.py Fri Jun 09 22:59:38 2006 +0000
2.3 @@ -0,0 +1,164 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"A simple Jython-based installer for the Web applications."
2.7 +
2.8 +import os
2.9 +
2.10 +def copy_file(source, destination):
2.11 +
2.12 + """
2.13 + Copy a file from 'source' to 'destination'. Note that 'destination' must
2.14 + include the name of the file - it cannot be a directory name.
2.15 + """
2.16 +
2.17 + print "Copying", source, "to", destination
2.18 +
2.19 + # Do things by the book, since Jython/Java won't copy the file contents in
2.20 + # all cases presumably due to finalisation issues.
2.21 +
2.22 + f = open(source, "rb")
2.23 + s = f.read()
2.24 + f.close()
2.25 +
2.26 + f = open(destination, "wb")
2.27 + f.write(s)
2.28 + f.close()
2.29 +
2.30 +def recurse(dirs_and_files, dirname, names):
2.31 +
2.32 + """
2.33 + A recursive directory and file collector for os.path.walk. The provided
2.34 + 'dirs_and_files' list must contain two lists (one for directory names, one
2.35 + for filenames). The 'dirname' and 'names' parameters are supplied by the
2.36 + os.path.walk mechanism.
2.37 + """
2.38 +
2.39 + if dirname.endswith("/CVS"):
2.40 + return
2.41 + dirs_and_files[0].append(dirname)
2.42 + for name in names:
2.43 + if os.path.isfile(os.path.join(dirname, name)):
2.44 + dirs_and_files[1].append(os.path.join(dirname, name))
2.45 +
2.46 +def copy_directory(source, destination):
2.47 +
2.48 + """
2.49 + Copy a directory found at 'source' in the filesystem to the 'destination'.
2.50 + Note that 'destination' is the parent directory of the newly created
2.51 + directory.
2.52 + """
2.53 +
2.54 + # Remove trailing directory separators.
2.55 +
2.56 + source = os.path.normpath(source)
2.57 + prefix = os.path.split(source)[0]
2.58 + dirs_and_files = [[], []]
2.59 + os.path.walk(source, recurse, dirs_and_files)
2.60 +
2.61 + for dirname in dirs_and_files[0]:
2.62 +
2.63 + # Remove the prefix from the name and create the object under the destination.
2.64 + # NOTE: Joining "" to the path in Jython doesn't add the path separator.
2.65 +
2.66 + new_dirname = dirname[len(os.path.join(prefix, "x")) - 1:]
2.67 + print "Making", new_dirname, "under", destination
2.68 + os.mkdir(os.path.join(destination, new_dirname))
2.69 +
2.70 + for filename in dirs_and_files[1]:
2.71 +
2.72 + # Remove the prefix from the name and create the object under the destination.
2.73 + # NOTE: Joining "" to the path in Jython doesn't add the path separator.
2.74 +
2.75 + new_filename = filename[len(os.path.join(prefix, "x")) - 1:]
2.76 + copy_file(filename, os.path.join(destination, new_filename))
2.77 +
2.78 +def get_appname(handler):
2.79 + return os.path.split(os.path.splitext(handler)[0])[1]
2.80 +
2.81 +def make_app(handler, appdir, webstack_home, web_xml_template_name):
2.82 +
2.83 + """
2.84 + Make the application directory from the given 'handler', application
2.85 + directory 'appdir', the 'webstack_home' where the WebStack package can be
2.86 + found, and the deployment descriptor with the given 'web_xml_template_name'.
2.87 + """
2.88 +
2.89 + appname = get_appname(handler)
2.90 + print "Making", appname
2.91 +
2.92 + os.mkdir(appname)
2.93 + os.mkdir(os.path.join(appname, "WEB-INF"))
2.94 + os.mkdir(os.path.join(appname, "WEB-INF", "jython"))
2.95 + os.mkdir(os.path.join(appname, "WEB-INF", "lib"))
2.96 +
2.97 + # Copy the Jython runtime.
2.98 +
2.99 + jython_home = sys.exec_prefix
2.100 + copy_file(os.path.join(jython_home, "jython.jar"),
2.101 + os.path.join(appname, "WEB-INF", "lib", "jython.jar"))
2.102 +
2.103 + # Copy the special PyServlet classes.
2.104 +
2.105 + copy_directory(os.path.join(webstack_home, "tools", "JavaServlet", "classes"),
2.106 + os.path.join(appname, "WEB-INF"))
2.107 +
2.108 + # Copy the WebStack package.
2.109 +
2.110 + copy_directory(os.path.join(webstack_home, "WebStack"),
2.111 + os.path.join(appname, "WEB-INF", "jython"))
2.112 +
2.113 + # Copy the application itself.
2.114 +
2.115 + copy_directory(appdir, os.path.join(appname, "WEB-INF", "jython"))
2.116 +
2.117 + # Copy the handler.
2.118 +
2.119 + handler_filename = os.path.split(handler)[1]
2.120 + copy_file(handler, os.path.join(appname, handler_filename))
2.121 +
2.122 + # Configure the deployment descriptor.
2.123 +
2.124 + f = open(os.path.join(webstack_home, "tools", "JavaServlet", web_xml_template_name))
2.125 + web_xml = f.read()
2.126 + f.close()
2.127 + web_xml = web_xml % (jython_home, handler_filename)
2.128 +
2.129 + # Write the deployment descriptor.
2.130 +
2.131 + f = open(os.path.join(appname, "WEB-INF", "web.xml"), "w")
2.132 + f.write(web_xml)
2.133 + f.close()
2.134 +
2.135 +if __name__ == "__main__":
2.136 + import sys
2.137 + if len(sys.argv) < 5:
2.138 + print "Please specify..."
2.139 + print " * The location of the application handler."
2.140 + print " eg. .../WebStack-x.y/examples/JavaServlet/SimpleApp.py"
2.141 + print " * The location of the application."
2.142 + print " eg. .../WebStack-x.y/examples/Common/Simple"
2.143 + print " * The location of the WebStack package distribution or where"
2.144 + print " WebStack documentation and extras have been installed."
2.145 + print " eg. .../WebStack-x.y"
2.146 + print " eg. /usr/share/doc/python2.4-webstack"
2.147 + print " * The name of the deployment descriptor template."
2.148 + print " eg. web.xml"
2.149 + print "You can also specify some additional libraries for the application..."
2.150 + print " eg. $CATALINA_HOME/common/lib/activation.jar"
2.151 + print " $CATALINA_HOME/common/lib/mail.jar"
2.152 + sys.exit(1)
2.153 +
2.154 + print "Making application directory..."
2.155 + make_app(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
2.156 +
2.157 + if len(sys.argv) > 5:
2.158 + print "Copying additional libraries..."
2.159 + appname = get_appname(sys.argv[1])
2.160 + for library in sys.argv[5:]:
2.161 + library_dir, library_name = os.path.split(library)
2.162 + library_dest = os.path.join(appname, "WEB-INF", "lib", library_name)
2.163 + copy_file(library, library_dest)
2.164 +
2.165 + print "Now copy or move the application directory to your servlet container."
2.166 +
2.167 +# vim: tabstop=4 expandtab shiftwidth=4