| author | ymh <ymh.work@gmail.com> |
| Thu, 16 Feb 2012 21:48:40 +0100 | |
| changeset 119 | e3ebe3545f72 |
| parent 15 | a9136d8f0b4a |
| child 122 | fde8335a037c |
| permissions | -rw-r--r-- |
| 0 | 1 |
import sys |
2 |
import os |
|
3 |
import os.path |
|
4 |
import shutil |
|
5 |
import tarfile |
|
6 |
import zipfile |
|
7 |
import urllib |
|
8 |
import platform |
|
9 |
import patch |
|
10 |
||
11 |
join = os.path.join |
|
12 |
system_str = platform.system() |
|
13 |
||
14 |
||
15 |
URLS = { |
|
16 |
#'': {'setup': '', 'url':'', 'local':''}, |
|
17 |
'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz', 'local':"distribute-0.6.14.tar.gz"}, |
|
|
119
e3ebe3545f72
first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
18 |
'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.3.1/tarball/', 'local':"Django-1.3.1.tar.gz"}, |
| 0 | 19 |
'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/0.6', 'local':"django-extensions-0.6.tar.gz"}, |
20 |
'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.7.3.tar.gz', 'local':"south-0.7.3.tar.gz"}, |
|
21 |
'HTTPLIB2': { 'setup': 'python-httplib2', 'url':'http://httplib2.googlecode.com/files/httplib2-0.6.0.tar.gz', 'local':"httplib2-0.6.0.tar.gz"}, |
|
22 |
'HAYSTACK': { 'setup': 'haystack', 'url':'https://github.com/toastdriven/django-haystack/zipball/v1.2.2', 'local': "django-haystack-v1.2.2.tar.gz"}, |
|
23 |
'WHOOSH' : { 'setup': 'Whoosh', 'url': 'https://bitbucket.org/mchaput/whoosh/get/tip.tar.bz2', 'local': 'whoosh-1.8.3.tar.bz2'}, |
|
|
15
a9136d8f0b4a
add commant to reorder tags and query wikipedia
ymh <ymh.work@gmail.com>
parents:
10
diff
changeset
|
24 |
'WIKITOOLS' : { 'setup': 'wikitools', 'url': 'wikitools.tar.bz2', 'local': 'wikitools.tar.bz2'}, |
|
119
e3ebe3545f72
first implementation of django version.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
25 |
'RDFLIB' : { 'setup': 'rdflib', 'url': 'http://rdflib.googlecode.com/files/rdflib-3.2.0.tar.gz', 'local': 'rdflib-3.2.0.tar.gz'}, |
| 0 | 26 |
} |
27 |
||
28 |
if system_str == 'Windows': |
|
29 |
URLS.update({ |
|
30 |
'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip', 'local':"psycopg2-2.0.14.win32-py2.6-pg8.4.3-release.zip"}, |
|
31 |
'JCC': {'setup': 'jcc', 'url': 'http://pylucene-win32-binary.googlecode.com/files/JCC-2.6-py2.6-win32.egg', 'local':"JCC-2.6-py2.6-win32.egg"}, |
|
32 |
'PYLUCENE': {'setup': 'pylucene', 'url': 'http://pylucene-win32-binary.googlecode.com/files/lucene-3.0.2-py2.6-win32.egg', 'local':"lucene-3.0.2-py2.6-win32.egg"}, |
|
33 |
'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.6.exe', 'local':"PIL-1.1.7.win32-py2.6.exe"}, |
|
| 2 | 34 |
'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.6/l/lxml/lxml-2.2.2-py2.6-win32.egg', 'local':"lxml-2.2.2-py2.6-win32.egg"}, |
35 |
'PYYAML' : { 'setup': 'PyYAML', 'url': 'http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.6.exe', 'local': 'PyYAML-3.09.win32-py2.6.exe'}, |
|
| 10 | 36 |
'PYSTEMMER' : { 'setup': 'pystemmer', 'url': 'PyStemmer_compiled_for_pc.zip', 'local': 'PyStemmer_compiled_for_pc.zip'}, |
| 0 | 37 |
}) |
38 |
else: |
|
39 |
URLS.update({ |
|
40 |
'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.tar.gz', 'local':"psycopg2-2.4.tar.gz"}, |
|
41 |
'PYLUCENE': {'setup': 'pylucene', 'url': 'http://apache.crihan.fr/dist//lucene/pylucene/pylucene-3.1.0-1-src.tar.gz', 'local':"pylucene-3.1.0-1-src.tar.gz"}, |
|
42 |
'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz"}, |
|
| 2 | 43 |
'LXML': {'setup': 'lxml', 'url':"lxml-2.3.tar.bz2", 'local':"lxml-2.3.tar.bz2"}, |
44 |
'PYYAML' : { 'setup': 'PyYAML', 'url': 'http://pyyaml.org/download/pyyaml/PyYAML-3.09.tar.gz', 'local': 'PyYAML-3.09.tar.gz'}, |
|
| 0 | 45 |
}) |
46 |
||
47 |
||
48 |
||
49 |
class ResourcesEnv(object): |
|
50 |
||
51 |
def __init__(self, src_base, urls, normal_installs): |
|
52 |
self.src_base = src_base |
|
53 |
self.URLS = {} |
|
54 |
self.__init_url(urls) |
|
55 |
self.NORMAL_INSTALL = normal_installs |
|
56 |
||
57 |
def get_src_base_path(self, fpath): |
|
58 |
return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
59 |
||
60 |
def __add_package_def(self, key, setup, url, local): |
|
61 |
self.URLS[key] = {'setup':setup, 'url':url, 'local':self.get_src_base_path(local)} |
|
62 |
||
63 |
def __init_url(self, urls): |
|
64 |
for key, url_dict in urls.items(): |
|
65 |
url = url_dict['url'] |
|
66 |
if not url.startswith("http://"): |
|
67 |
url = self.get_src_base_path(url) |
|
68 |
self.__add_package_def(key, url_dict["setup"], url, url_dict["local"]) |
|
69 |
||
70 |
def ensure_dir(dir, logger): |
|
71 |
if not os.path.exists(dir): |
|
72 |
logger.notify('Creating directory %s' % dir) |
|
73 |
os.makedirs(dir) |
|
74 |
||
75 |
def extend_parser(parser): |
|
76 |
parser.add_option( |
|
77 |
'--index-url', |
|
78 |
metavar='INDEX_URL', |
|
79 |
dest='index_url', |
|
80 |
default='http://pypi.python.org/simple/', |
|
81 |
help='base URL of Python Package Index') |
|
82 |
parser.add_option( |
|
83 |
'--type-install', |
|
84 |
metavar='type_install', |
|
85 |
dest='type_install', |
|
86 |
default='local', |
|
87 |
help='type install : local, url, setup') |
|
88 |
parser.add_option( |
|
89 |
'--ignore-packages', |
|
90 |
metavar='ignore_packages', |
|
91 |
dest='ignore_packages', |
|
92 |
default=None, |
|
93 |
help='list of comma separated keys for package to ignore') |
|
94 |
||
95 |
def adjust_options(options, args): |
|
96 |
pass |
|
97 |
||
98 |
||
99 |
def install_pylucene(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
100 |
||
101 |
logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key]) |
|
102 |
pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
103 |
if res_source_key == 'local': |
|
104 |
shutil.copy(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
105 |
else: |
|
106 |
urllib.urlretrieve(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
107 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
108 |
pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
109 |
logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
110 |
tf.extractall(pylucene_base_path) |
|
111 |
tf.close() |
|
112 |
||
113 |
pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
114 |
jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
115 |
||
116 |
#install jcc |
|
117 |
||
118 |
#patch for linux |
|
119 |
if system_str == 'Linux' : |
|
120 |
olddir = os.getcwd() |
|
121 |
setuptools_path = os.path.join(lib_dir, 'site-packages', 'setuptools') |
|
122 |
if os.path.exists(setuptools_path) and os.path.isdir(setuptools_path): |
|
123 |
patch_dest_path = os.path.join(lib_dir, 'site-packages') |
|
124 |
else: |
|
125 |
patch_dest_path = os.path.join(lib_dir,'site-packages','setuptools-0.6c11-py%s.%s.egg' % (sys.version_info[0], sys.version_info[1])) |
|
126 |
if os.path.isfile(patch_dest_path): |
|
127 |
# must unzip egg |
|
128 |
# rename file and etract all |
|
129 |
shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
130 |
zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
131 |
zf.extractall(patch_dest_path) |
|
132 |
os.remove(patch_dest_path + ".zip") |
|
133 |
logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
134 |
os.chdir(patch_dest_path) |
|
135 |
p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
136 |
p.apply() |
|
137 |
os.chdir(olddir) |
|
138 |
||
139 |
logger.notify("Install jcc") |
|
140 |
call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
141 |
cwd=jcc_src_path, |
|
142 |
filter_stdout=filter_python_develop, |
|
143 |
show_stdout=True) |
|
144 |
#install pylucene |
|
145 |
||
146 |
logger.notify("Install pylucene") |
|
147 |
#modify makefile |
|
148 |
makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
149 |
logger.notify("Modify makefile %s " % makefile_path) |
|
150 |
shutil.move( makefile_path, makefile_path+"~" ) |
|
151 |
||
152 |
destination= open( makefile_path, "w" ) |
|
153 |
source= open( makefile_path+"~", "r" ) |
|
154 |
destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\n") |
|
155 |
destination.write("ANT=ant\n") |
|
156 |
destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\n") |
|
157 |
||
158 |
if system_str == "Darwin": |
|
159 |
if sys.version_info >= (2,6): |
|
160 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
161 |
else: |
|
162 |
destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\n") |
|
163 |
destination.write("NUM_FILES=2\n") |
|
164 |
elif system_str == "Windows": |
|
165 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
166 |
destination.write("NUM_FILES=2\n") |
|
167 |
else: |
|
168 |
if sys.version_info >= (2,6) and sys.version_info <= (2,7): |
|
169 |
destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\n") |
|
170 |
else: |
|
171 |
destination.write("JCC=$(PYTHON) -m jcc --shared\n") |
|
172 |
destination.write("NUM_FILES=2\n") |
|
173 |
for line in source: |
|
174 |
destination.write( line ) |
|
175 |
source.close() |
|
176 |
destination.close() |
|
177 |
os.remove(makefile_path+"~" ) |
|
178 |
||
179 |
logger.notify("pylucene make") |
|
180 |
call_subprocess(['make'], |
|
181 |
cwd=os.path.abspath(pylucene_src_path), |
|
182 |
filter_stdout=filter_python_develop, |
|
183 |
show_stdout=True) |
|
184 |
||
185 |
logger.notify("pylucene make install") |
|
186 |
call_subprocess(['make', 'install'], |
|
187 |
cwd=os.path.abspath(pylucene_src_path), |
|
188 |
filter_stdout=filter_python_develop, |
|
189 |
show_stdout=True) |
|
190 |
||
191 |
||
192 |
def install_psycopg2(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
193 |
psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
194 |
shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
195 |
#extract psycopg2 |
|
196 |
zf = zipfile.ZipFile(psycopg2_src) |
|
197 |
psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
198 |
zf.extractall(psycopg2_base_path) |
|
199 |
zf.close() |
|
200 |
||
201 |
psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
202 |
shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2'))) |
|
| 10 | 203 |
shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.14-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages'))) |
| 0 | 204 |
|
| 10 | 205 |
def install_pystemmer(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
206 |
print "install PYSTEMMER from " + res_env.URLS['PYSTEMMER'][res_source_key] |
|
207 |
pystemmer_src = os.path.join(src_dir,"pystemmer.zip") |
|
208 |
shutil.copy(res_env.URLS['PYSTEMMER'][res_source_key], pystemmer_src) |
|
209 |
#extract pystemmer |
|
210 |
zf = zipfile.ZipFile(pystemmer_src) |
|
211 |
pystemmer_base_path = os.path.join(src_dir,"pystemmer") |
|
212 |
zf.extractall(pystemmer_base_path) |
|
213 |
zf.close() |
|
214 |
||
215 |
shutil.copy(os.path.join(pystemmer_base_path, 'Stemmer.pyd'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages'))) |
|
216 |
shutil.copy(os.path.join(pystemmer_base_path, 'PyStemmer-1.0.1-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages'))) |
|
217 |
||
218 |
||
| 2 | 219 |
#TO DO does not work in virtual env |
220 |
def install_libyaml(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
221 |
logger.notify("Get libyaml from %s " % res_env.URLS['LIBYAML'][res_source_key]) |
|
222 |
libyaml_src = os.path.join(src_dir,"libyaml.tar.gz") |
|
223 |
if res_source_key == 'local': |
|
224 |
shutil.copy(res_env.URLS['LIBYAML'][res_source_key], libyaml_src) |
|
225 |
else: |
|
226 |
urllib.urlretrieve(res_env.URLS['LIBYAML'][res_source_key], libyaml_src) |
|
227 |
tf = tarfile.open(pylucene_src,'r:gz') |
|
228 |
libyaml_base_path = os.path.join(src_dir,"libyaml") |
|
229 |
logger.notify("Extract libyaml to %s " % libyaml_base_path) |
|
230 |
tf.extractall(libyaml_base_path) |
|
231 |
tf.close() |
|
232 |
||
233 |
libyaml_src_path = os.path.join(libyaml_base_path, os.listdir(libyaml_base_path)[0]) |
|
234 |
||
235 |
logger.notify("libyaml configure") |
|
236 |
call_subprocess(['configure'], |
|
237 |
cwd=os.path.abspath(libyaml_src_path), |
|
238 |
filter_stdout=filter_python_develop, |
|
239 |
show_stdout=True) |
|
240 |
||
241 |
logger.notify("libyaml make") |
|
242 |
call_subprocess(['make'], |
|
243 |
cwd=os.path.abspath(libyaml_src_path), |
|
244 |
filter_stdout=filter_python_develop, |
|
245 |
show_stdout=True) |
|
246 |
||
247 |
logger.notify("libyaml make install") |
|
248 |
call_subprocess(['make', 'install'], |
|
249 |
cwd=os.path.abspath(libyaml_src_path), |
|
250 |
filter_stdout=filter_python_develop, |
|
251 |
show_stdout=True) |
|
252 |
||
253 |
||
| 0 | 254 |
|
255 |
||
256 |
def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, urls=None): |
|
257 |
||
258 |
all_urls = URLS.copy() |
|
259 |
if urls is not None: |
|
260 |
all_urls.update(urls) |
|
261 |
||
262 |
res_env = ResourcesEnv(src_base, all_urls, normal_installs) |
|
263 |
||
264 |
def filter_python_develop(line): |
|
265 |
if not line.strip(): |
|
266 |
return Logger.DEBUG |
|
267 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
268 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
269 |
'creating ', 'Copying ']: |
|
270 |
if line.startswith(prefix): |
|
271 |
return Logger.DEBUG |
|
272 |
return Logger.NOTIFY |
|
273 |
||
274 |
||
275 |
def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
|
276 |
logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method)) |
|
277 |
if method == 'pip': |
|
278 |
if sys.platform == 'win32': |
|
279 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
|
280 |
else: |
|
281 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
|
282 |
if option_str : |
|
283 |
args.insert(4,option_str) |
|
284 |
call_subprocess(args, |
|
285 |
cwd=os.path.abspath(tmp_dir), |
|
286 |
filter_stdout=filter_python_develop, |
|
287 |
show_stdout=True, |
|
288 |
extra_env=extra_env) |
|
289 |
else: |
|
290 |
if sys.platform == 'win32': |
|
291 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]] |
|
292 |
else: |
|
293 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]] |
|
294 |
if option_str : |
|
295 |
args.insert(1,option_str) |
|
296 |
call_subprocess(args, |
|
297 |
cwd=os.path.abspath(tmp_dir), |
|
298 |
filter_stdout=filter_python_develop, |
|
299 |
show_stdout=True, |
|
300 |
extra_env=extra_env) |
|
301 |
||
302 |
||
303 |
def after_install(options, home_dir): |
|
304 |
||
305 |
global logger |
|
306 |
||
307 |
verbosity = options.verbose - options.quiet |
|
308 |
logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
|
309 |
||
310 |
||
311 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
312 |
base_dir = os.path.dirname(home_dir) |
|
313 |
src_dir = os.path.join(home_dir, 'src') |
|
314 |
tmp_dir = os.path.join(home_dir, 'tmp') |
|
315 |
ensure_dir(src_dir, logger) |
|
316 |
ensure_dir(tmp_dir, logger) |
|
317 |
system_str = platform.system() |
|
318 |
||
319 |
res_source_key = options.type_install |
|
320 |
||
321 |
ignore_packages = [] |
|
322 |
||
323 |
if options.ignore_packages : |
|
324 |
ignore_packages = options.ignore_packages.split(",") |
|
325 |
||
326 |
logger.indent += 2 |
|
327 |
try: |
|
328 |
for key, method, option_str, extra_env in res_env.NORMAL_INSTALL: |
|
329 |
if key not in ignore_packages: |
|
330 |
if callable(method): |
|
331 |
method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
332 |
else: |
|
333 |
normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
|
334 |
||
335 |
logger.notify("Clear source dir") |
|
336 |
shutil.rmtree(src_dir) |
|
337 |
||
338 |
finally: |
|
339 |
logger.indent -= 2 |
|
340 |
script_dir = join(base_dir, bin_dir) |
|
341 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
342 |
% join(script_dir, 'easy_install')) |
|
343 |
||
344 |
||
345 |
return adjust_options, extend_parser, after_install |