aboutsummaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py216
1 files changed, 216 insertions, 0 deletions
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..7cae721
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,216 @@
1#
2# Copyright 2010 Leonard Thomas
3#
4# This file is part of Dodai.
5#
6# Dodai is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# Dodai is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
18
19import os
20import sys
21import platform
22from setuptools import setup
23from setuptools import find_packages
24from ctypes.util import find_library
25from ctypes.util import _findLib_ldconfig as find_library_ldconfig
26from subprocess import Popen, PIPE
27from copy import deepcopy
28
29ARGS = {
30 'name': 'dodai',
31 'version': '0.4.1',
32 'install_requires': [
33 'sqlalchemy',
34 'chardet',
35 'couchdb',
36 'ordereddict',
37 'psycopg2',
38 'mysql-python',
39 'cx_oracle'
40 ],
41 'platforms': [
42 'Linux',
43 'Darwin',
44 ],
45 'author': 'Leonard Thomas',
46 'author_email': 'six@choushi.net',
47 'url': 'http://code.google.com/p/dodai',
48 'download_url': 'http://code.google.com/p/dodai/downloads/list',
49 'license': 'GPLv3',
50 'classifiers': [
51 'Development Status :: 4 - Beta',
52 'Intended Audience :: Developers',
53 'License :: OSI Approved :: GNU Affero General Public License v3',
54 'Natural Language :: English',
55 'Operating System :: POSIX',
56 'Operating System :: POSIX :: Linux',
57 'Operating System :: MacOS',
58 'Programming Language :: Python',
59 'Programming Language :: Python :: 2.6',
60 'Programming Language :: Python :: 2.7',
61 'Topic :: Database',
62 'Topic :: Software Development',
63 'Topic :: Software Development :: Libraries',
64 'Topic :: Software Development :: Libraries :: Python Modules',
65 ],
66 'description': "Module code for quick easy access to parsed text based "\
67 "config file data and configured database engines.",
68 'long_description': "This module provides code for quick easy access to "\
69 "parsed text based config file data and configured database "\
70 "engines. All config file data is returned ordered and transformed "\
71 "to unicode objects and database connections are returned as "\
72 "sqlalchemy objects.",
73 'entry_points': {
74 'distutils.commands': [
75 'devstrap = dodai.build:devstrap',
76 ]
77 },
78 'zip_safe': False,
79 'packages': find_packages('lib'),
80 'package_dir': {'':'lib'},
81}
82PYTHON_VERSION_LOW = '2.6'
83PYTHON_VERSION_HIGH = '3.0'
84
85class BaseLibCheck(object):
86
87 def _has_library(self, lib):
88 if find_library(lib):
89 return True
90 return False
91
92 def _which(self, name):
93 cmd = ['which', name]
94 return Popen(cmd, stdout=PIPE).communicate()[0]
95
96
97class PostgressLibCheck(BaseLibCheck):
98
99 PACKAGE = 'psycopg2'
100 LIB = 'pq'
101
102 def __call__(self, package):
103 if package.lower().startswith(self.PACKAGE):
104 if self._has_library(self.LIB):
105 return True
106 return False
107
108
109class MysqlLibCheck(BaseLibCheck):
110
111 PACKAGE = 'mysql-python'
112 LIB = 'mysqlpp'
113
114 def __call__(self, package):
115 if package.lower().startswith(self.PACKAGE):
116 if self._has_library(self.LIB):
117 if self._which('mysql_config'):
118 return True
119 return False
120
121
122class OracleLibCheck(BaseLibCheck):
123
124 PACKAGE = 'cx_oracle'
125 LIB = 'clntsh'
126
127 def __call__(self, package):
128 if package.lower().startswith(self.PACKAGE):
129 if 'ORACLE_HOME' in os.environ:
130 if os.environ['ORACLE_HOME']:
131 return True
132 else:
133 if self._has_library(self.LIB):
134 self._set_oracle_home()
135 return True
136 return False
137
138 def _set_oracle_home(self):
139 path = find_library_ldconfig(self.LIB)
140 os.environ['ORACLE_HOME'] = os.path.dirname(path)
141
142
143class OrderedDictLibCheck(BaseLibCheck):
144
145 PACKAGE = 'ordereddict'
146
147 def __call__(self, package):
148 if package.lower().startswith(self.PACKAGE):
149 if sys.version < '2.7':
150 return True
151 return False
152
153
154class ArgparseLibCheck(BaseLibCheck):
155
156 PACKAGE = 'argparse'
157
158 def __call__(self, package):
159 if package.lower().startswith(self.PACKAGE):
160 if sys.version < '2.7':
161 return True
162 return False
163
164
165class PassLibCheck(BaseLibCheck):
166
167 def __init__(self, chain):
168 self._packages = []
169 for obj in chain:
170 self._packages.append(obj.PACKAGE.lower())
171
172 def __call__(self, package):
173 if package.lower() not in self._packages:
174 return True
175
176def get_install_requires():
177 out = []
178 chain = [
179 PostgressLibCheck(),
180 MysqlLibCheck(),
181 OracleLibCheck(),
182 OrderedDictLibCheck(),
183 ArgparseLibCheck(),
184 ]
185 chain.append(PassLibCheck(chain))
186 for package in ARGS['install_requires']:
187 for can_install in chain:
188 if can_install(package):
189 out.append(package)
190 return out
191
192def valid_python_version():
193 if sys.version < PYTHON_VERSION_LOW:
194 return False
195 if sys.version >= PYTHON_VERSION_HIGH:
196 return False
197 return True
198
199def build_args():
200 args = deepcopy(ARGS)
201 args['install_requires'] = get_install_requires()
202 return args
203
204if not valid_python_version():
205 message = """
206 {package} is not able to install: Because the version of
207 Python that is being used, '{version}', is not compatable
208 with {package}. {package} will only install with Python
209 versions {low} through {high}\n
210 """.format(package=ARGS['name'].lower().capitalize(),
211 low=PYTHON_VERSION_LOW, high=PYTHON_VERSION_HIGH)
212 sys.stderr.write(message)
213 sys.exit(1)
214else:
215 setup(**build_args())
216