|
1
|
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 |
|
|
|
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 += " '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" |
|
|
46 |
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" |
|
|
47 |
EXTRA_TEXT += " 'DJANGO' : { 'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.2.3/tarball/', 'local': '"+ os.path.abspath(os.path.join(src_base,"Django-1.2.3.tar.gz"))+"'},\n" |
|
|
48 |
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"))+"'},\n" |
|
|
49 |
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" |
|
|
50 |
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" |
|
|
51 |
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"))+"' },\n" |
|
19
|
52 |
EXTRA_TEXT += " 'DJANGO-OAUTH' : { 'setup': 'django-oauth', 'url':'http://code.welldev.org/django-oauth/get/549a34c81394.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-oauth.gz"))+"' },\n" |
|
14
|
53 |
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"))+"'},\n" |
|
1
|
54 |
EXTRA_TEXT += "}\n" |
|
|
55 |
|
|
|
56 |
EXTRA_TEXT += "import sys\n" |
|
|
57 |
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n" |
|
|
58 |
|
|
|
59 |
EXTRA_TEXT += """ |
|
|
60 |
|
|
|
61 |
import shutil |
|
|
62 |
import tarfile |
|
|
63 |
import urllib |
|
|
64 |
import platform |
|
|
65 |
import patch |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
INDEX_URL = 'http://pypi.python.org/simple/' |
|
|
69 |
|
|
|
70 |
|
|
|
71 |
def extend_parser(parser): |
|
|
72 |
parser.add_option( |
|
|
73 |
'--index-url', |
|
|
74 |
metavar='INDEX_URL', |
|
|
75 |
dest='index_url', |
|
|
76 |
default='', |
|
|
77 |
help='base URL of Python Package Index') |
|
|
78 |
parser.add_option( |
|
|
79 |
'--type-install', |
|
|
80 |
metavar='type_install', |
|
|
81 |
dest='type_install', |
|
|
82 |
default='local', |
|
|
83 |
help='type install : local, url, setup') |
|
|
84 |
parser.add_option( |
|
|
85 |
'--ignore-packages', |
|
|
86 |
metavar='ignore_packages', |
|
|
87 |
dest='ignore_packages', |
|
|
88 |
default=None, |
|
|
89 |
help='list of comma separated keys for package to ignore') |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
def adjust_options(options, args): |
|
|
94 |
pass |
|
|
95 |
|
|
|
96 |
|
|
|
97 |
def after_install(options, home_dir): |
|
|
98 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
|
99 |
base_dir = os.path.dirname(home_dir) |
|
|
100 |
src_dir = join(home_dir, 'src') |
|
|
101 |
tmp_dir = join(home_dir, 'tmp') |
|
|
102 |
ensure_dir(src_dir) |
|
|
103 |
ensure_dir(tmp_dir) |
|
|
104 |
system_str = platform.system() |
|
|
105 |
|
|
|
106 |
res_source_key = options.type_install |
|
|
107 |
|
|
|
108 |
ignore_packages = [] |
|
|
109 |
|
|
|
110 |
if options.ignore_packages : |
|
|
111 |
ignore_packages = options.ignore_packages.split(",") |
|
|
112 |
|
|
|
113 |
logger.indent += 2 |
|
|
114 |
try: |
|
|
115 |
|
|
|
116 |
if 'PYLUCENE' not in ignore_packages: |
|
|
117 |
#get pylucene |
|
|
118 |
logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key]) |
|
|
119 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
|
120 |
urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
|
121 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
|
122 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
|
123 |
logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
|
124 |
tf.extractall(pylucene_base_path) |
|
|
125 |
tf.close() |
|
|
126 |
|
|
|
127 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
|
128 |
jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
|
129 |
|
|
|
130 |
#install jcc |
|
|
131 |
|
|
|
132 |
#patch for linux |
|
|
133 |
if system_str == 'Linux' : |
|
|
134 |
olddir = os.getcwd() |
|
|
135 |
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') |
|
|
136 |
if os.path.isfile(patch_dest_path): |
|
|
137 |
# must unzip egg |
|
|
138 |
# rename file and etract all |
|
|
139 |
shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
|
140 |
zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
|
141 |
zf.extractall(patch_dest_path) |
|
|
142 |
os.remove(patch_dest_path + ".zip") |
|
|
143 |
logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
|
144 |
os.chdir(patch_dest_path) |
|
|
145 |
p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
|
146 |
p.apply() |
|
|
147 |
os.chdir(olddir) |
|
|
148 |
|
|
|
149 |
logger.notify("Install jcc") |
|
|
150 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
|
151 |
cwd=jcc_src_path, |
|
|
152 |
filter_stdout=filter_python_develop, |
|
|
153 |
show_stdout=True) |
|
|
154 |
#install pylucene |
|
|
155 |
|
|
|
156 |
logger.notify("Install pylucene") |
|
|
157 |
#modify makefile |
|
|
158 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
|
159 |
logger.notify("Modify makefile %s " % makefile_path) |
|
|
160 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
|
161 |
|
|
|
162 |
destination= open( makefile_path, "w" ) |
|
|
163 |
source= open( makefile_path+"~", "r" ) |
|
|
164 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n") |
|
|
165 |
destination.write("ANT=ant\\n") |
|
|
166 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n") |
|
|
167 |
|
|
|
168 |
if system_str == "Darwin": |
|
|
169 |
if sys.version_info >= (2,6): |
|
|
170 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
171 |
else: |
|
|
172 |
destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n") |
|
|
173 |
destination.write("NUM_FILES=2\\n") |
|
|
174 |
elif system_str == "Windows": |
|
|
175 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
176 |
destination.write("NUM_FILES=2\\n") |
|
|
177 |
else: |
|
|
178 |
if sys.version_info >= (2,6) and sys.version_info < (2,7): |
|
|
179 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\n") |
|
|
180 |
else: |
|
|
181 |
destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
|
|
182 |
destination.write("NUM_FILES=2\\n") |
|
|
183 |
for line in source: |
|
|
184 |
destination.write( line ) |
|
|
185 |
source.close() |
|
|
186 |
destination.close() |
|
|
187 |
os.remove(makefile_path+"~" ) |
|
|
188 |
|
|
|
189 |
logger.notify("pylucene make") |
|
|
190 |
call_subprocess(['make'], |
|
|
191 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
192 |
filter_stdout=filter_python_develop, |
|
|
193 |
show_stdout=True) |
|
|
194 |
|
|
|
195 |
logger.notify("pylucene make install") |
|
|
196 |
call_subprocess(['make', 'install'], |
|
|
197 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
198 |
filter_stdout=filter_python_develop, |
|
|
199 |
show_stdout=True) |
|
|
200 |
|
|
|
201 |
if system_str == 'Linux' and 'DISTRIBUTE' not in ignore_packages: |
|
|
202 |
normal_install('DISTRIBUTE', 'pip', None, None, res_source_key, home_dir, tmp_dir) |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
NORMAL_INSTALL = [ #(key,method, option_str, extra_env) |
|
|
206 |
#('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'}), |
|
|
207 |
('PSYCOPG2', 'pip', None, None), |
|
|
208 |
('MYSQL', 'pip', None, None), |
|
|
209 |
('PIL', 'pip', None, None), |
|
|
210 |
('DJANGO','pip', None, None), |
|
|
211 |
('JOGGING','pip', None, None), |
|
|
212 |
('DJANGO-EXTENSIONS', 'pip', None, None), |
|
|
213 |
('DJANGO-REGISTRATION', 'easy_install', '-Z', None), |
|
|
214 |
('DJANGO-TAGGING', 'pip', None, None), |
|
19
|
215 |
('DJANGO-OAUTH', 'pip', None, None), |
|
1
|
216 |
] |
|
|
217 |
|
|
|
218 |
if system_str == "Darwin": |
|
|
219 |
NORMAL_INSTALL.append(('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'})) |
|
|
220 |
else: |
|
|
221 |
NORMAL_INSTALL.append(('LXML', 'easy_install', None, None)) |
|
|
222 |
|
|
|
223 |
|
|
|
224 |
for key, method, option_str, extra_env in NORMAL_INSTALL: |
|
|
225 |
if key not in ignore_packages: |
|
|
226 |
normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir) |
|
|
227 |
|
|
|
228 |
logger.notify("Clear source dir") |
|
|
229 |
shutil.rmtree(src_dir) |
|
|
230 |
|
|
|
231 |
finally: |
|
|
232 |
logger.indent -= 2 |
|
|
233 |
script_dir = join(base_dir, 'bin') |
|
|
234 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
|
235 |
% join(script_dir, 'easy_install')) |
|
|
236 |
|
|
|
237 |
|
|
|
238 |
def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir): |
|
|
239 |
logger.notify("Install %s from %s with %s" % (key,URLS[key][res_source_key],method)) |
|
|
240 |
if method == 'pip': |
|
|
241 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS[key][res_source_key]] |
|
|
242 |
if option_str : |
|
|
243 |
args.insert(4,option_str) |
|
|
244 |
call_subprocess(args, |
|
|
245 |
cwd=os.path.abspath(tmp_dir), |
|
|
246 |
filter_stdout=filter_python_develop, |
|
|
247 |
show_stdout=True, |
|
|
248 |
extra_env=extra_env) |
|
|
249 |
else: |
|
|
250 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS[key][res_source_key]] |
|
|
251 |
if option_str : |
|
|
252 |
args.insert(1,option_str) |
|
|
253 |
call_subprocess(args, |
|
|
254 |
cwd=os.path.abspath(tmp_dir), |
|
|
255 |
filter_stdout=filter_python_develop, |
|
|
256 |
show_stdout=True, |
|
|
257 |
extra_env=extra_env) |
|
|
258 |
|
|
|
259 |
|
|
|
260 |
def ensure_dir(dir): |
|
|
261 |
if not os.path.exists(dir): |
|
|
262 |
logger.notify('Creating directory %s' % dir) |
|
|
263 |
os.makedirs(dir) |
|
|
264 |
|
|
|
265 |
def filter_python_develop(line): |
|
|
266 |
if not line.strip(): |
|
|
267 |
return Logger.DEBUG |
|
|
268 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
269 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
270 |
'creating ', 'Copying ']: |
|
|
271 |
if line.startswith(prefix): |
|
|
272 |
return Logger.DEBUG |
|
|
273 |
return Logger.NOTIFY |
|
|
274 |
""" |
|
|
275 |
|
|
|
276 |
def main(): |
|
|
277 |
python_version = ".".join(map(str,sys.version_info[0:2])) |
|
|
278 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) |
|
|
279 |
if os.path.exists(script_name): |
|
|
280 |
f = open(script_name) |
|
|
281 |
cur_text = f.read() |
|
|
282 |
f.close() |
|
|
283 |
else: |
|
|
284 |
cur_text = '' |
|
|
285 |
print 'Updating %s' % script_name |
|
|
286 |
if cur_text == 'text': |
|
|
287 |
print 'No update' |
|
|
288 |
else: |
|
|
289 |
print 'Script changed; updating...' |
|
|
290 |
f = open(script_name, 'w') |
|
|
291 |
f.write(text) |
|
|
292 |
f.close() |
|
|
293 |
|
|
|
294 |
if __name__ == '__main__': |
|
|
295 |
main() |
|
|
296 |
|