virtualenv/res/lib/lib_create_env.py
changeset 671 fc56b4c9e4f3
parent 668 b52724db32ab
child 673 85994294d928
equal deleted inserted replaced
670:5e2f25f59429 671:fc56b4c9e4f3
     8 import platform
     8 import platform
     9 import patch
     9 import patch
    10 
    10 
    11 join = os.path.join
    11 join = os.path.join
    12 system_str = platform.system()
    12 system_str = platform.system()
    13 
       
    14 
    13 
    15 URLS = {
    14 URLS = {
    16     #'': {'setup': '', 'url':'', 'local':''},
    15     #'': {'setup': '', 'url':'', 'local':''},
    17     'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.4/tarball/', 'local':"Django-1.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    16     'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.4/tarball/', 'local':"Django-1.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    18     'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/0.8', 'local':"django-extensions-0.8.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    17     'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/0.8', 'local':"django-extensions-0.8.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    27     'DJANGO_OPENID_CONSUMER': {'setup':'django_openid_consumer', 'url':'http://pypi.python.org/packages/source/d/django-openid-consumer/django-openid-consumer-0.1.1.tar.gz', 'local':"django-openid-consumer-0.1.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    26     'DJANGO_OPENID_CONSUMER': {'setup':'django_openid_consumer', 'url':'http://pypi.python.org/packages/source/d/django-openid-consumer/django-openid-consumer-0.1.1.tar.gz', 'local':"django-openid-consumer-0.1.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    28     'SOCIAL_AUTH': {'setup':'social_auth', 'url':'https://github.com/omab/django-social-auth/tarball/v0.3.10', 'local':"omab-django-social-auth-v0.3.10-modified.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    27     'SOCIAL_AUTH': {'setup':'social_auth', 'url':'https://github.com/omab/django-social-auth/tarball/v0.3.10', 'local':"omab-django-social-auth-v0.3.10-modified.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    29     'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.7.5.tar.gz', 'local':"south-0.7.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    28     'SOUTH': { 'setup': 'South', 'url':'http://www.aeracode.org/releases/south/south-0.7.5.tar.gz', 'local':"south-0.7.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    30     'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'http://pypi.python.org/packages/source/d/django-guardian/django-guardian-1.0.3.tar.gz', 'local':"django-guardian-1.0.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    29     'DJANGO_GUARDIAN' : { 'setup': 'django-guardian', 'url':'http://pypi.python.org/packages/source/d/django-guardian/django-guardian-1.0.3.tar.gz', 'local':"django-guardian-1.0.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    31     'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'http://pypi.python.org/packages/source/s/sorl-thumbnail/sorl-thumbnail-11.12.tar.gz', 'local':"sorl-thumbnail-v10.12.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    30     'SORL_THUMBNAIL' : { 'setup': 'sorl-thumbnail', 'url':'http://pypi.python.org/packages/source/s/sorl-thumbnail/sorl-thumbnail-11.12.tar.gz', 'local':"sorl-thumbnail-v10.12.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    32     'LIBJPEG': {'setup': None, 'url':'jpegsrc.v8d.tar.gz', 'local':'jpegsrc.v8d.tar.gz', 'install': {'method': install_libjpeg, 'option_str': None, 'dict_extra_env': None}},
    31     'LIBJPEG': {'setup': None, 'url':'jpegsrc.v8d.tar.gz', 'local':'jpegsrc.v8d.tar.gz', 'install': {'method': 'install_libjpeg', 'option_str': None, 'dict_extra_env': None}},
    33     'ZLIB': {'setup': None, 'url':'zlib-1.2.7.tar.gz', 'local':'zlib-1.2.7.tar.gz', 'install': {'method': install_zlib, 'option_str': None, 'dict_extra_env': None}},
    32     'ZLIB': {'setup': None, 'url':'zlib-1.2.7.tar.gz', 'local':'zlib-1.2.7.tar.gz', 'install': {'method': 'install_zlib', 'option_str': None, 'dict_extra_env': None}},
    34     '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}},
    33     '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}},
    35     'SSH': {'setup': 'ssh', 'url':'http://pypi.python.org/packages/source/s/ssh/ssh-1.7.14.tar.gz#md5=4cdd0549ef4699bd67b96264d3b21427', 'local':'ssh-1.7.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    34     'SSH': {'setup': 'ssh', 'url':'http://pypi.python.org/packages/source/s/ssh/ssh-1.7.14.tar.gz#md5=4cdd0549ef4699bd67b96264d3b21427', 'local':'ssh-1.7.14.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    36     'FABRIC': {'setup': 'fabric', 'url':'https://github.com/fabric/fabric/tarball/1.4.2', 'local':'fabric-1.4.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    35     'FABRIC': {'setup': 'fabric', 'url':'https://github.com/fabric/fabric/tarball/1.4.2', 'local':'fabric-1.4.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    37     'MERCURIAL': {'setup': 'mercurial', 'url':'http://mercurial.selenic.com/release/mercurial-2.2.2.tar.gz', 'local':'mercurial-2.2.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    36     'MERCURIAL': {'setup': 'mercurial', 'url':'http://mercurial.selenic.com/release/mercurial-2.2.2.tar.gz', 'local':'mercurial-2.2.2.tar.gz', 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    38 }
    37 }
    39 
    38 
    40 if system_str == 'Windows':
    39 if system_str == 'Windows':
    41     URLS.update({
    40     URLS.update({
    42         '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", 'install': {'method': install_psycopg2, 'option_str': None, 'dict_extra_env': None}},
    41         '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", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
    43         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    42         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    44         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    43         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    45         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    44         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    46         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}
    45         '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", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}}
    47     })
    46     })
    48 else:
    47 else:
    49     URLS.update({
    48     URLS.update({
    50         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz', 'local':"psycopg2-2.4.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    49         'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz', 'local':"psycopg2-2.4.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
    51         'PYLUCENE': {'setup': 'pylucene', 'url': 'http://mirrors.ircam.fr/pub/apache/lucene/pylucene/pylucene-3.6.0-2-src.tar.gz', 'local':"pylucene-3.6.0-2-src.tar.gz", 'install': {'method': install_pylucene, 'option_str': None, 'dict_extra_env': None}},
    50         'PYLUCENE': {'setup': 'pylucene', 'url': 'http://mirrors.ircam.fr/pub/apache/lucene/pylucene/pylucene-3.6.0-2-src.tar.gz', 'local':"pylucene-3.6.0-2-src.tar.gz", 'install': {'method': 'install_pylucene', 'option_str': None, 'dict_extra_env': None}},
    52         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    51         'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}},
    53         'LXML': {'setup': 'lxml', 'url':"lxml-2.3.4.tar.bz2", 'local':"lxml-2.3.4.tar.bz2", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.7.8', 'LIBXSLT_VERSION': '1.1.26', 'LIBICONV_VERSION': '1.13.1'}}},
    52         'LXML': {'setup': 'lxml', 'url':"lxml-2.3.4.tar.bz2", 'local':"lxml-2.3.4.tar.bz2", 'install': {'method': 'easy_install', 'option_str': None, 'dict_extra_env': {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.7.8', 'LIBXSLT_VERSION': '1.1.26', 'LIBICONV_VERSION': '1.13.1'}}},
    54     })
    53     })
    55     
    54     
    56 
    55 
    89         help='base URL of Python Package Index')
    88         help='base URL of Python Package Index')
    90     parser.add_option(
    89     parser.add_option(
    91         '--type-install',
    90         '--type-install',
    92         metavar='type_install',
    91         metavar='type_install',
    93         dest='type_install',
    92         dest='type_install',
    94         default='local',
    93         help='type install : local, url, setup - default : local')
    95         help='type install : local, url, setup')
       
    96     parser.add_option(
    94     parser.add_option(
    97         '--ignore-packages',
    95         '--ignore-packages',
    98         metavar='ignore_packages',
    96         metavar='ignore_packages',
    99         dest='ignore_packages',
    97         dest='ignore_packages',
   100         default=None,
    98         default=None,
   101         help='list of comma separated keys for package to ignore')
    99         help='list of comma separated keys for package to ignore')
   102 
       
   103 def adjust_options(options, args):
       
   104     pass
       
   105 
       
   106 
   100 
   107 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):
   101 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):
   108     
   102     
   109     logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key])
   103     logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key])
   110     pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   104     pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   247 
   241 
   248 
   242 
   249     
   243     
   250     
   244     
   251 
   245 
   252 def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, urls=None):
   246 def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
   253     
   247     
   254     all_urls = URLS.copy()
   248     all_urls = URLS.copy()
   255     if urls is not None:
   249     if urls is not None:
   256         all_urls.update(urls)
   250         all_urls.update(urls)
   257         
   251         
   309         src_dir = os.path.join(home_dir, 'src')
   303         src_dir = os.path.join(home_dir, 'src')
   310         tmp_dir = os.path.join(home_dir, 'tmp')
   304         tmp_dir = os.path.join(home_dir, 'tmp')
   311         ensure_dir(src_dir, logger)
   305         ensure_dir(src_dir, logger)
   312         ensure_dir(tmp_dir, logger)
   306         ensure_dir(tmp_dir, logger)
   313         system_str = platform.system()
   307         system_str = platform.system()
   314         
   308                 
   315         res_source_key = options.type_install
   309         res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
       
   310         if res_source_key is None:
       
   311             res_source_key = local
   316         
   312         
   317         ignore_packages = []
   313         ignore_packages = []
   318         
   314         
   319         if system_str == 'Windows':
   315         if system_str == 'Windows':
   320             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}
   316             default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}
   337                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   333                 extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
   338                 #isinstance(lst, (list, tuple))
   334                 #isinstance(lst, (list, tuple))
   339                 if key not in ignore_packages:
   335                 if key not in ignore_packages:
   340                     if callable(method):
   336                     if callable(method):
   341                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
   337                         method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
       
   338                     elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
       
   339                         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)
   342                     else:
   340                     else:
   343                         normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   341                         normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
   344                             
   342                             
   345             logger.notify("Clear source dir")
   343             logger.notify("Clear source dir")
   346             shutil.rmtree(src_dir)
   344             shutil.rmtree(src_dir)
   349             logger.indent -= 2
   347             logger.indent -= 2
   350         script_dir = join(base_dir, bin_dir)
   348         script_dir = join(base_dir, bin_dir)
   351         logger.notify('Run "%s Package" to install new packages that provide builds'
   349         logger.notify('Run "%s Package" to install new packages that provide builds'
   352                       % join(script_dir, 'easy_install'))
   350                       % join(script_dir, 'easy_install'))
   353     
   351     
       
   352     def adjust_options(options, args):
       
   353         if not options_to_add:
       
   354             pass
       
   355         for opt in options_to_add:
       
   356             test_opt = opt.split('=',1)[0]
       
   357             if not hasattr(options,test_opt) or getattr(options, test_opt) is None:                
       
   358                 setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
   354 
   359 
   355     return adjust_options, extend_parser, after_install
   360     return adjust_options, extend_parser, after_install
   356 
       
   357 def lib_add_options(options_to_add):
       
   358     import sys
       
   359     def check_option(str):
       
   360         for opt in sys.argv:
       
   361             if opt.startswith(str):
       
   362                 return true
       
   363         return false
       
   364     for opt in options_to_add:
       
   365         test_opt = opt.split(['='])[0]
       
   366         if not check_option(test_opt):
       
   367             sys.argv.insert(len(sys.argv)-1, opt)