# # Copyright 2010 Leonard Thomas # # This file is part of Dodai. # # Dodai is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Dodai is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Dodai. If not, see . import os import sys import platform from setuptools import setup from setuptools import find_packages try: # This is probably Linux from ctypes.util import _findLib_ldconfig as find_library except ImportError: # This is something else (maybe Mac OS X?) from ctypes.util import find_library from subprocess import Popen, PIPE from copy import deepcopy ARGS = { 'name': 'dodai', 'version': '0.4.1', 'install_requires': [ 'sqlalchemy', 'chardet', 'couchdb', 'ordereddict', 'psycopg2', 'mysql-python', 'cx_oracle' ], 'platforms': [ 'Linux', 'Darwin', ], 'author': 'Leonard Thomas', 'author_email': 'six@choushi.net', 'url': 'http://code.google.com/p/dodai', 'download_url': 'http://code.google.com/p/dodai/downloads/list', 'license': 'GPLv3', 'classifiers': [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU Affero General Public License v3', 'Natural Language :: English', 'Operating System :: POSIX', 'Operating System :: POSIX :: Linux', 'Operating System :: MacOS', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Topic :: Database', 'Topic :: Software Development', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', ], 'description': "Module code for quick easy access to parsed text based "\ "config file data and configured database engines.", 'long_description': "This module provides code for quick easy access to "\ "parsed text based config file data and configured database "\ "engines. All config file data is returned ordered and transformed "\ "to unicode objects and database connections are returned as "\ "sqlalchemy objects.", 'entry_points': { 'distutils.commands': [ 'devstrap = dodai.build:devstrap', ] }, 'zip_safe': False, 'packages': find_packages('lib'), 'package_dir': {'':'lib'}, } PYTHON_VERSION_LOW = '2.6' PYTHON_VERSION_HIGH = '3.0' class BaseLibCheck(object): def _has_library(self, lib): if find_library(lib): return True return False def _which(self, name): cmd = ['which', name] return Popen(cmd, stdout=PIPE).communicate()[0] class PostgressLibCheck(BaseLibCheck): PACKAGE = 'psycopg2' LIB = 'pq' def __call__(self, package): if package.lower().startswith(self.PACKAGE): if self._has_library(self.LIB): return True return False class MysqlLibCheck(BaseLibCheck): PACKAGE = 'mysql-python' LIB = 'mysqlpp' def __call__(self, package): if package.lower().startswith(self.PACKAGE): if self._has_library(self.LIB): if self._which('mysql_config'): return True return False class OracleLibCheck(BaseLibCheck): PACKAGE = 'cx_oracle' LIB = 'clntsh' def __call__(self, package): if package.lower().startswith(self.PACKAGE): if 'ORACLE_HOME' in os.environ: if os.environ['ORACLE_HOME']: return True else: if self._has_library(self.LIB): self._set_oracle_home() return True return False def _set_oracle_home(self): path = find_library(self.LIB) os.environ['ORACLE_HOME'] = os.path.dirname(path) class OrderedDictLibCheck(BaseLibCheck): PACKAGE = 'ordereddict' def __call__(self, package): if package.lower().startswith(self.PACKAGE): if sys.version < '2.7': return True return False class ArgparseLibCheck(BaseLibCheck): PACKAGE = 'argparse' def __call__(self, package): if package.lower().startswith(self.PACKAGE): if sys.version < '2.7': return True return False class PassLibCheck(BaseLibCheck): def __init__(self, chain): self._packages = [] for obj in chain: self._packages.append(obj.PACKAGE.lower()) def __call__(self, package): if package.lower() not in self._packages: return True def get_install_requires(): out = [] chain = [ PostgressLibCheck(), MysqlLibCheck(), OracleLibCheck(), OrderedDictLibCheck(), ArgparseLibCheck(), ] chain.append(PassLibCheck(chain)) for package in ARGS['install_requires']: for can_install in chain: if can_install(package): out.append(package) return out def valid_python_version(): if sys.version < PYTHON_VERSION_LOW: return False if sys.version >= PYTHON_VERSION_HIGH: return False return True def build_args(): args = deepcopy(ARGS) args['install_requires'] = get_install_requires() return args if not valid_python_version(): message = """ {package} is not able to install: Because the version of Python that is being used, '{version}', is not compatable with {package}. {package} will only install with Python versions {low} through {high}\n """.format(package=ARGS['name'].lower().capitalize(), low=PYTHON_VERSION_LOW, high=PYTHON_VERSION_HIGH) sys.stderr.write(message) sys.exit(1) else: setup(**build_args())