author | ymh <ymh.work@gmail.com> |
Thu, 16 Jul 2015 18:05:22 +0200 | |
changeset 23 | 16303a95fdb8 |
parent 21 | d8f103659dfd |
child 52 | d5f030dbdb47 |
permissions | -rw-r--r-- |
3 | 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}}, |
|
16 | 20 |
'DJANGO': {'setup': 'django', 'url': 'https://github.com/IRI-Research/django/archive/1.8.3+IRI.tar.gz', 'local':"Django-1.8.3.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.5.tar.gz', 'local':"django-extensions-1.5.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
3 | 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}}, |
|
16 | 24 |
'DJANGO-TAGGIT': { 'setup': 'django-taggit', 'url':'https://github.com/alex/django-taggit/archive/0.16.2.tar.gz', 'local':"django-taggit-0.16.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
|
16 | 28 |
'DJANGO-OAUTH-PLUS': { 'setup': 'django-oauth-plus', 'url':'https://bitbucket.org/david/django-oauth-plus/get/2.2.8.tar.gz', 'local':"django-oauth-plus-2.2.8.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
|
16 | 31 |
'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'https://github.com/lukaszb/django-guardian/archive/v1.3.tar.gz', 'local':"django-guardian-1.3.dev.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
|
4 | 35 |
'HAYSTACK': {'setup': 'django-haystack', 'url': 'https://github.com/toastdriven/django-haystack/archive/v2.4.0.tar.gz', 'local': 'django-haystack-2.4.0.tar.gz', 'install':{'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
|
21
d8f103659dfd
tastypie 0.12.2 is NOT ready foor django 1.8
ymh <ymh.work@gmail.com>
parents:
16
diff
changeset
|
48 |
'DJANGO-TASTYPIE' : {'setup':'django-tastypie', 'url':'https://github.com/django-tastypie/django-tastypie/archive/master.tar.gz', 'local': 'django-tastypie-0.12.2.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
16 | 50 |
'DJANGO-CHUNCKED-UPLOADS' : {'setup': 'django-chuncked-uploads', 'url':'https://github.com/IRI-Research/django-chunked-uploads/archive/v0.7.tar.gz', 'local':'django-chunked-uploads-0.7.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 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}}, |
|
14
9618fe364dca
add missing django-cas library + upgrading virtualenv
ymh <ymh.work@gmail.com>
parents:
4
diff
changeset
|
57 |
'DJANGO_CAS_NG': {'setup': 'django-cas-ng', 'url': 'https://github.com/mingchen/django-cas-ng/archive/v3.4.2.tar.gz', 'local':'django-cas-ng-3.4.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
23 | 58 |
'DJANGO_URL_SHORTENER': {'setup': 'django-url-shortener', 'url': 'https://github.com/IRI-Research/django-url-shortener/archive/0.1.tar.gz', 'local': 'django-url-shortener-0.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 59 |
} |
60 |
||
61 |
if system_str == 'Windows': |
|
62 |
||
63 |
size = 8 * struct.calcsize("P") |
|
64 |
if size==32: |
|
65 |
mysqlres = "MySQL-python-1.2.3.win32-py2.7.exe" |
|
66 |
else: |
|
67 |
mysqlres = "MySQL-python-1.2.3.win-amd64-py2.7.exe" |
|
68 |
||
69 |
URLS.update({ |
|
70 |
'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}}, |
|
71 |
'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}}, |
|
72 |
'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}}, |
|
73 |
'MYSQL': { 'setup': 'mysql-python', 'url': mysqlres, 'local': mysqlres, 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}, |
|
74 |
}) |
|
75 |
else: |
|
76 |
if system_str == "Darwin": |
|
77 |
lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.2', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'} |
|
78 |
if os.path.exists('/usr/local/opt/xz'): |
|
79 |
if not os.path.exists('/usr/local/opt/libxml2'): |
|
80 |
sys.exit("You have installed xz with Homebrew but do not have libxml2 installed with Homebrew. Install libxml2 with Homebrew and try again.") |
|
81 |
lxml_options = {'LDFLAGS': '-L/usr/local/opt/libxml2/lib', 'CPPFLAGS': '-I/usr/local/opt/libxml2/include'} |
|
82 |
mysql_method = 'install_mysql' |
|
83 |
else: |
|
84 |
lxml_options = None |
|
85 |
mysql_method = 'pip' |
|
86 |
||
87 |
URLS.update({ |
|
88 |
'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}}, |
|
16 | 89 |
'PIL': {'setup': 'pillow', 'url': 'https://github.com/python-pillow/Pillow/archive/2.9.0.tar.gz', 'local':"Pillow-2.9.0.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
3 | 90 |
'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}}, |
91 |
'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}}, |
|
92 |
}) |
|
93 |
||
94 |
||
95 |
class ResourcesEnv(object): |
|
96 |
||
97 |
def __init__(self, src_base, run_base, urls, normal_installs): |
|
98 |
self.src_base = src_base |
|
99 |
self.run_base = run_base |
|
100 |
self.URLS = {} |
|
101 |
self.__init_url(urls) |
|
102 |
self.NORMAL_INSTALL = normal_installs |
|
103 |
||
104 |
def get_src_base_path(self, fpath): |
|
105 |
return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
106 |
||
107 |
def get_run_res_base_path(self, fpath): |
|
108 |
return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/") |
|
109 |
||
110 |
def __add_package_def(self, key, dict): |
|
111 |
self.URLS[key] = dict |
|
112 |
||
113 |
def __init_url(self, urls): |
|
114 |
for key, url_dict in urls.items(): |
|
115 |
url_dict_copy = url_dict.copy() |
|
116 |
if url_dict.get('install', {}).get('method','pip') == 'pip-req': |
|
117 |
get_base_path = self.get_run_res_base_path |
|
118 |
else: |
|
119 |
get_base_path = self.get_src_base_path |
|
120 |
if not url_dict['url'].startswith("http://"): |
|
121 |
url_dict_copy['url'] = get_base_path(url_dict['url']) |
|
122 |
url_dict_copy['local'] = get_base_path(url_dict['local']) |
|
123 |
||
124 |
self.__add_package_def(key, url_dict_copy ) |
|
125 |
||
126 |
def ensure_dir(dir, logger): |
|
127 |
logger.notify('Check directory %s' % dir) |
|
128 |
if not os.path.exists(dir): |
|
129 |
logger.notify('Creating directory %s' % dir) |
|
130 |
os.makedirs(dir) |
|
131 |
||
132 |
def extend_parser(parser): |
|
133 |
parser.add_option( |
|
134 |
'--index-url', |
|
135 |
metavar='INDEX_URL', |
|
136 |
dest='index_url', |
|
137 |
default='http://pypi.python.org/simple/', |
|
138 |
help='base URL of Python Package Index') |
|
139 |
parser.add_option( |
|
140 |
'--type-install', |
|
141 |
metavar='type_install', |
|
142 |
dest='type_install', |
|
143 |
help='type install : local, url, setup - default : local') |
|
144 |
parser.add_option( |
|
145 |
'--ignore-packages', |
|
146 |
metavar='ignore_packages', |
|
147 |
dest='ignore_packages', |
|
148 |
default=None, |
|
149 |
help='list of comma separated keys for package to ignore') |
|
150 |
parser.add_option( |
|
151 |
'--no-clear', |
|
152 |
metavar='do not clear env', |
|
153 |
dest='clear', |
|
154 |
default=True, |
|
155 |
action='store_false', |
|
156 |
help='do not clear env') |
|
157 |
||
158 |
||
159 |
||
160 |
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): |
|
161 |
psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
162 |
shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
163 |
#extract psycopg2 |
|
164 |
zf = zipfile.ZipFile(psycopg2_src) |
|
165 |
psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
166 |
zf.extractall(psycopg2_base_path) |
|
167 |
zf.close() |
|
168 |
||
169 |
psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
170 |
shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2'))) |
|
171 |
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'))) |
|
172 |
||
173 |
||
174 |
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): |
|
175 |
||
176 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]] |
|
177 |
if option_str : |
|
178 |
args.insert(4,option_str) |
|
179 |
call_subprocess(args, |
|
180 |
cwd=os.path.abspath(tmp_dir), |
|
181 |
filter_stdout=filter_python_develop, |
|
182 |
show_stdout=True, |
|
183 |
extra_env=extra_env) |
|
184 |
||
185 |
mysqlconfig_output = [] |
|
186 |
||
187 |
call_subprocess(['mysql_config', '--libmysqld-libs'], |
|
188 |
cwd=os.path.abspath(tmp_dir), |
|
189 |
filter_stdout=lambda line: mysqlconfig_output.append(line), |
|
190 |
show_stdout=True) |
|
191 |
||
192 |
mysqlconfig_output = "".join(mysqlconfig_output) |
|
193 |
m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output) |
|
194 |
if m: |
|
195 |
repdylibpath = m.group(1) |
|
196 |
else: |
|
197 |
repdylibpath = '/usr/local/mysql/lib' |
|
198 |
||
199 |
dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib") |
|
200 |
def key_func(s): |
|
201 |
m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s) |
|
202 |
if m: |
|
203 |
return int(m.group(1)) |
|
204 |
else: |
|
205 |
return sys.maxint |
|
206 |
dyliblist.sort(key=key_func) |
|
207 |
||
208 |
if dyliblist: |
|
209 |
dylibpath = dyliblist[0] |
|
210 |
else: |
|
211 |
dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib' |
|
212 |
||
213 |
dylibname = os.path.basename(dylibpath) |
|
214 |
sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so') |
|
215 |
||
216 |
call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath], |
|
217 |
cwd=os.path.abspath(tmp_dir), |
|
218 |
filter_stdout=filter_python_develop, |
|
219 |
show_stdout=True) |
|
220 |
||
221 |
||
222 |
def gen_install_comp_lib(lib_name, lib_key, configure_options=[], configure_env={}): |
|
223 |
||
224 |
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): |
|
225 |
lib_src = os.path.join(src_dir,lib_name+".tar.gz") |
|
226 |
logger.notify("Copy %s to %s " % (res_env.URLS[lib_key][res_source_key],lib_src)) |
|
227 |
shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src) |
|
228 |
tf = tarfile.open(lib_src,'r:gz') |
|
229 |
lib_base_path = os.path.join(src_dir, lib_name) |
|
230 |
logger.notify("Extract %s to %s " % (lib_name,lib_base_path)) |
|
231 |
tf.extractall(lib_base_path) |
|
232 |
tf.close() |
|
233 |
||
234 |
lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0]) |
|
235 |
||
236 |
||
237 |
context_map = { |
|
238 |
'option_str' : option_str, |
|
239 |
'home_dir': os.path.abspath(home_dir), |
|
240 |
'lib_dir': os.path.abspath(lib_dir), |
|
241 |
'tmp_dir': os.path.abspath(tmp_dir), |
|
242 |
'src_dir': os.path.abspath(src_dir), |
|
243 |
} |
|
244 |
||
245 |
configure_options_trans = map(lambda s: s % context_map, configure_options) |
|
246 |
configure_env_trans = {k: s % context_map for k,s in configure_env.items()} |
|
247 |
||
248 |
logger.notify(lib_name + " configure in " + lib_src_path) |
|
249 |
call_subprocess(['./configure', '--prefix='+os.path.abspath(home_dir)] + configure_options_trans, |
|
250 |
cwd=os.path.abspath(lib_src_path), |
|
251 |
filter_stdout=filter_python_develop, |
|
252 |
show_stdout=True, |
|
253 |
extra_env=configure_env_trans |
|
254 |
) |
|
255 |
||
256 |
logger.notify(lib_name + " make in " + lib_src_path) |
|
257 |
call_subprocess(['make'], |
|
258 |
cwd=os.path.abspath(lib_src_path), |
|
259 |
filter_stdout=filter_python_develop, |
|
260 |
show_stdout=True) |
|
261 |
||
262 |
logger.notify(lib_name + "make install in " + lib_src_path) |
|
263 |
call_subprocess(['make', 'install'], |
|
264 |
cwd=os.path.abspath(lib_src_path), |
|
265 |
filter_stdout=filter_python_develop, |
|
266 |
show_stdout=True) |
|
267 |
return install_lib |
|
268 |
||
269 |
install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'], {}) |
|
270 |
install_zlib = gen_install_comp_lib("zlib", "ZLIB", [], {}) |
|
271 |
||
272 |
#osx_extra_env = {'ARCHFLAGS': '-Wno-error=unused-command-line-argument-hard-error-in-future', 'CFLAGS': '-Qunused-arguments', 'CPPFLAGS': '-Qunused-arguments'} |
|
273 |
osx_extra_env = {} |
|
274 |
||
275 |
def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None): |
|
276 |
||
277 |
all_urls = URLS.copy() |
|
278 |
if urls is not None: |
|
279 |
all_urls.update(urls) |
|
280 |
||
281 |
res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs) |
|
282 |
||
283 |
def filter_python_develop(line): |
|
284 |
if not line.strip(): |
|
285 |
return Logger.DEBUG |
|
286 |
for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
287 |
'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
288 |
'creating ', 'Copying ']: |
|
289 |
if line.startswith(prefix): |
|
290 |
return Logger.DEBUG |
|
291 |
return Logger.NOTIFY |
|
292 |
||
293 |
||
294 |
def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
|
295 |
logger.notify("Install %s from %s with %s" % (key,res_path,method)) |
|
296 |
if method == 'pip': |
|
297 |
if sys.platform == 'win32': |
|
298 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path] |
|
299 |
else: |
|
300 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_path] |
|
301 |
if option_str : |
|
302 |
args.append(option_str) |
|
303 |
if res_source_key == 'local': |
|
304 |
if extra_env is None: |
|
305 |
extra_env = {} |
|
306 |
args.insert(2, '-f') |
|
307 |
args.insert(3, res_env.get_src_base_path("")) |
|
308 |
args.insert(4, '--no-index') |
|
309 |
logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
310 |
call_subprocess(args, |
|
311 |
cwd=os.path.abspath(tmp_dir), |
|
312 |
filter_stdout=filter_python_develop, |
|
313 |
show_stdout=True, |
|
314 |
extra_env=extra_env) |
|
315 |
if method == 'pip-req': |
|
316 |
if sys.platform == 'win32': |
|
317 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-r', res_path] |
|
318 |
else: |
|
319 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-r', res_path] |
|
320 |
if option_str : |
|
321 |
args.append(option_str) |
|
322 |
if res_source_key == 'local': |
|
323 |
if extra_env is None: |
|
324 |
extra_env = {} |
|
325 |
args.insert(2, '-f') |
|
326 |
args.insert(3, res_env.get_src_base_path("")) |
|
327 |
args.insert(4, '--no-index') |
|
328 |
logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
329 |
call_subprocess(args, |
|
330 |
cwd=os.path.abspath(tmp_dir), |
|
331 |
filter_stdout=filter_python_develop, |
|
332 |
show_stdout=True, |
|
333 |
extra_env=extra_env) |
|
334 |
else: |
|
335 |
if sys.platform == 'win32': |
|
336 |
args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_path] |
|
337 |
else: |
|
338 |
args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_path] |
|
339 |
if option_str : |
|
340 |
args.insert(1,option_str) |
|
341 |
call_subprocess(args, |
|
342 |
cwd=os.path.abspath(tmp_dir), |
|
343 |
filter_stdout=filter_python_develop, |
|
344 |
show_stdout=True, |
|
345 |
extra_env=extra_env) |
|
346 |
||
347 |
||
348 |
def after_install(options, home_dir): |
|
349 |
||
350 |
global logger |
|
351 |
||
352 |
verbosity = options.verbose - options.quiet |
|
353 |
logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
|
354 |
||
355 |
||
356 |
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
|
357 |
base_dir = os.path.dirname(home_dir) |
|
358 |
src_dir = os.path.join(home_dir, 'src') |
|
359 |
tmp_dir = os.path.join(home_dir, 'tmp') |
|
360 |
ensure_dir(src_dir, logger) |
|
361 |
ensure_dir(tmp_dir, logger) |
|
362 |
system_str = platform.system() |
|
363 |
||
364 |
res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local') |
|
365 |
if res_source_key is None: |
|
366 |
res_source_key = 'local' |
|
367 |
||
368 |
ignore_packages = [] |
|
369 |
||
370 |
if system_str == 'Windows': |
|
371 |
default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {}} |
|
372 |
else: |
|
373 |
default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': {}} |
|
374 |
||
375 |
if options.ignore_packages : |
|
376 |
ignore_packages = options.ignore_packages.split(",") |
|
377 |
||
378 |
logger.indent += 2 |
|
379 |
try: |
|
380 |
for key in res_env.NORMAL_INSTALL: |
|
381 |
install_options = None |
|
382 |
if isinstance(key, dict): |
|
383 |
install_options = key.get('install', default_install_options) |
|
384 |
install_options['method'] = 'pip-req' |
|
385 |
res_path = res_env.get_run_res_base_path(key['requirement']) |
|
386 |
else: |
|
387 |
if key not in res_env.URLS: |
|
388 |
logger.notify("%s not found in def : passing" % (key,)) |
|
389 |
install_options = res_env.URLS[key].get('install', None) |
|
390 |
res_path = res_env.URLS[key][res_source_key] |
|
391 |
if install_options is None: |
|
392 |
install_options = default_install_options |
|
393 |
method = install_options.get('method', default_install_options['method']) |
|
394 |
option_str = install_options.get('option_str', default_install_options['option_str']) |
|
395 |
extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env']) |
|
396 |
if not extra_env: |
|
397 |
extra_env = {} |
|
398 |
||
399 |
if 'TMPDIR' not in extra_env: |
|
400 |
extra_env['TMPDIR'] = os.path.abspath(tmp_dir) |
|
401 |
if system_str == 'Darwin': |
|
402 |
for flag_key, flag_value in iter(osx_extra_env.items()): |
|
403 |
flags = extra_env.get(flag_key, '') |
|
404 |
if flag_value not in flags: |
|
405 |
#flags += " -Wno-error=unused-command-line-argument-hard-error-in-future" |
|
406 |
flags += " "+flag_value |
|
407 |
extra_env[flag_key] = flags.strip() |
|
408 |
||
409 |
#isinstance(lst, (list, tuple)) |
|
410 |
if key not in ignore_packages: |
|
411 |
logger.notify("install %s with method %s" % (key, repr(method))) |
|
412 |
if callable(method): |
|
413 |
method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
|
414 |
elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']: |
|
415 |
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) |
|
416 |
else: |
|
417 |
normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
|
418 |
||
419 |
logger.notify("Clear source dir") |
|
420 |
shutil.rmtree(src_dir) |
|
421 |
||
422 |
finally: |
|
423 |
logger.indent -= 2 |
|
424 |
script_dir = join(base_dir, bin_dir) |
|
425 |
logger.notify('Run "%s Package" to install new packages that provide builds' |
|
426 |
% join(script_dir, 'easy_install')) |
|
427 |
||
428 |
def adjust_options(options, args): |
|
429 |
if not options_to_add: |
|
430 |
return |
|
431 |
for opt,opt_val in options_to_add.items(): |
|
432 |
#if not hasattr(options,test_opt) or getattr(options, test_opt) is None: |
|
433 |
setattr(options, opt, opt_val) |
|
434 |
||
435 |
return adjust_options, extend_parser, after_install |