194 DB2 Deployment Guide
We have assumed that Python is installed on the deployment machine, and that
the user has sufficient read and write permissions to install setuptools and
driver eggs. We place the egg files setuptools-0.6c7-py2.5.egg and
ibm_db-0.2.9-py2.5-linux-x86_64.egg under python_deploy/gem.
You also have to prepare the DB2 driver files. We discuss how to prepare the
redistributable driver files in “Preparing the redistributable driver files” on
page 159. This procedure can also be applied for preparing the DB2 ODBC and
CLI drivers for Python to be deployed along with the application. The script
requires a slight modification. In this example, we gather the required DB2 driver
files under pythony_deploy/odbcdrv and zip them in a package itso_cli.tar.gz.
Preparing the Python application package
The application is usually under some type of library control system and can be
gathered easily. In our example, we only have a simple Python application file
itso_pyapp.py for demonstration purpose. We place it under /python_deploy/bin.
Preparing the deployment package
To automate the application deployment as much as we can, we create a
deployment script, python_app_install. The script copies the application file to
specified path and installs the gem file. It also extracts ODBC and CLI driver files
to specified path and performs environmental configuration.
Example 4-27 shows the deployment script. There are two command line options
for the scr ipt:
򐂰The flag -p specifies the location where application to be deployed.
򐂰The flag -r registers required system variables.
Example 4-34 Code of script py_app_install
#!/usr/bin/ksh
##########################################################################
#
# Deploy application and ODBC CLI driver files to target path
#
# py_app_install -p <installpath> -r
#
# -p specify the location where application and ODBC drv files to be deployed
# -r specify to configure system variable for ODBC and CLI driver
#
# example: py_app_install -p /home/db2app/myapp -r"
#
##########################################################################
#set -x
# Define variables
DIR_DRV=odbcdrv # directory for odbc and cli driver files
DIR_APP=bin # directory for applications