14 join = os.path.join |
14 join = os.path.join |
15 system_str = platform.system() |
15 system_str = platform.system() |
16 |
16 |
17 URLS = { |
17 URLS = { |
18 #'': {'setup': '', 'url':'', 'local':''}, |
18 #'': {'setup': '', 'url':'', 'local':''}, |
19 'PYCRYPTO': {'setup': 'pycrypto', 'url':'https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz', 'local':'pycrypto-2.6.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
19 'EDCSA': {'setup': 'edcsa', 'url':'https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.10.tar.gz', 'local':'ecdsa-0.10.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
20 'PARAMIKO' : {'setup': 'paramiko', 'url':'https://github.com/paramiko/paramiko/archive/v1.10.1.tar.gz', 'local':'paramiko-1.10.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
20 'WSGIREF': {'setup': 'wsgiref', 'url':'https://pypi.python.org/packages/source/w/wsgiref/wsgiref-0.1.2.zip', 'local':'wsgiref-0.1.2.zip', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
21 'FABRIC': {'setup': 'fabric', 'url':'https://github.com/fabric/fabric/tarball/1.6.0', 'local':'fabric-1.6.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
21 'PYCRYPTO': {'setup': 'pycrypto', 'url':'http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz', 'local':'pycrypto-2.6.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
22 'MERCURIAL': {'setup': 'mercurial', 'url':'http://mercurial.selenic.com/release/mercurial-2.6.tar.gz', 'local':'mercurial-2.6.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
22 'PARAMIKO' : {'setup': 'paramiko', 'url':'https://github.com/paramiko/paramiko/archive/v1.12.0.tar.gz', 'local':'paramiko-1.12.0.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
23 'FABRIC': {'setup': 'fabric', 'url':'https://pypi.python.org/packages/source/F/Fabric/Fabric-1.8.1.tar.gz', 'local':'Fabric-1.8.1.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
|
24 'MERCURIAL': {'setup': 'mercurial', 'url':'http://mercurial.selenic.com/release/mercurial-2.8.2.tar.gz', 'local':'mercurial-2.8.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}}, |
23 } |
25 } |
24 |
26 |
25 class ResourcesEnv(object): |
27 class ResourcesEnv(object): |
26 |
28 |
27 def __init__(self, src_base, urls, normal_installs): |
29 def __init__(self, src_base, run_base, urls, normal_installs): |
28 self.src_base = src_base |
30 self.src_base = src_base |
|
31 self.run_base = run_base |
29 self.URLS = {} |
32 self.URLS = {} |
30 self.__init_url(urls) |
33 self.__init_url(urls) |
31 self.NORMAL_INSTALL = normal_installs |
34 self.NORMAL_INSTALL = normal_installs |
32 |
35 |
33 def get_src_base_path(self, fpath): |
36 def get_src_base_path(self, fpath): |
34 return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
37 return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/") |
|
38 |
|
39 def get_run_res_base_path(self, fpath): |
|
40 return os.path.abspath(os.path.join(self.run_base, 'res', fpath)).replace("\\","/") |
35 |
41 |
36 def __add_package_def(self, key, dict): |
42 def __add_package_def(self, key, dict): |
37 self.URLS[key] = dict |
43 self.URLS[key] = dict |
38 |
44 |
39 def __init_url(self, urls): |
45 def __init_url(self, urls): |
40 for key, url_dict in urls.items(): |
46 for key, url_dict in urls.items(): |
41 url_dict_copy = url_dict.copy() |
47 url_dict_copy = url_dict.copy() |
|
48 if url_dict.get('install', {}).get('method','pip') == 'pip-req': |
|
49 get_base_path = self.get_run_res_base_path |
|
50 else: |
|
51 get_base_path = self.get_src_base_path |
42 if not url_dict['url'].startswith("http://"): |
52 if not url_dict['url'].startswith("http://"): |
43 url_dict_copy['url'] = self.get_src_base_path(url_dict['url']) |
53 url_dict_copy['url'] = get_base_path(url_dict['url']) |
44 url_dict_copy['local'] = self.get_src_base_path(url_dict['local']) |
54 url_dict_copy['local'] = get_base_path(url_dict['local']) |
45 |
55 |
46 self.__add_package_def(key, url_dict_copy ) |
56 self.__add_package_def(key, url_dict_copy ) |
47 |
57 |
48 def ensure_dir(dir, logger): |
58 def ensure_dir(dir, logger): |
49 logger.notify('Check directory %s' % dir) |
59 logger.notify('Check directory %s' % dir) |
50 if not os.path.exists(dir): |
60 if not os.path.exists(dir): |
167 |
177 |
168 install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared']) |
178 install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared']) |
169 install_zlib = gen_install_comp_lib("zlib", "ZLIB", []) |
179 install_zlib = gen_install_comp_lib("zlib", "ZLIB", []) |
170 |
180 |
171 |
181 |
172 def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None): |
182 def lib_generate_install_methods(path_locations, src_base, run_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None): |
173 |
183 |
174 all_urls = URLS.copy() |
184 all_urls = URLS.copy() |
175 if urls is not None: |
185 if urls is not None: |
176 all_urls.update(urls) |
186 all_urls.update(urls) |
177 |
187 |
178 res_env = ResourcesEnv(src_base, all_urls, normal_installs) |
188 res_env = ResourcesEnv(src_base, run_base, all_urls, normal_installs) |
179 |
189 |
180 def filter_python_develop(line): |
190 def filter_python_develop(line): |
181 if not line.strip(): |
191 if not line.strip(): |
182 return Logger.DEBUG |
192 return Logger.DEBUG |
183 for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
193 for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
186 if line.startswith(prefix): |
196 if line.startswith(prefix): |
187 return Logger.DEBUG |
197 return Logger.DEBUG |
188 return Logger.NOTIFY |
198 return Logger.NOTIFY |
189 |
199 |
190 |
200 |
191 def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
201 def normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess): |
192 logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method)) |
202 logger.notify("Install %s from %s with %s" % (key,res_path,method)) |
193 if method == 'pip': |
203 if method == 'pip': |
194 if sys.platform == 'win32': |
204 if sys.platform == 'win32': |
195 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_env.URLS[key][res_source_key]] |
205 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_path] |
196 else: |
206 else: |
197 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS[key][res_source_key]] |
207 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_path] |
198 if option_str : |
208 if option_str : |
199 args.insert(4,option_str) |
209 args.append(option_str) |
|
210 if res_source_key == 'local': |
|
211 if extra_env is None: |
|
212 extra_env = {} |
|
213 extra_env["PIP_DOWNLOAD_CACHE"] = res_env.get_src_base_path("") |
|
214 args.insert(2, '-f') |
|
215 args.insert(3, res_env.get_src_base_path("")) |
|
216 args.insert(4, '--no-index') |
|
217 logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
|
218 call_subprocess(args, |
|
219 cwd=os.path.abspath(tmp_dir), |
|
220 filter_stdout=filter_python_develop, |
|
221 show_stdout=True, |
|
222 extra_env=extra_env) |
|
223 if method == 'pip-req': |
|
224 if sys.platform == 'win32': |
|
225 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-r', res_path] |
|
226 else: |
|
227 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-r', res_path] |
|
228 if option_str : |
|
229 args.append(option_str) |
|
230 if res_source_key == 'local': |
|
231 if extra_env is None: |
|
232 extra_env = {} |
|
233 extra_env["PIP_DOWNLOAD_CACHE"] = res_env.get_src_base_path("") |
|
234 args.insert(2, '-f') |
|
235 args.insert(3, res_env.get_src_base_path("")) |
|
236 args.insert(4, '--no-index') |
|
237 logger.notify("Install %s from %s with %s args %s " % (key,res_path,method, repr(args))) |
200 call_subprocess(args, |
238 call_subprocess(args, |
201 cwd=os.path.abspath(tmp_dir), |
239 cwd=os.path.abspath(tmp_dir), |
202 filter_stdout=filter_python_develop, |
240 filter_stdout=filter_python_develop, |
203 show_stdout=True, |
241 show_stdout=True, |
204 extra_env=extra_env) |
242 extra_env=extra_env) |
205 else: |
243 else: |
206 if sys.platform == 'win32': |
244 if sys.platform == 'win32': |
207 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]] |
245 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_path] |
208 else: |
246 else: |
209 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]] |
247 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_path] |
210 if option_str : |
248 if option_str : |
211 args.insert(1,option_str) |
249 args.insert(1,option_str) |
212 call_subprocess(args, |
250 call_subprocess(args, |
213 cwd=os.path.abspath(tmp_dir), |
251 cwd=os.path.abspath(tmp_dir), |
214 filter_stdout=filter_python_develop, |
252 filter_stdout=filter_python_develop, |
247 ignore_packages = options.ignore_packages.split(",") |
286 ignore_packages = options.ignore_packages.split(",") |
248 |
287 |
249 logger.indent += 2 |
288 logger.indent += 2 |
250 try: |
289 try: |
251 for key in res_env.NORMAL_INSTALL: |
290 for key in res_env.NORMAL_INSTALL: |
252 if key not in res_env.URLS: |
291 install_options = None |
253 logger.notify("%s not found in def : passing" % (key,)) |
292 if isinstance(key, dict): |
254 install_options = res_env.URLS[key].get('install', None) |
293 install_options = key.get('install', default_install_options) |
|
294 install_options['method'] = 'pip-req' |
|
295 res_path = res_env.get_run_res_base_path(key['requirement']) |
|
296 else: |
|
297 if key not in res_env.URLS: |
|
298 logger.notify("%s not found in def : passing" % (key,)) |
|
299 install_options = res_env.URLS[key].get('install', None) |
|
300 res_path = res_env.URLS[key][res_source_key] |
255 if install_options is None: |
301 if install_options is None: |
256 install_options = default_install_options |
302 install_options = default_install_options |
257 method = install_options.get('method', default_install_options['method']) |
303 method = install_options.get('method', default_install_options['method']) |
258 option_str = install_options.get('option_str', default_install_options['option_str']) |
304 option_str = install_options.get('option_str', default_install_options['option_str']) |
259 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env']) |
305 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env']) |
268 if callable(method): |
314 if callable(method): |
269 method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
315 method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop) |
270 elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']: |
316 elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']: |
271 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) |
317 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) |
272 else: |
318 else: |
273 normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
319 normal_install(key, res_path, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess) |
274 |
320 |
275 logger.notify("Clear source dir") |
321 logger.notify("Clear source dir") |
276 shutil.rmtree(src_dir) |
322 shutil.rmtree(src_dir) |
277 |
323 |
278 finally: |
324 finally: |
281 logger.notify('Run "%s Package" to install new packages that provide builds' |
327 logger.notify('Run "%s Package" to install new packages that provide builds' |
282 % join(script_dir, 'easy_install')) |
328 % join(script_dir, 'easy_install')) |
283 |
329 |
284 def adjust_options(options, args): |
330 def adjust_options(options, args): |
285 if not options_to_add: |
331 if not options_to_add: |
286 pass |
332 return |
287 for opt in options_to_add: |
333 for opt in options_to_add: |
288 test_opt = opt.split('=',1)[0] |
334 test_opt = opt.split('=',1)[0] |
289 if not hasattr(options,test_opt) or getattr(options, test_opt) is None: |
335 #if not hasattr(options,test_opt) or getattr(options, test_opt) is None: |
290 setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True) |
336 setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True) |
291 |
337 |
292 return adjust_options, extend_parser, after_install |
338 return adjust_options, extend_parser, after_install |
|
339 |