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