|
31
|
1 |
""" |
|
34
|
2 |
Call this like ``python create_python_env.py``; it will |
|
32
|
3 |
refresh the blinkster-boot.py script |
|
|
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 |
|
35
|
12 |
- python blinkster-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear bvenv |
|
|
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 |
|
31
|
24 |
script_name = os.path.join(base_dir, 'blinkster-boot.py') |
|
|
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 |
|
|
36
|
41 |
EXTRA_TEXT += " '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" |
|
|
42 |
EXTRA_TEXT += " 'FOURSUITE_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" |
|
|
43 |
EXTRA_TEXT += " 'PYLUCENE' : { '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" |
|
|
44 |
EXTRA_TEXT += " '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" |
|
|
45 |
EXTRA_TEXT += " 'PYXML' : { '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" |
|
|
46 |
|
|
|
47 |
EXTRA_TEXT += "}\n" |
|
|
48 |
|
|
|
49 |
EXTRA_TEXT += "import sys\n" |
|
|
50 |
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n" |
|
|
51 |
|
|
|
52 |
EXTRA_TEXT += """ |
|
31
|
53 |
|
|
|
54 |
import shutil |
|
32
|
55 |
import tarfile |
|
|
56 |
import urllib |
|
34
|
57 |
import platform |
|
36
|
58 |
import patch |
|
31
|
59 |
|
|
36
|
60 |
|
|
35
|
61 |
INDEX_URL = 'http://pypi.python.org/simple/' |
|
|
62 |
|
|
33
|
63 |
|
|
31
|
64 |
def extend_parser(parser): |
|
35
|
65 |
parser.add_option( |
|
|
66 |
'--index-url', |
|
|
67 |
metavar='INDEX_URL', |
|
|
68 |
dest='index_url', |
|
|
69 |
default='', |
|
|
70 |
help='base URL of Python Package Index') |
|
36
|
71 |
parser.add_option( |
|
|
72 |
'--local', |
|
|
73 |
metavar='LOCAL', |
|
|
74 |
dest='local', |
|
|
75 |
action="store_true", |
|
|
76 |
default=False, |
|
|
77 |
help='base URL of Python Package Index') |
|
|
78 |
|
|
31
|
79 |
|
|
|
80 |
def adjust_options(options, args): |
|
35
|
81 |
pass |
|
31
|
82 |
|
|
33
|
83 |
|
|
31
|
84 |
def after_install(options, home_dir): |
|
|
85 |
base_dir = os.path.dirname(home_dir) |
|
|
86 |
src_dir = join(home_dir, 'src') |
|
32
|
87 |
tmp_dir = join(home_dir, 'tmp') |
|
|
88 |
ensure_dir(src_dir) |
|
|
89 |
ensure_dir(tmp_dir) |
|
36
|
90 |
|
|
|
91 |
res_source_key = "local" if options.local else "url" |
|
|
92 |
|
|
34
|
93 |
logger.indent += 2 |
|
31
|
94 |
try: |
|
36
|
95 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PSYCOPG2'][res_source_key]], |
|
32
|
96 |
cwd=os.path.abspath(tmp_dir), |
|
|
97 |
filter_stdout=filter_python_develop, |
|
35
|
98 |
show_stdout=True) |
|
36
|
99 |
|
|
|
100 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PIL'][res_source_key]], |
|
35
|
101 |
cwd=os.path.abspath(tmp_dir), |
|
|
102 |
filter_stdout=filter_python_develop, |
|
|
103 |
show_stdout=True) |
|
36
|
104 |
|
|
|
105 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS['FOURSUITE_XML'][res_source_key]], |
|
32
|
106 |
cwd=os.path.abspath(tmp_dir), |
|
31
|
107 |
filter_stdout=filter_python_develop, |
|
35
|
108 |
show_stdout=True) |
|
32
|
109 |
|
|
36
|
110 |
|
|
|
111 |
if sys.version_info >= (2,6): |
|
|
112 |
pyxml_src = os.path.join(src_dir,"pyxml.tar.gz") |
|
|
113 |
urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src) |
|
|
114 |
tf = tarfile.open(pyxml_src,'r:gz') |
|
|
115 |
pyxml_base_path = os.path.join(src_dir,"pyxml") |
|
|
116 |
tf.extractall(pyxml_base_path) |
|
|
117 |
tf.close() |
|
|
118 |
#patch |
|
|
119 |
pyxml_version = os.listdir(pyxml_base_path)[0] |
|
|
120 |
pyxml_path = os.path.join(pyxml_base_path, pyxml_version) |
|
|
121 |
olddir = os.getcwd() |
|
|
122 |
os.chdir(pyxml_path) |
|
|
123 |
p = patch.fromfile(URLS['PYXML']['patch']) |
|
|
124 |
p.apply() |
|
|
125 |
os.chdir(olddir) |
|
|
126 |
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], |
|
|
127 |
cwd=os.path.abspath(tmp_dir), |
|
|
128 |
filter_stdout=filter_python_develop, |
|
|
129 |
show_stdout=True) |
|
|
130 |
else: |
|
|
131 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]], |
|
|
132 |
cwd=os.path.abspath(tmp_dir), |
|
|
133 |
filter_stdout=filter_python_develop, |
|
|
134 |
show_stdout=True) |
|
|
135 |
|
|
|
136 |
|
|
33
|
137 |
#get pylucene |
|
|
138 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
36
|
139 |
urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
33
|
140 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
34
|
141 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
|
142 |
tf.extractall(pylucene_base_path) |
|
33
|
143 |
tf.close() |
|
34
|
144 |
|
|
|
145 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
|
146 |
|
|
33
|
147 |
#install jcc |
|
|
148 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
34
|
149 |
cwd=os.path.abspath(os.path.join(pylucene_src_path,"jcc")), |
|
33
|
150 |
filter_stdout=filter_python_develop, |
|
35
|
151 |
show_stdout=True) |
|
33
|
152 |
#install pylucene |
|
34
|
153 |
#modify makefile |
|
|
154 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
|
155 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
33
|
156 |
|
|
34
|
157 |
destination= open( makefile_path, "w" ) |
|
|
158 |
source= open( makefile_path+"~", "r" ) |
|
35
|
159 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n") |
|
|
160 |
destination.write("ANT=ant\\n") |
|
|
161 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n") |
|
34
|
162 |
system_str = platform.system() |
|
|
163 |
if system_str == "Darwin": |
|
36
|
164 |
if sys.version_info >= (2,6): |
|
35
|
165 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
166 |
else: |
|
49
|
167 |
destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
|
35
|
168 |
destination.write("NUM_FILES=2\\n") |
|
34
|
169 |
elif system_str == "Windows": |
|
35
|
170 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
|
171 |
destination.write("NUM_FILES=2\\n") |
|
34
|
172 |
else: |
|
35
|
173 |
destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
|
|
174 |
destination.write("NUM_FILES=2\\n") |
|
34
|
175 |
for line in source: |
|
|
176 |
destination.write( line ) |
|
|
177 |
source.close() |
|
|
178 |
destination.close() |
|
|
179 |
os.remove(makefile_path+"~" ) |
|
33
|
180 |
|
|
36
|
181 |
call_subprocess(['make'], |
|
|
182 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
183 |
filter_stdout=filter_python_develop, |
|
|
184 |
show_stdout=True) |
|
|
185 |
|
|
34
|
186 |
call_subprocess(['make', 'install'], |
|
|
187 |
cwd=os.path.abspath(pylucene_src_path), |
|
|
188 |
filter_stdout=filter_python_develop, |
|
35
|
189 |
show_stdout=True) |
|
|
190 |
shutil.rmtree(src_dir) |
|
34
|
191 |
|
|
31
|
192 |
finally: |
|
34
|
193 |
logger.indent -= 2 |
|
31
|
194 |
script_dir = join(base_dir, 'bin') |
|
|
195 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
32
|
196 |
% join(script_dir, 'easy_install')) |
|
31
|
197 |
|
|
32
|
198 |
def ensure_dir(dir): |
|
31
|
199 |
if not os.path.exists(dir): |
|
|
200 |
logger.info('Creating directory %s' % dir) |
|
|
201 |
os.makedirs(dir) |
|
|
202 |
|
|
|
203 |
def filter_python_develop(line): |
|
|
204 |
if not line.strip(): |
|
|
205 |
return Logger.DEBUG |
|
|
206 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
|
207 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
|
208 |
'creating ', 'Copying ']: |
|
|
209 |
if line.startswith(prefix): |
|
|
210 |
return Logger.DEBUG |
|
|
211 |
return Logger.NOTIFY |
|
|
212 |
""" |
|
|
213 |
|
|
|
214 |
def main(): |
|
33
|
215 |
python_version = ".".join(map(str,sys.version_info[0:2])) |
|
|
216 |
text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version) |
|
31
|
217 |
if os.path.exists(script_name): |
|
|
218 |
f = open(script_name) |
|
|
219 |
cur_text = f.read() |
|
|
220 |
f.close() |
|
|
221 |
else: |
|
|
222 |
cur_text = '' |
|
|
223 |
print 'Updating %s' % script_name |
|
|
224 |
if cur_text == 'text': |
|
|
225 |
print 'No update' |
|
|
226 |
else: |
|
|
227 |
print 'Script changed; updating...' |
|
|
228 |
f = open(script_name, 'w') |
|
|
229 |
f.write(text) |
|
|
230 |
f.close() |
|
|
231 |
|
|
|
232 |
if __name__ == '__main__': |
|
|
233 |
main() |
|
|
234 |
|