|
31
|
1 |
""" |
|
34
|
2 |
Call this like ``python create_python_env.py``; it will |
|
51
|
3 |
refresh the project-boot.py script |
|
32
|
4 |
|
|
|
5 |
-prerequisite: |
|
|
6 |
|
|
|
7 |
- virtualenv |
|
|
8 |
- distribute |
|
|
9 |
- psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility |
|
|
10 |
|
|
33
|
11 |
- virtualenv --distribute --no-site-packages venv |
|
51
|
12 |
- python project-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear bvenv |
|
35
|
13 |
|
|
31
|
14 |
""" |
|
36
|
15 |
|
|
31
|
16 |
import os |
|
|
17 |
import subprocess |
|
|
18 |
import re |
|
34
|
19 |
import sys |
|
31
|
20 |
|
|
36
|
21 |
|
|
31
|
22 |
here = os.path.dirname(os.path.abspath(__file__)) |
|
34
|
23 |
base_dir = here |
|
51
|
24 |
script_name = os.path.join(base_dir, 'project-boot.py') |
|
31
|
25 |
|
|
|
26 |
import virtualenv |
|
|
27 |
|
|
|
28 |
# things to install |
|
33
|
29 |
# - psycopg2 -> pip |
|
|
30 |
# - PIL -> pip |
|
|
31 |
# - pyxml -> pip |
|
|
32 |
# - 4Suite-xml - easy_install ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2 |
|
|
33 |
# - pylucene - script |
|
|
34 |
|
|
36
|
35 |
src_base = os.path.join(here,"res","src") |
|
|
36 |
lib_path = os.path.abspath(os.path.join(here,"res","lib")) |
|
|
37 |
patch_path = os.path.abspath(os.path.join(here,"res","patch")) |
|
31
|
38 |
|
|
36
|
39 |
EXTRA_TEXT = "URLS = { \n" |
|
31
|
40 |
|
|
42
|
41 |
EXTRA_TEXT += " 'DISTRIBUTE' : { 'setup': 'distribute', 'url': 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.13.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"distribute-0.6.13.tar.gz"))+"'},\n" |
|
|
42 |
EXTRA_TEXT += " 'PSYCOPG2' : { 'setup': 'psycopg2','url': 'http://initd.org/pub/software/psycopg/psycopg2-2.2.1.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"psycopg2-2.2.1.tar.gz"))+"'},\n" |
|
|
43 |
EXTRA_TEXT += " 'FOURSUITE_XML' : { 'setup': '4Suite-XML', 'url': 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2', 'local': '"+ os.path.abspath(os.path.join(src_base,"4Suite-XML-1.0.2.tar.bz2"))+"'},\n" |
|
|
44 |
EXTRA_TEXT += " 'PYLUCENE' : { 'setup': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz', 'url': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"pylucene-3.0.1-1-src.tar.gz"))+"'},\n" |
|
|
45 |
EXTRA_TEXT += " 'PIL' : { 'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"Imaging-1.1.7.tar.gz"))+"'},\n" |
|
|
46 |
EXTRA_TEXT += " 'PYXML' : { 'setup': 'http://sourceforge.net/projects/pyxml/files/pyxml/0.8.4/PyXML-0.8.4.tar.gz/download', 'url': 'http://sourceforge.net/projects/pyxml/files/pyxml/0.8.4/PyXML-0.8.4.tar.gz/download', 'local': '"+ os.path.abspath(os.path.join(src_base,"PyXML-0.8.4.tar.gz"))+"', 'patch': '"+os.path.join(patch_path,"pyxml.patch")+"'},\n" |
|
36
|
47 |
|
|
|
48 |
EXTRA_TEXT += "}\n" |
|
|
49 |
|
|
|
50 |
EXTRA_TEXT += "import sys\n" |
|
|
51 |
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n" |
|
|
52 |
|
|
|
53 |
EXTRA_TEXT += """ |
|
31
|
54 |
|
|
|
55 |
import shutil |
|
32
|
56 |
import tarfile |
|
|
57 |
import urllib |
|
34
|
58 |
import platform |
|
36
|
59 |
import patch |
|
51
|
60 |
import zipfile |
|
|
61 |
from distutils.sysconfig import get_python_lib |
|
31
|
62 |
|
|
36
|
63 |
|
|
35
|
64 |
INDEX_URL = 'http://pypi.python.org/simple/' |
|
|
65 |
|
|
33
|
66 |
|
|
31
|
67 |
def extend_parser(parser): |
|
35
|
68 |
parser.add_option( |
|
|
69 |
'--index-url', |
|
|
70 |
metavar='INDEX_URL', |
|
|
71 |
dest='index_url', |
|
|
72 |
default='', |
|
|
73 |
help='base URL of Python Package Index') |
|
36
|
74 |
parser.add_option( |
|
45
|
75 |
'--type-install', |
|
42
|
76 |
metavar='type_install', |
|
|
77 |
dest='type_install', |
|
|
78 |
default='local', |
|
|
79 |
help='type install : local, url, setup') |
|
36
|
80 |
|
|
31
|
81 |
|
|
|
82 |
def adjust_options(options, args): |
|
35
|
83 |
pass |
|
31
|
84 |
|
|
33
|
85 |
|
|
31
|
86 |
def after_install(options, home_dir): |
|
42
|
87 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
31
|
88 |
base_dir = os.path.dirname(home_dir) |
|
|
89 |
src_dir = join(home_dir, 'src') |
|
32
|
90 |
tmp_dir = join(home_dir, 'tmp') |
|
|
91 |
ensure_dir(src_dir) |
|
|
92 |
ensure_dir(tmp_dir) |
|
42
|
93 |
system_str = platform.system() |
|
51
|
94 |
python_lib_dir = get_python_lib() |
|
36
|
95 |
|
|
45
|
96 |
res_source_key = options.type_install |
|
36
|
97 |
|
|
34
|
98 |
logger.indent += 2 |
|
31
|
99 |
try: |
|
36
|
100 |
|
|
33
|
101 |
#get pylucene |
|
46
|
102 |
logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key]) |
|
33
|
103 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
36
|
104 |
urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
33
|
105 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
34
|
106 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
46
|
107 |
logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
34
|
108 |
tf.extractall(pylucene_base_path) |
|
33
|
109 |
tf.close() |
|
34
|
110 |
|
|
|
111 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
42
|
112 |
jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
34
|
113 |
|
|
33
|
114 |
#install jcc |
|
42
|
115 |
|
|
|
116 |
#patch for linux |
|
45
|
117 |
if system_str == 'Linux' : |
|
42
|
118 |
olddir = os.getcwd() |
|
51
|
119 |
patch_dest_path = os.path.join(lib_dir, 'site-packages','setuptools-0.6c11-py'+'%s.%s' % (sys.version_info[0], sys.version_info[1])+'.egg') |
|
|
120 |
|
|
|
121 |
if os.path.isfile(patch_dest_path): |
|
|
122 |
# must unzip egg |
|
|
123 |
# rename file and etract all |
|
|
124 |
shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
|
125 |
zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
|
126 |
zf.extractall(patch_dest_path) |
|
|
127 |
os.remove(patch_dest_path + ".zip") |
|
46
|
128 |
logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
45
|
129 |
os.chdir(patch_dest_path) |
|
|
130 |
p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
42
|
131 |
p.apply() |
|
|
132 |
os.chdir(olddir) |
|
|
133 |
|
|
46
|
134 |
logger.notify("Install jcc") |
|
33
|
135 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
42
|
136 |
cwd=jcc_src_path, |
|
33
|
137 |
filter_stdout=filter_python_develop, |
|
35
|
138 |
show_stdout=True) |
|
45
|
139 |
#install pylucene |
|
|
140 |
|
|
46
|
141 |
logger.notify("Install pylucene") |
|
34
|
142 |
#modify makefile |
|
|
143 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
46
|
144 |
logger.notify("Modify makefile %s " % makefile_path) |
|
34
|
145 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
33
|
146 |
|
|
34
|
147 |
destination= open( makefile_path, "w" ) |
|
|
148 |
source= open( makefile_path+"~", "r" ) |
|
35
|
149 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n") |
|
|
150 |
destination.write("ANT=ant\\n") |
|
|
151 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n") |
|
42
|
152 |
|
|
34
|
153 |
if system_str == "Darwin": |
|
36
|
154 |
if sys.version_info >= (2,6): |
|
35
|
155 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
156 |
else: |
|
|
157 |
destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n") |
|
|
158 |
destination.write("NUM_FILES=2\\n") |
|
34
|
159 |
elif system_str == "Windows": |
|
35
|
160 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
161 |
destination.write("NUM_FILES=2\\n") |
|
34
|
162 |
else: |
|
51
|
163 |
if sys.version_info >= (2,6) and sys.version_info < (2,7): |
|
|
164 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\n") |
|
|
165 |
else: |
|
|
166 |
destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
|
35
|
167 |
destination.write("NUM_FILES=2\\n") |
|
34
|
168 |
for line in source: |
|
|
169 |
destination.write( line ) |
|
|
170 |
source.close() |
|
|
171 |
destination.close() |
|
|
172 |
os.remove(makefile_path+"~" ) |
|
33
|
173 |
|
|
46
|
174 |
logger.notify("pylucene make") |
|
36
|
175 |
call_subprocess(['make'], |
|
|
176 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
177 |
filter_stdout=filter_python_develop, |
|
|
178 |
show_stdout=True) |
|
|
179 |
|
|
46
|
180 |
logger.notify("pylucene make install") |
|
34
|
181 |
call_subprocess(['make', 'install'], |
|
|
182 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
183 |
filter_stdout=filter_python_develop, |
|
35
|
184 |
show_stdout=True) |
|
42
|
185 |
|
|
46
|
186 |
logger.notify("PyXML install : %s " % URLS['PYXML'][res_source_key]) |
|
42
|
187 |
if sys.version_info >= (2,6): |
|
46
|
188 |
logger.notify("PyXML -> python version >= 2.6 : patching") |
|
42
|
189 |
pyxml_src = os.path.join(src_dir,"pyxml.tar.gz") |
|
|
190 |
urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src) |
|
46
|
191 |
logger.notify("PyXML -> python version >= 2.6 : extract archive") |
|
42
|
192 |
tf = tarfile.open(pyxml_src,'r:gz') |
|
|
193 |
pyxml_base_path = os.path.join(src_dir,"pyxml") |
|
|
194 |
tf.extractall(pyxml_base_path) |
|
|
195 |
tf.close() |
|
46
|
196 |
|
|
42
|
197 |
#patch |
|
|
198 |
pyxml_version = os.listdir(pyxml_base_path)[0] |
|
|
199 |
pyxml_path = os.path.join(pyxml_base_path, pyxml_version) |
|
|
200 |
olddir = os.getcwd() |
|
|
201 |
os.chdir(pyxml_path) |
|
46
|
202 |
logger.notify("PyXML -> python version >= 2.6 : do patch %s : %s " % (pyxml_path, URLS['PYXML']['patch'])) |
|
42
|
203 |
p = patch.fromfile(URLS['PYXML']['patch']) |
|
|
204 |
p.apply() |
|
|
205 |
os.chdir(olddir) |
|
46
|
206 |
logger.notify("PyXML -> python version >= 2.6 : install") |
|
42
|
207 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), '--build='+os.path.abspath(pyxml_base_path), '--no-download', pyxml_version], |
|
|
208 |
cwd=os.path.abspath(tmp_dir), |
|
|
209 |
filter_stdout=filter_python_develop, |
|
|
210 |
show_stdout=True) |
|
|
211 |
else: |
|
|
212 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]], |
|
|
213 |
cwd=os.path.abspath(tmp_dir), |
|
|
214 |
filter_stdout=filter_python_develop, |
|
|
215 |
show_stdout=True) |
|
|
216 |
|
|
46
|
217 |
logger.notify("Install Distribute from %s" % URLS['DISTRIBUTE'][res_source_key]) |
|
42
|
218 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['DISTRIBUTE'][res_source_key]], |
|
|
219 |
cwd=os.path.abspath(tmp_dir), |
|
|
220 |
filter_stdout=filter_python_develop, |
|
|
221 |
show_stdout=True) |
|
|
222 |
|
|
46
|
223 |
logger.notify("Install Psycopg2 from %s" % URLS['PSYCOPG2'][res_source_key]) |
|
42
|
224 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PSYCOPG2'][res_source_key]], |
|
|
225 |
cwd=os.path.abspath(tmp_dir), |
|
|
226 |
filter_stdout=filter_python_develop, |
|
|
227 |
show_stdout=True) |
|
|
228 |
|
|
46
|
229 |
logger.notify("Install PIL from %s" % URLS['PIL'][res_source_key]) |
|
42
|
230 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PIL'][res_source_key]], |
|
|
231 |
cwd=os.path.abspath(tmp_dir), |
|
|
232 |
filter_stdout=filter_python_develop, |
|
|
233 |
show_stdout=True) |
|
46
|
234 |
|
|
|
235 |
logger.notify("Install 4Suite-XML from %s" % URLS['FOURSUITE_XML'][res_source_key]) |
|
42
|
236 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS['FOURSUITE_XML'][res_source_key]], |
|
|
237 |
cwd=os.path.abspath(tmp_dir), |
|
|
238 |
filter_stdout=filter_python_develop, |
|
|
239 |
show_stdout=True) |
|
|
240 |
|
|
46
|
241 |
logger.notify("Clear source dir") |
|
35
|
242 |
shutil.rmtree(src_dir) |
|
34
|
243 |
|
|
31
|
244 |
finally: |
|
34
|
245 |
logger.indent -= 2 |
|
31
|
246 |
script_dir = join(base_dir, 'bin') |
|
|
247 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
32
|
248 |
% join(script_dir, 'easy_install')) |
|
31
|
249 |
|
|
32
|
250 |
def ensure_dir(dir): |
|
31
|
251 |
if not os.path.exists(dir): |
|
46
|
252 |
logger.notify('Creating directory %s' % dir) |
|
31
|
253 |
os.makedirs(dir) |
|
|
254 |
|
|
|
255 |
def filter_python_develop(line): |
|
|
256 |
if not line.strip(): |
|
|
257 |
return Logger.DEBUG |
|
|
258 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
259 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
260 |
'creating ', 'Copying ']: |
|
|
261 |
if line.startswith(prefix): |
|
|
262 |
return Logger.DEBUG |
|
|
263 |
return Logger.NOTIFY |
|
|
264 |
""" |
|
|
265 |
|
|
|
266 |
def main(): |
|
33
|
267 |
python_version = ".".join(map(str,sys.version_info[0:2])) |
|
|
268 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) |
|
31
|
269 |
if os.path.exists(script_name): |
|
|
270 |
f = open(script_name) |
|
|
271 |
cur_text = f.read() |
|
|
272 |
f.close() |
|
|
273 |
else: |
|
|
274 |
cur_text = '' |
|
|
275 |
print 'Updating %s' % script_name |
|
|
276 |
if cur_text == 'text': |
|
|
277 |
print 'No update' |
|
|
278 |
else: |
|
|
279 |
print 'Script changed; updating...' |
|
|
280 |
f = open(script_name, 'w') |
|
|
281 |
f.write(text) |
|
|
282 |
f.close() |
|
|
283 |
|
|
|
284 |
if __name__ == '__main__': |
|
|
285 |
main() |
|
|
286 |
|