|
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 import struct |
|
11 import glob |
|
12 import re |
|
13 |
|
14 join = os.path.join |
|
15 system_str = platform.system() |
|
16 |
|
17 URLS = { |
|
18 #'': {'setup': '', 'url':'', 'local':''}, |
|
19 'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.34.tar.gz', 'local':"distribute-0.6.34.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
20 'DJANGO': {'setup': 'django', 'url': 'https://github.com/IRI-Research/django/archive/d11d79737105223c99d15b3956837c1246f60441.tar.gz', 'local':"django-1.8.2.dev.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
21 'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/archive/1.5.3.tar.gz', 'local':"django-extensions-1.5.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
22 'DJANGO-REGISTRATION': { 'setup': 'django-registration', 'url':'https://github.com/macropin/django-registration/archive/v1.2.tar.gz', 'local':"django-registration-redux-1.2.tar.gz", 'install': {'method': 'easy_install', 'option_str': '-Z', 'dict_extra_env': None}}, |
|
23 'DJANGO-TEMPLATETAG-SUGAR': { 'setup': 'django-templatetag-sugar', 'url': 'https://github.com/alex/django-templatetag-sugar/archive/1.0.tar.gz', 'local': 'django-templatetag-sugar-1.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
24 'DJANGO-TAGGIT': { 'setup': 'django-taggit', 'url':'https://github.com/alex/django-taggit/archive/0.14.0.tar.gz', 'local':"django-taggit-0.14.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
25 'DJANGO-TAGGIT-TEMPLATETAGS': { 'setup': 'django-taggit-templatetags', 'url':'https://github.com/feuervogel/django-taggit-templatetags/archive/d2216c9d1888e0739a04899a36e5149b5cbb3381.zip', 'local':"django-taggit-templatetags-0.4.5dev-r0.zip", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
26 'OAUTH2': { 'setup': 'python-oauth2', 'url':"https://github.com/simplegeo/python-oauth2/tarball/hudson-python-oauth2-211", 'local':"oauth2-1.5.211.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}, |
|
27 'HTTPLIB2': { 'setup': 'python-httplib2', 'url':'https://pypi.python.org/packages/source/h/httplib2/httplib2-0.9.1.tar.gz', 'local':"httplib2-0.9.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
28 'DJANGO-OAUTH-PLUS': { 'setup': 'django-oauth-plus', 'url':'https://pypi.python.org/packages/source/d/django-oauth-plus/django-oauth-plus-2.2.6.tar.gz', 'local':"django-oauth-plus-2.2.6.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
29 'OPENID': {'setup':'openid', 'url':'http://pypi.python.org/packages/source/p/python-openid/python-openid-2.2.5.tar.gz', 'local':"python-openid-2.2.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
30 'SOCIAL_AUTH': {'setup':'social_auth', 'url':'https://github.com/omab/python-social-auth/archive/v0.2.7.tar.gz', 'local':"python-social-auth-0.2.7.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
31 'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'https://github.com/TauPan/django-guardian/archive/full-django-1.8-compatibility.tar.gz', 'local':"django-guardian-1.2.6.dev.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
32 'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'https://github.com/mariocesar/sorl-thumbnail/archive/v12.2.tar.gz', 'local':"sorl-thumbnail-12.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
33 'LIBJPEG': {'setup': None, 'url':'jpegsrc.v9.tar.gz', 'local':'jpegsrc.v9.tar.gz', 'install': {'method': 'install_libjpeg', 'option_str': None, 'dict_extra_env': None}}, |
|
34 'ZLIB': {'setup': None, 'url':'zlib-1.2.8.tar.gz', 'local':'zlib-1.2.8.tar.gz', 'install': {'method': 'install_zlib', 'option_str': None, 'dict_extra_env': None}}, |
|
35 'HAYSTACK': {'setup': 'django-haystack', 'url': 'https://github.com/toastdriven/django-haystack/archive/v2.3.1.tar.gz', 'local': 'django-haystack-2.3.1.tar.gz', 'install':{'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
36 'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v2.7.0.tar.gz', 'local':'requests-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
37 'ELASTICSEARCH': {'setup': 'elasticsearch', 'url':'https://github.com/elastic/elasticsearch-py/archive/1.4.0.tar.gz', 'local':'elasticsearch-1.4.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
38 'PYELASTICSEARCH': {'setup': 'pyelasticsearch', 'url':'https://pypi.python.org/packages/source/p/pyelasticsearch/pyelasticsearch-1.2.3.tar.gz', 'local':'pyelasticsearch-1.2.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
39 'WHOOSH': {'setup': 'whoosh', 'url':'https://bitbucket.org/mchaput/whoosh/get/2.7.0.tar.gz', 'local':'whoosh-2.7.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
40 'SETUPTOOLS_HG' : {'setup':'setuptools_hg', 'url':'https://bitbucket.org/jezdez/setuptools_hg/get/v0.4.tar.gz', 'local': 'setuptools_hg-0.4.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
41 # dependencies for Tastypie : mimeparse>=0.1.3, python-dateutil>=2.1, lxml, PyYAML (not necessary but we never know), python-digest, defusedxml |
|
42 'MIMEPARSE' : {'setup':'mimeparse', 'url':'http://pypi.python.org/packages/source/m/mimeparse/mimeparse-0.1.3.tar.gz', 'local': 'mimeparse-0.1.3.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
43 'SIX' : {'setup':'six', 'url':'https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz', 'local': 'six-1.9.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
44 'PYTHON-DATEUTIL' : {'setup':'python-dateutil', 'url':'https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz', 'local': 'python-dateutil-2.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
45 'PYYAML' : {'setup':'pyyaml', 'url':'http://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz', 'local': 'PyYAML-3.11.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
46 'PYTHON-DIGEST' : {'setup':'python-digest', 'url':'http://pypi.python.org/packages/source/p/python-digest/python-digest-1.7.tar.gz', 'local': 'python-digest-1.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
47 'DEFUSEDXML' : {'setup':'defusedxml', 'url':'https://pypi.python.org/packages/source/d/defusedxml/defusedxml-0.4.1.tar.gz', 'local': 'defusedxml-0.4.1.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
48 'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/toastdriven/django-tastypie/archive/130cb64eb6c0e688b1efe3b9839fbd86f034b4ed.tar.gz', 'local': 'django-tastypie-0.12.2.dev0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
49 'DJANGO-CORS-HEADERS' : {'setup':'django-cors-headers', 'url':'https://github.com/ottoyiu/django-cors-headers/archive/1.0.0.tar.gz', 'local': 'django-cors-headers-1.0.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
50 'DJANGO-CHUNCKED-UPLOADS' : {'setup': 'django-chuncked-uploads', 'url':'https://github.com/IRI-Research/django-chunked-uploads/archive/v0.6.tar.gz', 'local':'django-chunked-uploads-0.6.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
51 'OAUTHLIB': { 'setup': 'oauthlib', 'url':"https://github.com/idan/oauthlib/archive/0.7.2.tar.gz", 'local':"oauthlib-0.7.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
52 'URLLIB3': { 'setup': 'urllib3', 'url':'https://github.com/shazow/urllib3/archive/1.10.4.tar.gz', 'local':"urllib3-1.10.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
53 'SIMPLEJSON' : { 'setup': 'simplejson', 'url': 'https://github.com/simplejson/simplejson/archive/v3.6.5.tar.gz', 'local' : 'simplejson-3.6.5.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
54 'PYJWT' : { 'setup': 'pyjwt', 'url': 'https://github.com/jpadilla/pyjwt/archive/1.1.0.tar.gz', 'local' : 'pyjwt-1.1.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
55 'PYTHON-MIMEPARSE': { 'setup': 'python-mimeparse', 'url': 'https://pypi.python.org/packages/source/p/python-mimeparse/python-mimeparse-0.1.4.tar.gz', 'local' : 'python-mimeparse-0.1.4.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
56 'REQUESTS-OAUTHLIB': { 'setup': 'requests-oauthlib', 'url': 'https://github.com/requests/requests-oauthlib/archive/v0.5.0.tar.gz', 'local' : 'requests-oauthlib-0.5.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
57 'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-1.0.2.tar.gz', 'local':"south-1.0.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
58 } |
|
59 |
|
60 if system_str == 'Windows': |
|
61 |
|
62 size = 8 * struct.calcsize("P") |
|
63 if size==32: |
|
64 mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe" |
|
65 else: |
|
66 mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe" |
|
67 |
|
68 URLS.update({ |
|
69 'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe', 'local':"psycopg2-2.4.6.win32-py2.7-pg9.2.2-release.exe", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}}, |
|
70 'PIL': {'setup': 'pil', 'url': 'http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe', 'local':"PIL-1.1.7.win32-py2.7.exe", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}, |
|
71 'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.7/l/lxml/lxml-2.3-py2.7-win32.egg', 'local':"lxml-2.3-py2.7-win32.egg", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}, |
|
72 'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}, |
|
73 }) |
|
74 else: |
|
75 if system_str == "Darwin": |
|
76 lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.2', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'} |
|
77 if os.path.exists('/usr/local/opt/xz'): |
|
78 if not os.path.exists('/usr/local/opt/libxml2'): |
|
79 sys.exit("You have installed xz with Homebrew but do not have libxml2 installed with Homebrew. Install libxml2 with Homebrew and try again.") |
|
80 lxml_options = {'LDFLAGS': '-L/usr/local/opt/libxml2/lib', 'CPPFLAGS': '-I/usr/local/opt/libxml2/include'} |
|
81 mysql_method = 'install_mysql' |
|
82 else: |
|
83 lxml_options = None |
|
84 mysql_method = 'pip' |
|
85 |
|
86 URLS.update({ |
|
87 'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.tar.gz', 'local':"psycopg2-2.6.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
88 'PIL': {'setup': 'pillow', 'url': 'https://github.com/python-pillow/Pillow/archive/2.8.1.tar.gz', 'local':"Pillow-2.8.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
89 'LXML': {'setup': 'lxml', 'url': 'lxml-3.2.1.tar.bz2', 'local': 'lxml-3.2.1.tar.bz2', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': lxml_options}}, |
|
90 'MYSQL': { 'setup': 'mysql-python', 'url': 'http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.4b4/MySQL-python-1.2.4b4.tar.gz', 'local':"MySQL-python-1.2.4b4.tar.gz", 'install': {'method': mysql_method, 'option_str': None, 'dict_extra_env': None}}, |
|
91 }) |
|
92 |
|
93 |
|
94 class ResourcesEnv(object): |
|
95 |
|
96 def __init__(self, src_base, run_base, urls, normal_installs): |
|
97 self.src_base = src_base |
|
98 self.run_base = run_base |
|
99 self.URLS = {} |
|
100 self.__init_url(urls) |
|
101 self.NORMAL_INSTALL = normal_installs |
|
102 |
|
103 def get_src_base_path(self, fpath): |
|
104 return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
105 |
|
106 def get_run_res_base_path(self, fpath): |
|
107 return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/") |
|
108 |
|
109 def __add_package_def(self, key, dict): |
|
110 self.URLS[key] = dict |
|
111 |
|
112 def __init_url(self, urls): |
|
113 for key, url_dict in urls.items(): |
|
114 url_dict_copy = url_dict.copy() |
|
115 if url_dict.get('install', {}).get('method','pip') == 'pip-req': |
|
116 get_base_path = self.get_run_res_base_path |
|
117 else: |
|
118 get_base_path = self.get_src_base_path |
|
119 if not url_dict['url'].startswith("http://"): |
|
120 url_dict_copy['url'] = get_base_path(url_dict['url']) |
|
121 url_dict_copy['local'] = get_base_path(url_dict['local']) |
|
122 |
|
123 self.__add_package_def(key, url_dict_copy ) |
|
124 |
|
125 def ensure_dir(dir, logger): |
|
126 logger.notify('Check directory %s' % dir) |
|
127 if not os.path.exists(dir): |
|
128 logger.notify('Creating directory %s' % dir) |
|
129 os.makedirs(dir) |
|
130 |
|
131 def extend_parser(parser): |
|
132 parser.add_option( |
|
133 '--index-url', |
|
134 metavar='INDEX_URL', |
|
135 dest='index_url', |
|
136 default='http://pypi.python.org/simple/', |
|
137 help='base URL of Python Package Index') |
|
138 parser.add_option( |
|
139 '--type-install', |
|
140 metavar='type_install', |
|
141 dest='type_install', |
|
142 help='type install : local, url, setup - default : local') |
|
143 parser.add_option( |
|
144 '--ignore-packages', |
|
145 metavar='ignore_packages', |
|
146 dest='ignore_packages', |
|
147 default=None, |
|
148 help='list of comma separated keys for package to ignore') |
|
149 parser.add_option( |
|
150 '--no-clear', |
|
151 metavar='do not clear env', |
|
152 dest='clear', |
|
153 default=True, |
|
154 action='store_false', |
|
155 help='do not clear env') |
|
156 |
|
157 |
|
158 |
|
159 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): |
|
160 psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
161 shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
162 #extract psycopg2 |
|
163 zf = zipfile.ZipFile(psycopg2_src) |
|
164 psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
165 zf.extractall(psycopg2_base_path) |
|
166 zf.close() |
|
167 |
|
168 psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
169 shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2'))) |
|
170 shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.4.5-py2.7.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'site-packages'))) |
|
171 |
|
172 |
|
173 def install_mysql(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
174 |
|
175 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]] |
|
176 if option_str : |
|
177 args.insert(4,option_str) |
|
178 call_subprocess(args, |
|
179 cwd=os.path.abspath(tmp_dir), |
|
180 filter_stdout=filter_python_develop, |
|
181 show_stdout=True, |
|
182 extra_env=extra_env) |
|
183 |
|
184 mysqlconfig_output = [] |
|
185 |
|
186 call_subprocess(['mysql_config', '--libmysqld-libs'], |
|
187 cwd=os.path.abspath(tmp_dir), |
|
188 filter_stdout=lambda line: mysqlconfig_output.append(line), |
|
189 show_stdout=True) |
|
190 |
|
191 mysqlconfig_output = "".join(mysqlconfig_output) |
|
192 m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output) |
|
193 if m: |
|
194 repdylibpath = m.group(1) |
|
195 else: |
|
196 repdylibpath = '/usr/local/mysql/lib' |
|
197 |
|
198 dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib") |
|
199 def key_func(s): |
|
200 m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s) |
|
201 if m: |
|
202 return int(m.group(1)) |
|
203 else: |
|
204 return sys.maxint |
|
205 dyliblist.sort(key=key_func) |
|
206 |
|
207 if dyliblist: |
|
208 dylibpath = dyliblist[0] |
|
209 else: |
|
210 dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib' |
|
211 |
|
212 dylibname = os.path.basename(dylibpath) |
|
213 sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so') |
|
214 |
|
215 call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath], |
|
216 cwd=os.path.abspath(tmp_dir), |
|
217 filter_stdout=filter_python_develop, |
|
218 show_stdout=True) |
|
219 |
|
220 |
|
221 def gen_install_comp_lib(lib_name, lib_key, configure_options=[], configure_env={}): |
|
222 |
|
223 def install_lib(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop): |
|
224 lib_src = os.path.join(src_dir,lib_name+".tar.gz") |
|
225 logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src)) |
|
226 shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src) |
|
227 tf = tarfile.open(lib_src,'r:gz') |
|
228 lib_base_path = os.path.join(src_dir, lib_name) |
|
229 logger.notify("Extract %s to %s " % (lib_name,lib_base_path)) |
|
230 tf.extractall(lib_base_path) |
|
231 tf.close() |
|
232 |
|
233 lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0]) |
|
234 |
|
235 |
|
236 context_map = { |
|
237 'option_str' : option_str, |
|
238 'home_dir': os.path.abspath(home_dir), |
|
239 'lib_dir': os.path.abspath(lib_dir), |
|
240 'tmp_dir': os.path.abspath(tmp_dir), |
|
241 'src_dir': os.path.abspath(src_dir), |
|
242 } |
|
243 |
|
244 configure_options_trans = map(lambda s: s % context_map, configure_options) |
|
245 configure_env_trans = {k: s % context_map for k,s in configure_env.items()} |
|
246 |
|
247 logger.notify(lib_name + " configure in " + lib_src_path) |
|
248 call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options_trans, |
|
249 cwd=os.path.abspath(lib_src_path), |
|
250 filter_stdout=filter_python_develop, |
|
251 show_stdout=True, |
|
252 extra_env=configure_env_trans |
|
253 ) |
|
254 |
|
255 logger.notify(lib_name + " make in " + lib_src_path) |
|
256 call_subprocess(['make'], |
|
257 cwd=os.path.abspath(lib_src_path), |
|
258 filter_stdout=filter_python_develop, |
|
259 show_stdout=True) |
|
260 |
|
261 logger.notify(lib_name + "make install in " + lib_src_path) |
|
262 call_subprocess(['make', 'install'], |
|
263 cwd=os.path.abspath(lib_src_path), |
|
264 filter_stdout=filter_python_develop, |
|
265 show_stdout=True) |
|
266 return install_lib |
|
267 |
|
268 install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'], {}) |
|
269 install_zlib = gen_install_comp_lib("zlib", "ZLIB", [], {}) |
|
270 |
|
271 #osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'} |
|
272 osx_extra_env = {} |
|
273 |
|
274 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None): |
|
275 |
|
276 all_urls = URLS.copy() |
|
277 if urls is not None: |
|
278 all_urls.update(urls) |
|
279 |
|
280 res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs) |
|
281 |
|
282 def filter_python_develop(line): |
|
283 if not line.strip(): |
|
284 return Logger.DEBUG |
|
285 for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
286 'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
287 'creating ', 'Copying ']: |
|
288 if line.startswith(prefix): |
|
289 return Logger.DEBUG |
|
290 return Logger.NOTIFY |
|
291 |
|
292 |
|
293 def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
|
294 logger.notify("Install %s from %s with %s" % (key,res_path,method)) |
|
295 if method == 'pip': |
|
296 if sys.platform == 'win32': |
|
297 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path] |
|
298 else: |
|
299 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_path] |
|
300 if option_str : |
|
301 args.append(option_str) |
|
302 if res_source_key == 'local': |
|
303 if extra_env is None: |
|
304 extra_env = {} |
|
305 args.insert(2, '-f') |
|
306 args.insert(3, res_env.get_src_base_path("")) |
|
307 args.insert(4, '--no-index') |
|
308 logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
309 call_subprocess(args, |
|
310 cwd=os.path.abspath(tmp_dir), |
|
311 filter_stdout=filter_python_develop, |
|
312 show_stdout=True, |
|
313 extra_env=extra_env) |
|
314 if method == 'pip-req': |
|
315 if sys.platform == 'win32': |
|
316 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-r', res_path] |
|
317 else: |
|
318 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-r', res_path] |
|
319 if option_str : |
|
320 args.append(option_str) |
|
321 if res_source_key == 'local': |
|
322 if extra_env is None: |
|
323 extra_env = {} |
|
324 args.insert(2, '-f') |
|
325 args.insert(3, res_env.get_src_base_path("")) |
|
326 args.insert(4, '--no-index') |
|
327 logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
328 call_subprocess(args, |
|
329 cwd=os.path.abspath(tmp_dir), |
|
330 filter_stdout=filter_python_develop, |
|
331 show_stdout=True, |
|
332 extra_env=extra_env) |
|
333 else: |
|
334 if sys.platform == 'win32': |
|
335 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_path] |
|
336 else: |
|
337 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_path] |
|
338 if option_str : |
|
339 args.insert(1,option_str) |
|
340 call_subprocess(args, |
|
341 cwd=os.path.abspath(tmp_dir), |
|
342 filter_stdout=filter_python_develop, |
|
343 show_stdout=True, |
|
344 extra_env=extra_env) |
|
345 |
|
346 |
|
347 def after_install(options, home_dir): |
|
348 |
|
349 global logger |
|
350 |
|
351 verbosity = options.verbose - options.quiet |
|
352 logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
|
353 |
|
354 |
|
355 home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
356 base_dir = os.path.dirname(home_dir) |
|
357 src_dir = os.path.join(home_dir, 'src') |
|
358 tmp_dir = os.path.join(home_dir, 'tmp') |
|
359 ensure_dir(src_dir, logger) |
|
360 ensure_dir(tmp_dir, logger) |
|
361 system_str = platform.system() |
|
362 |
|
363 res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local') |
|
364 if res_source_key is None: |
|
365 res_source_key = 'local' |
|
366 |
|
367 ignore_packages = [] |
|
368 |
|
369 if system_str == 'Windows': |
|
370 default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}} |
|
371 else: |
|
372 default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}} |
|
373 |
|
374 if options.ignore_packages : |
|
375 ignore_packages = options.ignore_packages.split(",") |
|
376 |
|
377 logger.indent += 2 |
|
378 try: |
|
379 for key in res_env.NORMAL_INSTALL: |
|
380 install_options = None |
|
381 if isinstance(key, dict): |
|
382 install_options = key.get('install', default_install_options) |
|
383 install_options['method'] = 'pip-req' |
|
384 res_path = res_env.get_run_res_base_path(key['requirement']) |
|
385 else: |
|
386 if key not in res_env.URLS: |
|
387 logger.notify("%s not found in def : passing" % (key,)) |
|
388 install_options = res_env.URLS[key].get('install', None) |
|
389 res_path = res_env.URLS[key][res_source_key] |
|
390 if install_options is None: |
|
391 install_options = default_install_options |
|
392 method = install_options.get('method', default_install_options['method']) |
|
393 option_str = install_options.get('option_str', default_install_options['option_str']) |
|
394 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env']) |
|
395 if not extra_env: |
|
396 extra_env = {} |
|
397 |
|
398 if 'TMPDIR' not in extra_env: |
|
399 extra_env['TMPDIR'] = os.path.abspath(tmp_dir) |
|
400 if system_str == 'Darwin': |
|
401 for flag_key, flag_value in iter(osx_extra_env.items()): |
|
402 flags = extra_env.get(flag_key, '') |
|
403 if flag_value not in flags: |
|
404 #flags += " -Wno-error=unused-command-line-argument-hard-error-in-future" |
|
405 flags += " "+flag_value |
|
406 extra_env[flag_key] = flags.strip() |
|
407 |
|
408 #isinstance(lst, (list, tuple)) |
|
409 if key not in ignore_packages: |
|
410 logger.notify("install %s with method %s" % (key, repr(method))) |
|
411 if callable(method): |
|
412 method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
413 elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']: |
|
414 globals()[method](option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
415 else: |
|
416 normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
|
417 |
|
418 logger.notify("Clear source dir") |
|
419 shutil.rmtree(src_dir) |
|
420 |
|
421 finally: |
|
422 logger.indent -= 2 |
|
423 script_dir = join(base_dir, bin_dir) |
|
424 logger.notify('Run "%s Package" to install new packages that provide builds' |
|
425 % join(script_dir, 'easy_install')) |
|
426 |
|
427 def adjust_options(options, args): |
|
428 if not options_to_add: |
|
429 return |
|
430 for opt,opt_val in options_to_add.items(): |
|
431 #if not hasattr(options,test_opt) or getattr(options, test_opt) is None: |
|
432 setattr(options, opt, opt_val) |
|
433 |
|
434 return adjust_options, extend_parser, after_install |