|
1
|
1 |
import sys |
|
|
2 |
import os |
|
|
3 |
import os.path |
|
|
4 |
import shutil |
|
|
5 |
import tarfile |
|
|
6 |
import zipfile |
|
|
7 |
import urllib |
|
|
8 |
import platform |
|
|
9 |
import patch |
|
|
10 |
|
|
|
11 |
join = os.path.join |
|
|
12 |
system_str = platform.system() |
|
|
13 |
|
|
|
14 |
|
|
|
15 |
URLS = { |
|
|
16 |
#'': {'setup': '', 'url':'', 'local':''}, |
|
|
17 |
'SQLALCHEMY' : {'setup': 'SQLAlchemy', 'url':'http://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.7.3.tar.gz', 'local':'SQLAlchemy-0.7.3.tar.gz'}, |
|
|
18 |
'FLASK' : {'setup': 'flask', 'url':'http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz', 'local':'Flask-0.8.tar.gz'}, |
|
|
19 |
'FLASK-SQLALCHEMY' : {'setup': 'flask', 'url':'https://github.com/mitsuhiko/flask-sqlalchemy/tarball/master', 'local':'Flask-SQLAlchemy-0.15.tar.gz'}, |
|
|
20 |
'FLASK-CACHE' : { 'setup': 'Flask-Cache', 'url' : 'http://pypi.python.org/packages/source/F/Flask-Cache/Flask-Cache-0.3.4.tar.gz', 'local':'Flask-Cache-0.3.4.tar.gz'}, |
|
|
21 |
'SIMPLEJSON' : {'setup': 'simplejson', 'url':'http://pypi.python.org/packages/source/s/simplejson/simplejson-2.2.1.tar.gz', 'local':'simplejson-2.2.1.tar.gz'}, |
|
|
22 |
'ANYJSON' : {'setup': 'anyjson', 'url': 'http://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.1.tar.gz', 'local':'anyjson-0.3.1.tar.gz'}, |
|
|
23 |
'WERKZEUG' : { 'setup': 'werkzeug', 'url':'http://pypi.python.org/packages/source/W/Werkzeug/Werkzeug-0.8.1.tar.gz','local':'Werkzeug-0.8.1.tar.gz'}, |
|
|
24 |
'JINJA2' : { 'setup': 'jinja2', 'url':'http://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.6.tar.gz','local':'Jinja2-2.6.tar.gz'}, |
|
|
25 |
'PYTZ' : { 'setup':'pytz', 'url': 'http://pypi.python.org/packages/source/p/pytz/pytz-2011n.tar.bz2', 'local': 'pytz-2011n.tar.bz2'}, |
|
28
|
26 |
'RFC3339' : { 'setup':'pyRFC3339', 'url': 'http://pypi.python.org/packages/source/p/pyRFC3339/pyRFC3339-0.1.tar.gz', 'local': 'pyRFC3339-0.1.tar.gz'}, |
|
|
27 |
'IRI_TWEET' : { 'setup':'iri_tweet', 'url': 'iri_tweet.tar.gz', 'local': 'iri_tweet.tar.gz'}, |
|
1
|
28 |
} |
|
|
29 |
|
|
|
30 |
if system_str == 'Windows': |
|
|
31 |
URLS.update({ |
|
|
32 |
'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip', 'local':"psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip"}, |
|
|
33 |
}) |
|
|
34 |
else: |
|
|
35 |
URLS.update({ |
|
|
36 |
'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz', 'local':"psycopg2-2.4.2.tar.gz"}, |
|
|
37 |
}) |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
class ResourcesEnv(object): |
|
|
42 |
|
|
|
43 |
def __init__(self, src_base, urls, normal_installs): |
|
|
44 |
self.src_base = src_base |
|
|
45 |
self.URLS = {} |
|
|
46 |
self.__init_url(urls) |
|
|
47 |
self.NORMAL_INSTALL = normal_installs |
|
|
48 |
|
|
|
49 |
def get_src_base_path(self, fpath): |
|
|
50 |
return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
|
51 |
|
|
|
52 |
def __add_package_def(self, key, setup, url, local): |
|
|
53 |
self.URLS[key] = {'setup':setup, 'url':url, 'local':self.get_src_base_path(local)} |
|
|
54 |
|
|
|
55 |
def __init_url(self, urls): |
|
|
56 |
for key, url_dict in urls.items(): |
|
|
57 |
url = url_dict['url'] |
|
|
58 |
if not url.startswith("http://"): |
|
|
59 |
url = self.get_src_base_path(url) |
|
|
60 |
self.__add_package_def(key, url_dict["setup"], url, url_dict["local"]) |
|
|
61 |
|
|
|
62 |
def ensure_dir(dir, logger): |
|
|
63 |
if not os.path.exists(dir): |
|
|
64 |
logger.notify('Creating directory %s' % dir) |
|
|
65 |
os.makedirs(dir) |
|
|
66 |
|
|
|
67 |
def extend_parser(parser): |
|
|
68 |
parser.add_option( |
|
|
69 |
'--index-url', |
|
|
70 |
metavar='INDEX_URL', |
|
|
71 |
dest='index_url', |
|
|
72 |
default='http://pypi.python.org/simple/', |
|
|
73 |
help='base URL of Python Package Index') |
|
|
74 |
parser.add_option( |
|
|
75 |
'--type-install', |
|
|
76 |
metavar='type_install', |
|
|
77 |
dest='type_install', |
|
|
78 |
default='local', |
|
|
79 |
help='type install : local, url, setup') |
|
|
80 |
parser.add_option( |
|
|
81 |
'--ignore-packages', |
|
|
82 |
metavar='ignore_packages', |
|
|
83 |
dest='ignore_packages', |
|
|
84 |
default=None, |
|
|
85 |
help='list of comma separated keys for package to ignore') |
|
|
86 |
|
|
|
87 |
def adjust_options(options, args): |
|
|
88 |
pass |
|
|
89 |
|
|
|
90 |
|
|
|
91 |
def install_pylucene(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
|
92 |
|
|
|
93 |
logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key]) |
|
|
94 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
|
95 |
if res_source_key == 'local': |
|
|
96 |
shutil.copy(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
|
97 |
else: |
|
|
98 |
urllib.urlretrieve(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
|
99 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
|
100 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
|
101 |
logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
|
102 |
tf.extractall(pylucene_base_path) |
|
|
103 |
tf.close() |
|
|
104 |
|
|
|
105 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
|
106 |
jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
|
107 |
|
|
|
108 |
#install jcc |
|
|
109 |
|
|
|
110 |
#patch for linux |
|
|
111 |
if system_str == 'Linux' : |
|
|
112 |
olddir = os.getcwd() |
|
|
113 |
setuptools_path = os.path.join(lib_dir, 'site-packages', 'setuptools') |
|
|
114 |
if os.path.exists(setuptools_path) and os.path.isdir(setuptools_path): |
|
|
115 |
patch_dest_path = os.path.join(lib_dir, 'site-packages') |
|
|
116 |
else: |
|
|
117 |
patch_dest_path = os.path.join(lib_dir,'site-packages','setuptools-0.6c11-py%s.%s.egg' % (sys.version_info[0], sys.version_info[1])) |
|
|
118 |
if os.path.isfile(patch_dest_path): |
|
|
119 |
# must unzip egg |
|
|
120 |
# rename file and etract all |
|
|
121 |
shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
|
122 |
zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
|
123 |
zf.extractall(patch_dest_path) |
|
|
124 |
os.remove(patch_dest_path + ".zip") |
|
|
125 |
logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
|
126 |
os.chdir(patch_dest_path) |
|
|
127 |
p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
|
128 |
p.apply() |
|
|
129 |
os.chdir(olddir) |
|
|
130 |
|
|
|
131 |
logger.notify("Install jcc") |
|
|
132 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
|
133 |
cwd=jcc_src_path, |
|
|
134 |
filter_stdout=filter_python_develop, |
|
|
135 |
show_stdout=True) |
|
|
136 |
#install pylucene |
|
|
137 |
|
|
|
138 |
logger.notify("Install pylucene") |
|
|
139 |
#modify makefile |
|
|
140 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
|
141 |
logger.notify("Modify makefile %s " % makefile_path) |
|
|
142 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
|
143 |
|
|
|
144 |
destination= open( makefile_path, "w" ) |
|
|
145 |
source= open( makefile_path+"~", "r" ) |
|
|
146 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\n") |
|
|
147 |
destination.write("ANT=ant\n") |
|
|
148 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\n") |
|
|
149 |
|
|
|
150 |
if system_str == "Darwin": |
|
|
151 |
if sys.version_info >= (2,6): |
|
|
152 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
|
153 |
else: |
|
|
154 |
destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\n") |
|
|
155 |
destination.write("NUM_FILES=2\n") |
|
|
156 |
elif system_str == "Windows": |
|
|
157 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
|
158 |
destination.write("NUM_FILES=2\n") |
|
|
159 |
else: |
|
|
160 |
if sys.version_info >= (2,6) and sys.version_info <= (2,7): |
|
|
161 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\n") |
|
|
162 |
else: |
|
|
163 |
destination.write("JCC=$(PYTHON) -m jcc --shared\n") |
|
|
164 |
destination.write("NUM_FILES=2\n") |
|
|
165 |
for line in source: |
|
|
166 |
destination.write( line ) |
|
|
167 |
source.close() |
|
|
168 |
destination.close() |
|
|
169 |
os.remove(makefile_path+"~" ) |
|
|
170 |
|
|
|
171 |
logger.notify("pylucene make") |
|
|
172 |
call_subprocess(['make'], |
|
|
173 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
174 |
filter_stdout=filter_python_develop, |
|
|
175 |
show_stdout=True) |
|
|
176 |
|
|
|
177 |
logger.notify("pylucene make install") |
|
|
178 |
call_subprocess(['make', 'install'], |
|
|
179 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
180 |
filter_stdout=filter_python_develop, |
|
|
181 |
show_stdout=True) |
|
|
182 |
|
|
|
183 |
|
|
|
184 |
def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
|
185 |
psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
|
186 |
shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
|
187 |
#extract psycopg2 |
|
|
188 |
zf = zipfile.ZipFile(psycopg2_src) |
|
|
189 |
psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
|
190 |
zf.extractall(psycopg2_base_path) |
|
|
191 |
zf.close() |
|
|
192 |
|
|
|
193 |
psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
|
194 |
shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2'))) |
|
|
195 |
shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.14-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages'))) |
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, urls=None): |
|
|
200 |
|
|
|
201 |
all_urls = URLS.copy() |
|
|
202 |
if urls is not None: |
|
|
203 |
all_urls.update(urls) |
|
|
204 |
|
|
|
205 |
res_env = ResourcesEnv(src_base, all_urls, normal_installs) |
|
|
206 |
|
|
|
207 |
def filter_python_develop(line): |
|
|
208 |
if not line.strip(): |
|
|
209 |
return Logger.DEBUG |
|
|
210 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
211 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
212 |
'creating ', 'Copying ']: |
|
|
213 |
if line.startswith(prefix): |
|
|
214 |
return Logger.DEBUG |
|
|
215 |
return Logger.NOTIFY |
|
|
216 |
|
|
|
217 |
|
|
|
218 |
def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
|
|
219 |
logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method)) |
|
|
220 |
if method == 'pip': |
|
|
221 |
if sys.platform == 'win32': |
|
|
222 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
|
|
223 |
else: |
|
|
224 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
|
|
225 |
if option_str : |
|
|
226 |
args.insert(4,option_str) |
|
|
227 |
call_subprocess(args, |
|
|
228 |
cwd=os.path.abspath(tmp_dir), |
|
|
229 |
filter_stdout=filter_python_develop, |
|
|
230 |
show_stdout=True, |
|
|
231 |
extra_env=extra_env) |
|
|
232 |
else: |
|
|
233 |
if sys.platform == 'win32': |
|
|
234 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]] |
|
|
235 |
else: |
|
|
236 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]] |
|
|
237 |
if option_str : |
|
|
238 |
args.insert(1,option_str) |
|
|
239 |
call_subprocess(args, |
|
|
240 |
cwd=os.path.abspath(tmp_dir), |
|
|
241 |
filter_stdout=filter_python_develop, |
|
|
242 |
show_stdout=True, |
|
|
243 |
extra_env=extra_env) |
|
|
244 |
|
|
|
245 |
|
|
|
246 |
def after_install(options, home_dir): |
|
|
247 |
|
|
|
248 |
global logger |
|
|
249 |
|
|
|
250 |
verbosity = options.verbose - options.quiet |
|
|
251 |
logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
|
|
252 |
|
|
|
253 |
|
|
|
254 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
|
255 |
base_dir = os.path.dirname(home_dir) |
|
|
256 |
src_dir = os.path.join(home_dir, 'src') |
|
|
257 |
tmp_dir = os.path.join(home_dir, 'tmp') |
|
|
258 |
ensure_dir(src_dir, logger) |
|
|
259 |
ensure_dir(tmp_dir, logger) |
|
|
260 |
system_str = platform.system() |
|
|
261 |
|
|
|
262 |
res_source_key = options.type_install |
|
|
263 |
|
|
|
264 |
ignore_packages = [] |
|
|
265 |
|
|
|
266 |
if options.ignore_packages : |
|
|
267 |
ignore_packages = options.ignore_packages.split(",") |
|
|
268 |
|
|
|
269 |
logger.indent += 2 |
|
|
270 |
try: |
|
|
271 |
for key, method, option_str, extra_env in res_env.NORMAL_INSTALL: |
|
|
272 |
if key not in ignore_packages: |
|
|
273 |
if callable(method): |
|
|
274 |
method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
|
275 |
else: |
|
|
276 |
normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
|
|
277 |
|
|
|
278 |
logger.notify("Clear source dir") |
|
|
279 |
shutil.rmtree(src_dir) |
|
|
280 |
|
|
|
281 |
finally: |
|
|
282 |
logger.indent -= 2 |
|
|
283 |
script_dir = join(base_dir, bin_dir) |
|
|
284 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
|
285 |
% join(script_dir, 'easy_install')) |
|
|
286 |
|
|
|
287 |
|
|
|
288 |
return adjust_options, extend_parser, after_install |