setup.py :  » Database » PyDB2 » PyDB2_1.1.1 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyDB2 
PyDB2 » PyDB2_1.1.1 » setup.py
#
#    PyDB2 Distutils Setup
#    Man-Yong Lee <yong@linuxkorea.co.kr>, 2002
#    Dave Hughes - wadahu, 2007

from distutils.core import setup,Extension

import sys
import os

# Specifiy your DB2 root if auto-find doesn't work, for example:
# DB2_ROOT = "/opt/IBM/db2/V8.1/"
DB2_ROOT = ""

def find_db2rootdir():
    # Check various environment variables, depending on platform.
    if sys.platform[:5] == 'win32':
        # In Windows, DB2PATH is set to the installation path. DB2TEMPDIR is
        # usually (bizarrely) also set to the installation path, in 8dot3
        # notation
        if 'DB2PATH' in os.environ:
            print "Found DB2 with DB2PATH"
            return os.environ['DB2PATH']
        if 'DB2TEMPDIR' in os.environ:
            print "Found DB2 with DB2TEMPDIR"
            return os.environ['DB2TEMPDIR']
    else:
        # In UNIX, DB2DIR is usually set in the environment of any
        # "DB2-enabled" user (a user which has sourced
        # insthome/sqllib/db2profile). Unfortunately, it is not usually
        # exported, so is not available to the Python environment. Still, it's
        # worth a shot...
        if 'DB2DIR' in os.environ:
            print "Found DB2 with DB2DIR"
            return os.environ['DB2DIR']
    # If the above fails, attempt to run the db2level command and parse the
    # last line of output which is of the form 'Product is installed at
    # "/opt/ibm/db2/V9.1"'. The first part is localizable, so we need to
    # extract the quoted part at the end. This command should be in the path of
    # any "DB2-enabled" user (see above)
    f = os.popen('db2level')
    s = f.read()
    if not f.close() and len(s) > 0:
        s = [i.strip() for i in s.split('\n') if i.strip() != ''][-1]
        s = s[s.find('"')+1:]
        s = s[:s.rfind('"')]
        if os.path.exists(s):
            print "Found DB2 with db2level"
            return s
    # If all the above has failed, try searching some standard locations,
    # depending on platform
    if sys.platform[:5] == 'win32':
        try:
            root = os.environ['ProgramFiles']
        except KeyError:
            pass
        else:
            for path in [os.path.join(root, 'SQLLIB'), os.path.join(root, 'IBM', 'SQLLIB')]:
                if os.path.exists(path):
                    print "Found DB2 with standard location search"
                    return path
    else:
        for root in ['/opt/IBM/db2', '/opt/ibm/db2', '/usr/IBMdb2']:
            if os.path.exists(root):
                files = os.listdir(root)
                for path in files:
                    if path[:1] == "V" and path.find(".") > 0:
                        print "Found DB2 with standard location search"
                        return os.path.join(root, path)
    # Finally, try the user-specified DB2_ROOT variable
    if os.path.exists(DB2_ROOT):
        print "Found DB2 with user-specified variable"
        return DB2_ROOT
    # Give up noisily
    raise Exception('Unable to locate DB2 installation directory.\nTry editing DB2_ROOT in setup.py')

def find_db2libdir():
    # In DB2 v8 and below, the library directory is always "lib". In DB2 v9,
    # the library directory is either lib32 or lib64. According to some, a
    # "lib" symlink should point to the appropriate dir, but it certainly
    # doesn't in the installs I've seen...
    for path in ['lib', 'lib32', 'lib64']:
        if os.path.exists(os.path.join(db2rootdir, path)):
            return os.path.join(db2rootdir, path)
    # Give up noisily
    raise Exception('Unable to locate DB2 lib directory')

def find_db2lib():
    if sys.platform[:5] == 'win32':
        return 'db2cli'
    else:
        return 'db2'

db2rootdir = find_db2rootdir()
print 'DB2 install path: "%s"' % db2rootdir
db2includedir = os.path.join(db2rootdir, 'include')
print 'DB2 include path: "%s"' % db2includedir
db2libdir = find_db2libdir()
print 'DB2 lib path:     "%s"' % db2libdir
db2lib = find_db2lib()
print 'DB2 library:      "%s"' % db2lib

if not os.path.exists(os.path.join(db2includedir, 'sqlcli1.h')):
    print """WARNING:
It seems that you did not install the 'Application Development Kit'.
Compilation may fail."""

setup(
    name="PyDB2",
    version="1.1.1",
    description="Python module for IBM DB2",
    author="Man-Yong (Bryan) Lee",
    author_email="manyong.lee@gmail.com",
    url="http://sourceforge.net/projects/pydb2/",
    maintainer="Jon Thoroddsen",
    maintainer_email="jon.thoroddsen@gmail.com",
    license="LGPL",
    package_dir={'DB2': os.curdir},
    py_modules=['DB2'],
    ext_modules=[
        Extension(
            "_db2",
            ["_db2_module.c"],
            include_dirs=[db2includedir],
            library_dirs=[db2libdir],
            libraries=[db2lib],
            )
        ],
    )

# FIN

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.