| author | wakimd |
| Thu, 03 Feb 2011 11:12:53 +0100 | |
| changeset 17 | ab47434f9ffc |
| parent 13 | 97ab7b3191cf |
| child 22 | 03d02cf0bea7 |
| 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 |
||
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> |
|
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 |
||
| 17 | 36 |
src_base = os.path.join(here,"res","src").replace("\\","/") |
37 |
lib_path = os.path.abspath(os.path.join(here,"res","lib")).replace("\\","/") |
|
38 |
patch_path = os.path.abspath(os.path.join(here,"res","patch")).replace("\\","/") |
|
| 0 | 39 |
|
40 |
EXTRA_TEXT = "URLS = { \n" |
|
41 |
||
| 17 | 42 |
EXTRA_TEXT += " 'DISTRIBUTE' : { 'setup': 'distribute', 'url': 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"distribute-0.6.14.tar.gz")).replace("\\","/")+"'},\n" |
43 |
if sys.platform == 'win32': |
|
44 |
EXTRA_TEXT += " 'PSYCOPG2' : { 'setup': 'psycopg2','url': 'D:/wakimd/dev/hg/platform/virtualenv/web/res/src/psycopg2-2.0.10.win32-py2.6-pg8.3.7-release.zip', 'local': '"+ os.path.abspath(os.path.join(src_base,"psycopg2-2.0.10.win32-py2.6-pg8.3.7-release.zip")).replace("\\","/")+"'},\n" |
|
45 |
else: |
|
46 |
EXTRA_TEXT += " 'PSYCOPG2' : { 'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-3/psycopg2-2.3.2.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"psycopg2-2.3.2.tar.gz")).replace("\\","/")+"'},\n" |
|
47 |
EXTRA_TEXT += " 'MYSQL' : { 'setup': 'mysql-python', 'url': 'http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download', 'local' : '"+ os.path.abspath(os.path.join(src_base,"MySQL-python-1.2.3.tar.gz")).replace("\\","/")+"'},\n" |
|
48 |
if sys.platform == 'win32': |
|
49 |
EXTRA_TEXT += " 'PYLUCENE' : { 'setup': 'http://pylucene-win32-binary.googlecode.com/files/lucene-3.0.2-py2.6-win32.egg', 'local': '"+ os.path.abspath(os.path.join(src_base,"lucene-3.0.2-py2.6-win32.egg")).replace("\\","/")+"'},\n" |
|
50 |
EXTRA_TEXT += " 'JCC' : { 'setup': 'http://pylucene-win32-binary.googlecode.com/files/JCC-2.6-py2.6-win32.egg', 'local': '"+ os.path.abspath(os.path.join(src_base,"JCC-2.6-py2.6-win32.egg")).replace("\\","/")+"'},\n" |
|
51 |
else: |
|
52 |
EXTRA_TEXT += " 'PYLUCENE' : { 'setup': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.3-1-src.tar.gz', 'url': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.3-1-src.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"pylucene-3.0.3-1-src.tar.gz")).replace("\\","/")+"'},\n" |
|
53 |
if sys.platform == 'win32': |
|
54 |
EXTRA_TEXT += " 'PIL' : { 'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.6.exe', 'local': '"+ os.path.abspath(os.path.join(src_base,"PIL-1.1.7.win32-py2.6.exe")).replace("\\","/")+"'},\n" |
|
55 |
else: |
|
56 |
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")).replace("\\","/")+"'},\n" |
|
57 |
EXTRA_TEXT += " 'DJANGO' : { 'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.2.4/tarball/', 'local': '"+ os.path.abspath(os.path.join(src_base,"Django-1.2.4.tar.gz")).replace("\\","/")+"'},\n" |
|
58 |
EXTRA_TEXT += " 'JOGGING' : { 'setup': 'jogging', 'url': 'http://github.com/zain/jogging/tarball/v0.2.2', 'local': '"+ os.path.abspath(os.path.join(src_base,"jogging-0.2.2.tar.gz")).replace("\\","/")+"'},\n" |
|
59 |
EXTRA_TEXT += " 'DJANGO-EXTENSIONS' : { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/0.6', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-extensions-0.6.tar.gz")).replace("\\","/")+"' },\n" |
|
60 |
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")).replace("\\","/")+"' },\n" |
|
61 |
EXTRA_TEXT += " 'DJANGO-TAGGING' : { 'setup': 'django-tagging', 'url':'http://django-tagging.googlecode.com/files/django-tagging-0.3.1.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-tagging-0.3.1.tar.gz")).replace("\\","/")+"' },\n" |
|
62 |
EXTRA_TEXT += " 'DJANGO-PISTON' : { 'setup': 'django-piston', 'url':'http://bitbucket.org/jespern/django-piston/downloads/django-piston-0.2.2.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-piston-0.2.2.tar.gz")).replace("\\","/")+"' },\n" |
|
63 |
if sys.platform == 'win32': |
|
64 |
EXTRA_TEXT += " 'LXML' : { 'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.6/l/lxml/lxml-2.2.8-py2.6-win32.egg', 'local': '"+ os.path.abspath(os.path.join(src_base,"lxml-2.2.8-py2.6-win32.egg")).replace("\\","/")+"'},\n" |
|
65 |
else: |
|
66 |
EXTRA_TEXT += " 'LXML' : { 'setup': 'lxml', 'url': '"+ os.path.abspath(os.path.join(src_base,"lxml_2.2.8.tar.gz"))+"', 'local': '"+ os.path.abspath(os.path.join(src_base,"lxml-2.2.8.tar.gz")).replace("\\","/")+"'},\n" |
|
| 0 | 67 |
EXTRA_TEXT += "}\n" |
68 |
||
69 |
EXTRA_TEXT += "import sys\n" |
|
70 |
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n" |
|
71 |
||
72 |
EXTRA_TEXT += """ |
|
73 |
||
74 |
import shutil |
|
75 |
import tarfile |
|
| 17 | 76 |
import zipfile |
| 0 | 77 |
import urllib |
78 |
import platform |
|
79 |
import patch |
|
80 |
||
81 |
||
82 |
INDEX_URL = 'http://pypi.python.org/simple/' |
|
83 |
||
84 |
||
85 |
def extend_parser(parser): |
|
86 |
parser.add_option( |
|
87 |
'--index-url', |
|
88 |
metavar='INDEX_URL', |
|
89 |
dest='index_url', |
|
90 |
default='', |
|
91 |
help='base URL of Python Package Index') |
|
92 |
parser.add_option( |
|
93 |
'--type-install', |
|
94 |
metavar='type_install', |
|
95 |
dest='type_install', |
|
96 |
default='local', |
|
97 |
help='type install : local, url, setup') |
|
98 |
parser.add_option( |
|
99 |
'--ignore-packages', |
|
100 |
metavar='ignore_packages', |
|
101 |
dest='ignore_packages', |
|
102 |
default=None, |
|
103 |
help='list of comma separated keys for package to ignore') |
|
104 |
||
105 |
||
106 |
||
107 |
def adjust_options(options, args): |
|
108 |
pass |
|
109 |
||
110 |
||
111 |
def after_install(options, home_dir): |
|
112 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
113 |
base_dir = os.path.dirname(home_dir) |
|
114 |
src_dir = join(home_dir, 'src') |
|
115 |
tmp_dir = join(home_dir, 'tmp') |
|
116 |
ensure_dir(src_dir) |
|
117 |
ensure_dir(tmp_dir) |
|
118 |
system_str = platform.system() |
|
119 |
|
|
120 |
res_source_key = options.type_install |
|
121 |
|
|
122 |
ignore_packages = [] |
|
123 |
|
|
124 |
if options.ignore_packages : |
|
125 |
ignore_packages = options.ignore_packages.split(",") |
|
126 |
|
|
127 |
logger.indent += 2 |
|
128 |
try: |
|
129 |
|
|
| 17 | 130 |
if 'PYLUCENE' not in ignore_packages and system_str != "Windows": |
| 0 | 131 |
#get pylucene |
132 |
logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key]) |
|
133 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
| 17 | 134 |
if res_source_key == 'local': |
135 |
shutil.copy(URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
136 |
else: |
|
137 |
urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
| 0 | 138 |
tf = tarfile.open(pylucene_src,'r:gz') |
139 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
140 |
logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
141 |
tf.extractall(pylucene_base_path) |
|
142 |
tf.close() |
|
143 |
|
|
144 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
145 |
jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
146 |
|
|
147 |
#install jcc |
|
148 |
|
|
149 |
#patch for linux |
|
150 |
if system_str == 'Linux' : |
|
151 |
olddir = os.getcwd() |
|
152 |
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') |
|
153 |
if os.path.isfile(patch_dest_path): |
|
154 |
# must unzip egg |
|
155 |
# rename file and etract all |
|
156 |
shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
157 |
zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
158 |
zf.extractall(patch_dest_path) |
|
159 |
os.remove(patch_dest_path + ".zip") |
|
160 |
logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
161 |
os.chdir(patch_dest_path) |
|
162 |
p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
163 |
p.apply() |
|
164 |
os.chdir(olddir) |
|
165 |
|
|
166 |
logger.notify("Install jcc") |
|
167 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
168 |
cwd=jcc_src_path, |
|
169 |
filter_stdout=filter_python_develop, |
|
170 |
show_stdout=True) |
|
171 |
#install pylucene |
|
172 |
|
|
173 |
logger.notify("Install pylucene") |
|
174 |
#modify makefile |
|
175 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
176 |
logger.notify("Modify makefile %s " % makefile_path) |
|
177 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
178 |
|
|
179 |
destination= open( makefile_path, "w" ) |
|
180 |
source= open( makefile_path+"~", "r" ) |
|
181 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n") |
|
182 |
destination.write("ANT=ant\\n") |
|
183 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n") |
|
184 |
|
|
185 |
if system_str == "Darwin": |
|
186 |
if sys.version_info >= (2,6): |
|
187 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
188 |
else: |
|
189 |
destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n") |
|
190 |
destination.write("NUM_FILES=2\\n") |
|
191 |
elif system_str == "Windows": |
|
192 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
193 |
destination.write("NUM_FILES=2\\n") |
|
194 |
else: |
|
195 |
if sys.version_info >= (2,6) and sys.version_info < (2,7): |
|
196 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\n") |
|
197 |
else: |
|
198 |
destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
|
199 |
destination.write("NUM_FILES=2\\n") |
|
200 |
for line in source: |
|
201 |
destination.write( line ) |
|
202 |
source.close() |
|
203 |
destination.close() |
|
204 |
os.remove(makefile_path+"~" ) |
|
205 |
|
|
206 |
logger.notify("pylucene make") |
|
207 |
call_subprocess(['make'], |
|
208 |
cwd=os.path.abspath(pylucene_src_path), |
|
209 |
filter_stdout=filter_python_develop, |
|
210 |
show_stdout=True) |
|
211 |
|
|
212 |
logger.notify("pylucene make install") |
|
213 |
call_subprocess(['make', 'install'], |
|
214 |
cwd=os.path.abspath(pylucene_src_path), |
|
215 |
filter_stdout=filter_python_develop, |
|
216 |
show_stdout=True) |
|
217 |
||
218 |
if system_str == 'Linux' and 'DISTRIBUTE' not in ignore_packages: |
|
219 |
normal_install('DISTRIBUTE', 'pip', None, None, res_source_key, home_dir, tmp_dir) |
|
220 |
||
221 |
NORMAL_INSTALL = [ #(key,method, option_str, extra_env) |
|
222 |
('MYSQL', 'pip', None, None), |
|
| 17 | 223 |
('PIL', 'easy_install', None, None), |
| 0 | 224 |
('DJANGO','pip', None, None), |
225 |
('JOGGING','pip', None, None), |
|
226 |
('DJANGO-EXTENSIONS', 'pip', None, None), |
|
227 |
('DJANGO-REGISTRATION', 'easy_install', '-Z', None), |
|
228 |
('DJANGO-TAGGING', 'pip', None, None), |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
1
diff
changeset
|
229 |
('DJANGO-PISTON', 'pip', None, None), |
| 0 | 230 |
] |
| 17 | 231 |
|
232 |
if 'PYLUCENE' not in ignore_packages and system_str == "Windows": |
|
233 |
NORMAL_INSTALL.append(('JCC','easy_install',None,None)) |
|
234 |
NORMAL_INSTALL.append(('PYLUCENE','easy_install',None,None)) |
|
235 |
|
|
| 0 | 236 |
if system_str == "Darwin": |
237 |
NORMAL_INSTALL.append(('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'})) |
|
238 |
else: |
|
239 |
NORMAL_INSTALL.append(('LXML', 'easy_install', None, None)) |
|
240 |
|
|
| 17 | 241 |
if system_str == "Windows": |
242 |
#get psycopg2 |
|
243 |
psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
244 |
shutil.copy(URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
245 |
#extract psycopg2 |
|
246 |
zf = zipfile.ZipFile(psycopg2_src) |
|
247 |
psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
248 |
zf.extractall(psycopg2_base_path) |
|
249 |
zf.close() |
|
250 |
|
|
251 |
psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
252 |
shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib', 'psycopg2'))) |
|
253 |
shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.10-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib', 'site-packages'))) |
|
254 |
else: |
|
255 |
NORMAL_INSTALL.append(('PSYCOPG2', 'pip', None, None)) |
|
256 |
||
| 0 | 257 |
|
258 |
for key, method, option_str, extra_env in NORMAL_INSTALL: |
|
259 |
if key not in ignore_packages: |
|
260 |
normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir) |
|
261 |
|
|
262 |
logger.notify("Clear source dir") |
|
263 |
shutil.rmtree(src_dir) |
|
264 |
||
265 |
finally: |
|
266 |
logger.indent -= 2 |
|
| 17 | 267 |
script_dir = join(base_dir, bin_dir) |
| 0 | 268 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
269 |
% join(script_dir, 'easy_install')) |
|
270 |
||
271 |
||
272 |
def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir): |
|
273 |
logger.notify("Install %s from %s with %s" % (key,URLS[key][res_source_key],method)) |
|
274 |
if method == 'pip': |
|
| 17 | 275 |
if sys.platform == 'win32': |
276 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS[key][res_source_key]] |
|
277 |
else: |
|
278 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS[key][res_source_key]] |
|
| 0 | 279 |
if option_str : |
280 |
args.insert(4,option_str) |
|
281 |
call_subprocess(args, |
|
282 |
cwd=os.path.abspath(tmp_dir), |
|
283 |
filter_stdout=filter_python_develop, |
|
284 |
show_stdout=True, |
|
285 |
extra_env=extra_env) |
|
286 |
else: |
|
| 17 | 287 |
if sys.platform == 'win32': |
288 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), URLS[key][res_source_key]] |
|
289 |
else: |
|
290 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS[key][res_source_key]] |
|
| 0 | 291 |
if option_str : |
292 |
args.insert(1,option_str) |
|
293 |
call_subprocess(args, |
|
294 |
cwd=os.path.abspath(tmp_dir), |
|
295 |
filter_stdout=filter_python_develop, |
|
296 |
show_stdout=True, |
|
297 |
extra_env=extra_env) |
|
298 |
|
|
299 |
||
300 |
def ensure_dir(dir): |
|
301 |
if not os.path.exists(dir): |
|
302 |
logger.notify('Creating directory %s' % dir) |
|
303 |
os.makedirs(dir) |
|
304 |
||
305 |
def filter_python_develop(line): |
|
306 |
if not line.strip(): |
|
307 |
return Logger.DEBUG |
|
308 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
309 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
310 |
'creating ', 'Copying ']: |
|
311 |
if line.startswith(prefix): |
|
312 |
return Logger.DEBUG |
|
313 |
return Logger.NOTIFY |
|
314 |
""" |
|
315 |
||
316 |
def main(): |
|
317 |
python_version = ".".join(map(str,sys.version_info[0:2])) |
|
318 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) |
|
319 |
if os.path.exists(script_name): |
|
320 |
f = open(script_name) |
|
321 |
cur_text = f.read() |
|
322 |
f.close() |
|
323 |
else: |
|
324 |
cur_text = '' |
|
325 |
print 'Updating %s' % script_name |
|
326 |
if cur_text == 'text': |
|
327 |
print 'No update' |
|
328 |
else: |
|
329 |
print 'Script changed; updating...' |
|
330 |
f = open(script_name, 'w') |
|
331 |
f.write(text) |
|
332 |
f.close() |
|
333 |
||
334 |
if __name__ == '__main__': |
|
335 |
main() |
|
336 |