virtualenv/res/lib/lib_create_env.py
author ymh <ymh.work@gmail.com>
Fri, 08 Apr 2011 17:18:44 +0200
changeset 68 b40657713336
child 70 8e3281bcebc9
permissions -rw-r--r--
use platform and clean install files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import sys
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import os
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import os.path
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import shutil
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import tarfile
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import zipfile
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import urllib
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import platform
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import patch
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
join = os.path.join
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
system_str = platform.system()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
URLS = {
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    #'': {'setup': '', 'url':'', 'local':''},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    'DISTRIBUTE': {'setup': 'distribute', 'url':'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz', 'local':"distribute-0.6.14.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    'DJANGO': {'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.2.4/tarball/', 'local':"Django-1.2.4.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    'JOGGING': {'setup': 'jogging', 'url': 'http://github.com/zain/jogging/tarball/v0.2.2', 'local':"jogging-0.2.2.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    'DJANGO-EXTENSIONS': { 'setup': 'django-extensions', 'url':'https://github.com/django-extensions/django-extensions/tarball/0.6', 'local':"django-extensions-0.6.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    'DJANGO-REGISTRATION': { 'setup': 'django-registration', 'url':'http://bitbucket.org/ubernostrum/django-registration/get/tip.tar.gz', 'local':"django-registration.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    'DJANGO-TAGGING': { 'setup': 'django-tagging', 'url':'http://django-tagging.googlecode.com/files/django-tagging-0.3.1.tar.gz', 'local':"django-tagging-0.3.1.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    'DJANGO-PISTON': { 'setup': 'django-piston', 'url':"django-piston-0.2.2-modified.tar.gz", 'local':"django-piston-0.2.2-modified.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    'OAUTH2': { 'setup': 'python-oauth2', 'url':"python-oauth2-1.2.1-modified.tar.gz", 'local':"python-oauth2-1.2.1-modified.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    'HTTPLIB2': { 'setup': 'python-oauth2', 'url':'http://httplib2.googlecode.com/files/httplib2-0.6.0.tar.gz', 'local':"httplib2-0.6.0.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    'DJANGO-OAUTH-PLUS': { 'setup': 'django-oauth-plus', 'url':'http://bitbucket.org/david/django-oauth-plus/get/f314f018e473.gz', 'local':"django-oauth-plus.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    'MYSQL': { 'setup': 'mysql-python', 'url': 'http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download', 'local':"MySQL-python-1.2.3.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    'SETUPTOOLS-HG': { 'setup':'mercurial_hg', 'url':'http://pypi.python.org/packages/source/s/setuptools_hg/setuptools_hg-0.2.tar.gz', 'local':"setuptools_hg-0.2.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    'MERCURIAL': {'setup':'mercurial', 'url':'http://pypi.python.org/packages/source/d/mercurial/mercurial-1.7.5.tar.gz', 'local':"mercurial-1.7.5.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
#added for blinkster
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    'MODELTRANSLATION': {'setup':'modeltranslation', 'url':'http://code.google.com/p/django-modeltranslation/downloads/detail?name=django-modeltranslation-0.2.tar.gz', 'local':'django-modeltranslation-0.2.tar.gz'},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    'PHOTOLOGUE': {'setup': 'photologue', 'url':'http://django-photologue.googlecode.com/files/django-photologue-2.2.zip', 'local':'django-photologue-2.2.zip'},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
}
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
if system_str == 'Windows':
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    URLS.update({
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        'PSYCOPG2': {'setup': 'psycopg2','url': 'psycopg2-2.0.10.win32-py2.6-pg8.3.7-release.zip', 'local':"psycopg2-2.0.10.win32-py2.6-pg8.3.7-release.zip"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        'JCC': {'setup': 'http://pylucene-win32-binary.googlecode.com/files/JCC-2.6-py2.6-win32.egg', 'local':"JCC-2.6-py2.6-win32.egg"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        'PYLUCENE': {'setup': 'http://pylucene-win32-binary.googlecode.com/files/lucene-3.0.2-py2.6-win32.egg', 'local':"lucene-3.0.2-py2.6-win32.egg"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        '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"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
        'LXML': {'setup': 'lxml', 'url': 'http://pypi.python.org/packages/2.6/l/lxml/lxml-2.2.8-py2.6-win32.egg', 'local':"lxml-2.2.8-py2.6-win32.egg"}
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    })
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    URLS.update({
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        'PSYCOPG2': {'setup': 'psycopg2','url': 'http://initd.org/psycopg/tarballs/PSYCOPG-2-3/psycopg2-2.3.2.tar.gz', 'local':"psycopg2-2.3.2.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        'PYLUCENE': {'setup': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.3-1-src.tar.gz', 'url': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.3-1-src.tar.gz', 'local':"pylucene-3.0.3-1-src.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        'PIL': {'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local':"Imaging-1.1.7.tar.gz"},
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        'LXML': {'setup': 'lxml', 'url':"lxml_2.2.8.tar.gz", 'local':"lxml-2.2.8.tar.gz"}
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    })
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
class ResourcesEnv(object):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    def __init__(self, src_base, urls, normal_installs):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        self.src_base = src_base
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        self.URLS = {}
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        self.__init_url(urls)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        self.NORMAL_INSTALL = normal_installs
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    def get_src_base_path(self, fpath):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        return os.path.abspath(os.path.join(self.src_base, fpath)).replace("\\","/")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    def __add_package_def(self, key, setup, url, local):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        self.URLS[key] = {'setup':setup, 'url':url, 'local':self.get_src_base_path(local)}
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    def __init_url(self, urls):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
        for key, url_dict in urls.items():
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
            url = url_dict['url']
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
            if not url.startswith("http://"):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
                url = self.get_src_base_path(url)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
            self.__add_package_def(key, url_dict["setup"], url, url_dict["local"])
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
def ensure_dir(dir, logger):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    if not os.path.exists(dir):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        logger.notify('Creating directory %s' % dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        os.makedirs(dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
def extend_parser(parser):    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    parser.add_option(
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        '--index-url',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
        metavar='INDEX_URL',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        dest='index_url',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        default='http://pypi.python.org/simple/',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        help='base URL of Python Package Index')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    parser.add_option(
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        '--type-install',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
        metavar='type_install',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
        dest='type_install',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
        default='local',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        help='type install : local, url, setup')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
    parser.add_option(
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
        '--ignore-packages',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
        metavar='ignore_packages',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
        dest='ignore_packages',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
        default=None,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        help='list of comma separated keys for package to ignore')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
def adjust_options(options, args):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
    pass
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
def install_pylucene(option_str, extra_env, res_source_key, home_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
    logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key])
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
    if res_source_key == 'local':
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
        shutil.copy(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        urllib.urlretrieve(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    tf = tarfile.open(pylucene_src,'r:gz')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
    pylucene_base_path = os.path.join(src_dir,"pylucene") 
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
    logger.notify("Extract Pylucene to %s " % pylucene_base_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    tf.extractall(pylucene_base_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
    tf.close()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
    pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0])
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
    jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc"))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
    #install jcc
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    #patch for linux
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
    if system_str == 'Linux' :
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
        olddir = os.getcwd()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
        patch_dest_path = os.path.join(lib_dir,'site-packages','setuptools-0.6c11-py'+'%s.%s' % (sys.version_info[0], sys.version_info[1])+'.egg')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
        if os.path.isfile(patch_dest_path):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
            # must unzip egg
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
            # rename file and etract all
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
            shutil.move(patch_dest_path, patch_dest_path + ".zip")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
            zf = zipfile.ZipFile(patch_dest_path + ".zip",'r')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
            zf.extractall(patch_dest_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
            os.remove(patch_dest_path + ".zip")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
        logger.notify("Patch jcc : %s " % (patch_dest_path))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
        os.chdir(patch_dest_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
        p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11"))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
        p.apply()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
        os.chdir(olddir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
    logger.notify("Install jcc")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
    call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
                    cwd=jcc_src_path,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
                    filter_stdout=filter_python_develop,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
                    show_stdout=True)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
    #install pylucene
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    logger.notify("Install pylucene")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    #modify makefile
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
    makefile_path = os.path.join(pylucene_src_path,"Makefile")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
    logger.notify("Modify makefile %s " % makefile_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
    shutil.move( makefile_path, makefile_path+"~" )
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    destination= open( makefile_path, "w" )
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
    source= open( makefile_path+"~", "r" )
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
    destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
    destination.write("ANT=ant\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
    destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
    if system_str == "Darwin":
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
        if sys.version_info >= (2,6):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
            destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
        else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
            destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
        destination.write("NUM_FILES=2\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
    elif system_str == "Windows":
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
        destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
        destination.write("NUM_FILES=2\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
    else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
        if sys.version_info >= (2,6) and sys.version_info <= (2,7):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
            destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
        else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
            destination.write("JCC=$(PYTHON) -m jcc --shared\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
        destination.write("NUM_FILES=2\n")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    for line in source:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
        destination.write( line )
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
    source.close()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
    destination.close()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
    os.remove(makefile_path+"~" )
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    logger.notify("pylucene make")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
    call_subprocess(['make'],
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
                    cwd=os.path.abspath(pylucene_src_path),
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
                    filter_stdout=filter_python_develop,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
                    show_stdout=True)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
    logger.notify("pylucene make install")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
    call_subprocess(['make', 'install'],
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
                    cwd=os.path.abspath(pylucene_src_path),
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
                    filter_stdout=filter_python_develop,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
                    show_stdout=True)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
def install_psycopg2(option_str, extra_env, res_source_key, home_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
    psycopg2_src = os.path.join(src_dir,"psycopg2.zip")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
    shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
    #extract psycopg2
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
    zf = zipfile.ZipFile(psycopg2_src)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    psycopg2_base_path = os.path.join(src_dir,"psycopg2")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
    zf.extractall(psycopg2_base_path)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
    zf.close()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
    psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0])
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
    shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib', 'psycopg2')))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
    shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.10-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib', 'site-packages')))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
def lib_generate_install_methods(path_locations, src_base, Logger, call_subprocess, normal_installs, urls=None):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
    all_urls = URLS.copy()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
    if urls is not None:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
        all_urls.update(urls)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
    res_env = ResourcesEnv(src_base, all_urls, normal_installs)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
    def filter_python_develop(line):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
        if not line.strip():
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
            return Logger.DEBUG
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
        for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
                       'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
                       'creating ', 'Copying ']:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
            if line.startswith(prefix):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
                return Logger.DEBUG
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
        return Logger.NOTIFY
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
    def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
        logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
        if method == 'pip':
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
            if sys.platform == 'win32':
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]]
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
            else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]]
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
            if option_str :
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
                args.insert(4,option_str)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
            call_subprocess(args,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
                    cwd=os.path.abspath(tmp_dir),
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
                    filter_stdout=filter_python_develop,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
                    show_stdout=True,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
                    extra_env=extra_env)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
        else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
            if sys.platform == 'win32':
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
                args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]]
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
            else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
                args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]]
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
            if option_str :
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
                args.insert(1,option_str)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
            call_subprocess(args,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
                    cwd=os.path.abspath(tmp_dir),
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
                    filter_stdout=filter_python_develop,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
                    show_stdout=True,
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
                    extra_env=extra_env)            
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
    def after_install(options, home_dir):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
        global logger
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
        verbosity = options.verbose - options.quiet
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
        logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)])
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
        home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
        base_dir = os.path.dirname(home_dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
        src_dir = os.path.join(home_dir, 'src')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
        tmp_dir = os.path.join(home_dir, 'tmp')
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
        ensure_dir(src_dir, logger)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
        ensure_dir(tmp_dir, logger)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
        system_str = platform.system()
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
        res_source_key = options.type_install
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
        ignore_packages = []
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
        if options.ignore_packages :
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
            ignore_packages = options.ignore_packages.split(",")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
        
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
        logger.indent += 2
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
        try:    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
            for key, method, option_str, extra_env in res_env.NORMAL_INSTALL:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
                if key not in ignore_packages:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
                    if callable(method):
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
                        method(option_str, extra_env, res_source_key, home_dir, tmp_dir, src_dir, res_env, logger, call_subprocess, filter_python_develop)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
                    else:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
                        normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir, res_env, logger, call_subprocess)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
                            
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
            logger.notify("Clear source dir")
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
            shutil.rmtree(src_dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
        finally:
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
            logger.indent -= 2
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
        script_dir = join(base_dir, bin_dir)
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
        logger.notify('Run "%s Package" to install new packages that provide builds'
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
                      % join(script_dir, 'easy_install'))
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
    
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
b40657713336 use platform and clean install files
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
    return adjust_options, extend_parser, after_install