script/virtualenv/res/lib/lib_create_env.py
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Tue, 14 May 2013 03:08:45 +0200
changeset 897 7ac9cf3be701
parent 888 6fc6637d8403
child 957 e4d0094f097b
permissions -rw-r--r--
update lxml
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     1
import sys
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     2
import os
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     3
import os.path
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     4
import shutil
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     5
import tarfile
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     6
import zipfile
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     7
import urllib
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     8
import platform
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
     9
import patch
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    10
import struct
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    11
import glob
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    12
import re
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    13
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    14
join = os.path.join
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    15
system_str = platform.system()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    16
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    17
URLS = {
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    18
    #'': {'setup': '', 'url':'', 'local':''},
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    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}},
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    20
    'ANYJSON': {'setup': 'anyjson', 'url':'http://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz', 'local':"anyjson-0.3.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    21
    'OAUTH2': { 'setup': 'python-oauth2', 'url':"https://github.com/simplegeo/python-oauth2/tarball/hudson-python-oauth2-211", 'local':"python-oauth2-1.5-211.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    22
    'HTTPLIB2': { 'setup': 'httplib2', 'url':'http://pypi.python.org/packages/source/h/httplib2/httplib2-0.8.tar.gz', 'local':"httplib2-0.8.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    23
    'LOCKFILE': {'setup': 'lockfile', 'url':'http://code.google.com/p/pylockfile/downloads/detail?name=lockfile-0.9.1.tar.gz', 'local':"lockfile-0.9.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    24
    'DAEMON': {'setup': 'python-daemon', 'url':'http://pypi.python.org/packages/source/p/python-daemon/python-daemon-1.5.5.tar.gz', 'local':"python-daemon-1.5.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    25
    'DATEUTIL': {'setup': 'python-dateutil', 'url':'http://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}},
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    26
    'PYTZ': {'setup': 'pytz', 'url':'http://pypi.python.org/packages/source/p/pytz/pytz-2013b.tar.bz2', 'local':"pytz-2013b.tar.bz2", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    27
    'SIMPLEJSON': {'setup': 'simplejson', 'url':'http://pypi.python.org/packages/source/s/simplejson/simplejson-3.1.3.tar.gz', 'local':"simplejson-3.1.3.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
888
6fc6637d8403 update listener. add support for twitter regulation messages. update virtualenv
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 886
diff changeset
    28
    'SQLALCHEMY': {'setup': 'sqlalchemy', 'url':'http://www.python.org/pypi/SQLAlchemy/0.8.1', 'local':"SQLAlchemy-0.8.1.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    29
    'TWITTER': {'setup': 'twitter', 'url':'http://pypi.python.org/packages/source/t/twitter/twitter-1.9.2.tar.gz', 'local':"twitter-1.9.2.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    30
    'TWITTER-TEXT': {'setup': 'twitter-text', 'url':'https://github.com/dryan/twitter-text-py/archive/master.tar.gz', 'local':"twitter-text-1.0.4.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    31
    'REQUESTS': {'setup': 'requests', 'url':'https://github.com/kennethreitz/requests/archive/v1.2.0.tar.gz', 'local':'requests-v1.2.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    32
    'OAUTHLIB': {'setup': 'oauthlib', 'url':'https://github.com/idan/oauthlib/archive/0.4.0.tar.gz', 'local':'oauthlib-0.4.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    33
    'REQUESTS-OAUTHLIB': {'setup': 'requests-oauthlib', 'url':'https://github.com/requests/requests-oauthlib/archive/master.tar.gz', 'local':'requests-oauthlib-0.3.0.tar.gz', 'install' : {'method':'pip', 'option_str': None, 'dict_extra_env': None}},
888
6fc6637d8403 update listener. add support for twitter regulation messages. update virtualenv
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 886
diff changeset
    34
    'BLESSINGS': {'setup': 'blessings', 'url':'https://github.com/erikrose/blessings/archive/1.5.tar.gz', 'local':'blessings-1.5.tar.gz', 'install' :  {'method':'pip', 'option_str': None, 'dict_extra_env': None}}
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    35
}
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    36
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    37
if system_str == 'Windows':
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    38
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    39
    URLS.update({
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    40
        'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.5.win32-py2.7-pg9.2.4-release.zip', 'local':"psycopg2-2.5.win32-py2.7-pg9.2.4-release.zip", 'install': {'method': 'install_psycopg2', 'option_str': None, 'dict_extra_env': None}},
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    41
        '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}},
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    42
    })
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    43
else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    44
    if system_str == "Darwin":        
897
7ac9cf3be701 update lxml
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 888
diff changeset
    45
        lxml_options = {'STATIC_DEPS': 'true', 'LIBXML2_VERSION': '2.9.1', 'LIBXSLT_VERSION': '1.1.28', 'LIBICONV_VERSION': '1.14'}
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    46
        lxml_method = 'pip'
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    47
    else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    48
        lxml_options = None
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    49
        lxml_method = 'pip'
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    50
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    51
    URLS.update({
884
07f1c6854df9 update virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 883
diff changeset
    52
        'PSYCOPG2': {'setup': 'psycopg2','url': 'http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.tar.gz', 'local':"psycopg2-2.5.tar.gz", 'install': {'method': 'pip', 'option_str': None, 'dict_extra_env': None}},
897
7ac9cf3be701 update lxml
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents: 888
diff changeset
    53
        'LXML': {'setup': 'lxml', 'url':"lxml-3.2.1.tar.bz2", 'local':"lxml-3.2.1.tar.bz2", 'install': {'method': lxml_method, 'option_str': None, 'dict_extra_env': lxml_options}},
735
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    54
    })
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    55
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    56
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    57
class ResourcesEnv(object):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    58
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    59
    def __init__(self, src_base, urls, normal_installs):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    60
        self.src_base = src_base
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    61
        self.URLS = {}
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    62
        self.__init_url(urls)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    63
        self.NORMAL_INSTALL = normal_installs
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    64
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    65
    def get_src_base_path(self, fpath):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    66
        return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    67
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    68
    def __add_package_def(self, key, dict):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    69
        self.URLS[key] = dict
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    70
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    71
    def __init_url(self, urls):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    72
        for key, url_dict in urls.items():
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    73
            url_dict_copy = url_dict.copy()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    74
            if not url_dict['url'].startswith("http://"):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    75
                url_dict_copy['url'] = self.get_src_base_path(url_dict['url'])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    76
            url_dict_copy['local'] = self.get_src_base_path(url_dict['local'])            
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    77
            
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    78
            self.__add_package_def(key, url_dict_copy )
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    79
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    80
def ensure_dir(dir, logger):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    81
    if not os.path.exists(dir):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    82
        logger.notify('Creating directory %s' % dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    83
        os.makedirs(dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    84
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    85
def extend_parser(parser):    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    86
    parser.add_option(
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    87
        '--index-url',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    88
        metavar='INDEX_URL',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    89
        dest='index_url',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    90
        default='http://pypi.python.org/simple/',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    91
        help='base URL of Python Package Index')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    92
    parser.add_option(
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    93
        '--type-install',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    94
        metavar='type_install',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    95
        dest='type_install',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    96
        help='type install : local, url, setup - default : local')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    97
    parser.add_option(
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    98
        '--ignore-packages',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
    99
        metavar='ignore_packages',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   100
        dest='ignore_packages',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   101
        default=None,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   102
        help='list of comma separated keys for package to ignore')    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   103
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   104
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):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   105
    psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   106
    shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   107
    #extract psycopg2
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   108
    zf = zipfile.ZipFile(psycopg2_src)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   109
    psycopg2_base_path = os.path.join(src_dir,"psycopg2")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   110
    zf.extractall(psycopg2_base_path)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   111
    zf.close()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   112
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   113
    psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   114
    shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib/site-packages', 'psycopg2')))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   115
    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')))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   116
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   117
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   118
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):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   119
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   120
    args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS['MYSQL'][res_source_key]]                
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   121
    if option_str :
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   122
        args.insert(4,option_str)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   123
    call_subprocess(args,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   124
            cwd=os.path.abspath(tmp_dir),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   125
            filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   126
            show_stdout=True,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   127
            extra_env=extra_env)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   128
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   129
    mysqlconfig_output = []
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   130
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   131
    call_subprocess(['mysql_config', '--libmysqld-libs'],
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   132
        cwd=os.path.abspath(tmp_dir),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   133
        filter_stdout=lambda line: mysqlconfig_output.append(line),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   134
        show_stdout=True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   135
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   136
    mysqlconfig_output = "".join(mysqlconfig_output)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   137
    m = re.search("\-L[\'\"]?([\w\/]+)[\'\"]?", mysqlconfig_output)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   138
    if m:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   139
        repdylibpath = m.group(1)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   140
    else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   141
        repdylibpath = '/usr/local/mysql/lib'
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   142
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   143
    dyliblist = glob.glob(repdylibpath+"/libmysqlclient.*.dylib")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   144
    def key_func(s):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   145
        m = re.match(repdylibpath+"/libmysqlclient\.([\d]+)\.dylib", s)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   146
        if m:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   147
            return int(m.group(1))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   148
        else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   149
            return sys.maxint
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   150
    dyliblist.sort(key=key_func)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   151
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   152
    if dyliblist:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   153
        dylibpath = dyliblist[0]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   154
    else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   155
        dylibpath = '/usr/local/mysql/lib/libmysqlclient.18.dylib'
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   156
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   157
    dylibname = os.path.basename(dylibpath)    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   158
    sopath = os.path.join(os.path.abspath(lib_dir), 'site-packages', '_mysql.so')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   159
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   160
    call_subprocess(['install_name_tool', '-change', dylibname, dylibpath, sopath],
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   161
        cwd=os.path.abspath(tmp_dir),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   162
        filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   163
        show_stdout=True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   164
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   165
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   166
def gen_install_comp_lib(lib_name, lib_key, configure_options=[]):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   167
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   168
    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):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   169
        lib_src = os.path.join(src_dir,lib_name+".tar.gz")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   170
        shutil.copy(res_env.URLS[lib_key][res_source_key], lib_src)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   171
        tf = tarfile.open(lib_src,'r:gz')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   172
        lib_base_path = os.path.join(src_dir, lib_name) 
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   173
        logger.notify("Extract %s to %s " % (lib_name,lib_base_path))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   174
        tf.extractall(lib_base_path)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   175
        tf.close()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   176
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   177
        lib_src_path = os.path.join(lib_base_path, os.listdir(lib_base_path)[0])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   178
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   179
        logger.notify(libname + " configure")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   180
        call_subprocess(['configure', '--prefix='+os.path.abspath(home_dir)] + configure_options,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   181
                        cwd=os.path.abspath(lib_src_path),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   182
                        filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   183
                        show_stdout=True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   184
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   185
        logger.notify(libname + " make")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   186
        call_subprocess(['make'],
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   187
                        cwd=os.path.abspath(lib_src_path),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   188
                        filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   189
                        show_stdout=True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   190
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   191
        logger.notify(libname + "make install")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   192
        call_subprocess(['make', 'install'],
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   193
                        cwd=os.path.abspath(lib_src_path),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   194
                        filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   195
                        show_stdout=True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   196
        return install_lib
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   197
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   198
install_libjpeg = gen_install_comp_lib("libjpeg", "LIBJPEG", ['--enable-shared'])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   199
install_zlib = gen_install_comp_lib("zlib", "ZLIB", [])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   200
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   201
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   202
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   203
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   204
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   205
def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, options_to_add=None, urls= None):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   206
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   207
    all_urls = URLS.copy()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   208
    if urls is not None:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   209
        all_urls.update(urls)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   210
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   211
    res_env = ResourcesEnv(src_base, all_urls, normal_installs)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   212
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   213
    def filter_python_develop(line):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   214
        if not line.strip():
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   215
            return Logger.DEBUG
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   216
        for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   217
                       'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   218
                       'creating ', 'Copying ']:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   219
            if line.startswith(prefix):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   220
                return Logger.DEBUG
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   221
        return Logger.NOTIFY
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   222
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   223
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   224
    def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   225
        logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   226
        if method == 'pip':
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   227
            if sys.platform == 'win32':
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   228
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', res_env.URLS[key][res_source_key]]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   229
            else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   230
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', res_env.URLS[key][res_source_key]]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   231
            if option_str :
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   232
                args.insert(4,option_str)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   233
            call_subprocess(args,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   234
                    cwd=os.path.abspath(tmp_dir),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   235
                    filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   236
                    show_stdout=True,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   237
                    extra_env=extra_env)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   238
        else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   239
            if sys.platform == 'win32':
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   240
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   241
            else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   242
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   243
            if option_str :
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   244
                args.insert(1,option_str)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   245
            call_subprocess(args,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   246
                    cwd=os.path.abspath(tmp_dir),
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   247
                    filter_stdout=filter_python_develop,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   248
                    show_stdout=True,
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   249
                    extra_env=extra_env)            
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   250
 
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   251
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   252
    def after_install(options, home_dir):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   253
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   254
        global logger
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   255
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   256
        verbosity = options.verbose - options.quiet
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   257
        logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   258
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   259
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   260
        home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   261
        base_dir = os.path.dirname(home_dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   262
        src_dir = os.path.join(home_dir, 'src')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   263
        tmp_dir = os.path.join(home_dir, 'tmp')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   264
        ensure_dir(src_dir, logger)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   265
        ensure_dir(tmp_dir, logger)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   266
        system_str = platform.system()
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   267
                
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   268
        res_source_key = getattr(options, 'type_install') if hasattr(options, 'type_install') else 'local' #.get('type_install', 'local')
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   269
        if res_source_key is None:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   270
            res_source_key = local
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   271
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   272
        ignore_packages = []
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   273
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   274
        if system_str == 'Windows':
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   275
            default_install_options = {'method': 'easy_install', 'option_str': None, 'dict_extra_env': None}
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   276
        else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   277
            default_install_options = {'method': 'pip', 'option_str': None, 'dict_extra_env': None}
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   278
            
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   279
        if options.ignore_packages :
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   280
            ignore_packages = options.ignore_packages.split(",")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   281
        
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   282
        logger.indent += 2
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   283
        try:    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   284
            for key in res_env.NORMAL_INSTALL:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   285
                if key not in res_env.URLS:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   286
                    logger.notify("%s not found in def : passing" % (key,))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   287
                install_options = res_env.URLS[key].get('install', None)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   288
                if install_options is None:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   289
                    install_options = default_install_options
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   290
                method = install_options.get('method', default_install_options['method'])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   291
                option_str = install_options.get('option_str', default_install_options['option_str'])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   292
                extra_env = install_options.get('dict_extra_env', default_install_options['dict_extra_env'])
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   293
                #isinstance(lst, (list, tuple))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   294
                if key not in ignore_packages:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   295
                    if callable(method):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   296
                        method(option_str, extra_env, res_source_key, home_dir, lib_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   297
                    elif method in globals() and callable(globals()[method]) and method not in ['pip', 'easy_install']:  
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   298
                        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)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   299
                    else:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   300
                        normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   301
                            
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   302
            logger.notify("Clear source dir")
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   303
            shutil.rmtree(src_dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   304
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   305
        finally:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   306
            logger.indent -= 2
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   307
        script_dir = join(base_dir, bin_dir)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   308
        logger.notify('Run "%s Package" to install new packages that provide builds'
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   309
                      % join(script_dir, 'easy_install'))
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   310
    
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   311
    def adjust_options(options, args):
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   312
        if not options_to_add:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   313
            pass
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   314
        for opt in options_to_add:
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   315
            test_opt = opt.split('=',1)[0]
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   316
            if not hasattr(options,test_opt) or getattr(options, test_opt) is None:                
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   317
                setattr(options, test_opt,opt.split('=',1)[1] if "=" in opt else True)
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   318
655bf8a12003 add virtualenv creation
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
diff changeset
   319
    return adjust_options, extend_parser, after_install