sbin/virtualenv/create_python_env.py
author ymh <ymh.work@gmail.com>
Mon, 13 Dec 2010 23:55:19 +0100
changeset 22 83b28fc0d731
parent 19 7cf81d58a968
permissions -rw-r--r--
improve on ldt test framework start migration for text test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
"""
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
Call this like ``python create_python_env.py``; it will
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
refresh the project-boot.py script
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
-prerequisite:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
- virtualenv
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
- distribute
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
- psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
- python project-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear --type-install=local <path_to_venv>
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
- For Linux :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
python project-boot.py --unzip-setuptools --no-site-packages --index-url=http://pypi.websushi.org/ --clear --type-install=local <path_to_venv>
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    15
"""
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    16
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    17
import os
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    18
import subprocess
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    19
import re
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    20
import sys
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    21
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    22
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    23
here = os.path.dirname(os.path.abspath(__file__))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    24
base_dir = here
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    25
script_name = os.path.join(base_dir, 'project-boot.py')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    26
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    27
import virtualenv
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    28
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    29
# things to install
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    30
# - psycopg2 -> pip
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    31
# - PIL -> pip
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    32
# - pyxml -> pip
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    33
# - 4Suite-xml - easy_install ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    34
# - pylucene  - script
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    35
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    36
src_base = os.path.join(here,"res","src")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    37
lib_path = os.path.abspath(os.path.join(here,"res","lib"))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    38
patch_path = os.path.abspath(os.path.join(here,"res","patch"))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    39
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    40
EXTRA_TEXT  = "URLS = { \n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    41
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    42
EXTRA_TEXT += "    'DISTRIBUTE' : { 'setup': 'distribute', 'url': 'http://pypi.python.org/packages/source/d/distribute/distribute-0.6.13.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"distribute-0.6.13.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    43
EXTRA_TEXT += "    'PSYCOPG2' : { 'setup': 'psycopg2','url': 'http://initd.org/pub/software/psycopg/psycopg2-2.2.1.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"psycopg2-2.2.1.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    44
EXTRA_TEXT += "    'MYSQL' : { 'setup': 'mysql-python', 'url': 'http://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz/download', 'local' : '"+ os.path.abspath(os.path.join(src_base,"MySQL-python-1.2.3c1.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    45
EXTRA_TEXT += "    'PYLUCENE' : { 'setup': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz', 'url': 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"pylucene-3.0.1-1-src.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    46
EXTRA_TEXT += "    'PIL' : { 'setup': 'pil', 'url': 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz', 'local': '"+ os.path.abspath(os.path.join(src_base,"Imaging-1.1.7.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    47
EXTRA_TEXT += "    'DJANGO' : { 'setup': 'django', 'url': 'http://www.djangoproject.com/download/1.2.3/tarball/', 'local': '"+ os.path.abspath(os.path.join(src_base,"Django-1.2.3.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    48
EXTRA_TEXT += "    'JOGGING' : { 'setup': 'jogging', 'url': 'http://github.com/zain/jogging/tarball/v0.2.2', 'local': '"+ os.path.abspath(os.path.join(src_base,"jogging-0.2.2.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    49
EXTRA_TEXT += "    'DJANGO-EXTENSIONS' : { 'setup': 'django-extensions', 'url':'http://django-command-extensions.googlecode.com/files/django-extensions-0.4.1.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-extensions-0.4.1.tar.gz"))+"' },\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    50
EXTRA_TEXT += "    'DJANGO-REGISTRATION' : { 'setup': 'django-registration', 'url':'http://bitbucket.org/ubernostrum/django-registration/get/tip.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-registration.tar.gz"))+"' },\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    51
EXTRA_TEXT += "    'DJANGO-TAGGING' : { 'setup': 'django-tagging', 'url':'http://django-tagging.googlecode.com/files/django-tagging-0.3.1.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-tagging-0.3.1.tar.gz"))+"' },\n"
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    52
EXTRA_TEXT += "    'SETUPTOOLS-HG' : { 'setup': 'setuptools-hg', 'url':'http://bitbucket.org/jezdez/setuptools_hg/downloads/setuptools_hg-0.2.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"setuptools_hg-0.2.tar.gz"))+"' },\n"
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    53
EXTRA_TEXT += "    'OAUTH2' : { 'setup': 'python-oauth2', 'url':'https://github.com/simplegeo/python-oauth2/tarball/1.2.1', 'local':'"+ os.path.abspath(os.path.join(src_base,"python-oauth2-1.2.1.tar.gz"))+"' },\n"
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    54
EXTRA_TEXT += "    'HTTPLIB2' : { 'setup': 'python-oauth2', 'url':'http://httplib2.googlecode.com/files/httplib2-0.6.0.tar.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"httplib2-0.6.0.tar.gz"))+"' },\n"
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    55
EXTRA_TEXT += "    'DJANGO-OAUTH-PLUS' : { 'setup': 'django-oauth-plus', 'url':'http://bitbucket.org/david/django-oauth-plus/get/f314f018e473.gz', 'local':'"+ os.path.abspath(os.path.join(src_base,"django-oauth-plus.gz"))+"' },\n"
14
446e0fd2ae55 Uograde lxml
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    56
EXTRA_TEXT += "    'LXML' : { 'setup': 'lxml', 'url': '"+ os.path.abspath(os.path.join(src_base,"lxml_2.2.8.tar.gz"))+"', 'local': '"+ os.path.abspath(os.path.join(src_base,"lxml-2.2.8.tar.gz"))+"'},\n"
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    57
EXTRA_TEXT += "}\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    58
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    59
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    60
EXTRA_TEXT += "import sys\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    61
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    62
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    63
EXTRA_TEXT += """
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    64
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    65
import shutil
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    66
import tarfile
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    67
import urllib
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    68
import platform
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    69
import patch
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    70
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    71
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    72
INDEX_URL = 'http://pypi.python.org/simple/'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    73
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    74
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    75
def extend_parser(parser):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    76
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    77
        '--index-url',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    78
        metavar='INDEX_URL',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    79
        dest='index_url',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    80
        default='',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    81
        help='base URL of Python Package Index')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    82
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    83
        '--type-install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    84
        metavar='type_install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    85
        dest='type_install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    86
        default='local',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    87
        help='type install : local, url, setup')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    88
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    89
        '--ignore-packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    90
        metavar='ignore_packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    91
        dest='ignore_packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    92
        default=None,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    93
        help='list of comma separated keys for package to ignore')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    94
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    95
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    96
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    97
def adjust_options(options, args):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    98
    pass
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    99
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   100
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   101
def after_install(options, home_dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   102
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   103
    base_dir = os.path.dirname(home_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   104
    src_dir = join(home_dir, 'src')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   105
    tmp_dir = join(home_dir, 'tmp')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   106
    ensure_dir(src_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   107
    ensure_dir(tmp_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   108
    system_str = platform.system()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   109
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   110
    res_source_key = options.type_install
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   111
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   112
    ignore_packages = []
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   113
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   114
    if options.ignore_packages :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   115
        ignore_packages = options.ignore_packages.split(",")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   116
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   117
    logger.indent += 2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   118
    try:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   119
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   120
        if 'PYLUCENE' not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   121
            #get pylucene
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   122
            logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   123
            pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   124
            urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   125
            tf = tarfile.open(pylucene_src,'r:gz')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   126
            pylucene_base_path = os.path.join(src_dir,"pylucene") 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   127
            logger.notify("Extract Pylucene to %s " % pylucene_base_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   128
            tf.extractall(pylucene_base_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   129
            tf.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   130
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   131
            pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   132
            jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc"))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   133
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   134
            #install jcc
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   135
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   136
            #patch for linux
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   137
            if system_str == 'Linux' :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   138
                olddir = os.getcwd()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   139
                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')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   140
                if os.path.isfile(patch_dest_path):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   141
                    # must unzip egg
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   142
                    # rename file and etract all
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   143
                    shutil.move(patch_dest_path, patch_dest_path + ".zip")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   144
                    zf = zipfile.ZipFile(patch_dest_path + ".zip",'r')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   145
                    zf.extractall(patch_dest_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   146
                    os.remove(patch_dest_path + ".zip")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   147
                logger.notify("Patch jcc : %s " % (patch_dest_path))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   148
                os.chdir(patch_dest_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   149
                p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11"))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   150
                p.apply()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   151
                os.chdir(olddir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   152
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   153
            logger.notify("Install jcc")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   154
            call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   155
                            cwd=jcc_src_path,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   156
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   157
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   158
            #install pylucene
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   159
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   160
            logger.notify("Install pylucene")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   161
            #modify makefile
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   162
            makefile_path = os.path.join(pylucene_src_path,"Makefile")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   163
            logger.notify("Modify makefile %s " % makefile_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   164
            shutil.move( makefile_path, makefile_path+"~" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   165
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   166
            destination= open( makefile_path, "w" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   167
            source= open( makefile_path+"~", "r" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   168
            destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   169
            destination.write("ANT=ant\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   170
            destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   171
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   172
            if system_str == "Darwin":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   173
                if sys.version_info >= (2,6):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   174
                    destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   175
                else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   176
                    destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   177
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   178
            elif system_str == "Windows":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   179
                destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   180
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   181
            else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   182
                if sys.version_info >= (2,6) and sys.version_info < (2,7):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   183
                    destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   184
                else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   185
                    destination.write("JCC=$(PYTHON) -m jcc --shared\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   186
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   187
            for line in source:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   188
                destination.write( line )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   189
            source.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   190
            destination.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   191
            os.remove(makefile_path+"~" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   192
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   193
            logger.notify("pylucene make")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   194
            call_subprocess(['make'],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   195
                            cwd=os.path.abspath(pylucene_src_path),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   196
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   197
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   198
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   199
            logger.notify("pylucene make install")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   200
            call_subprocess(['make', 'install'],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   201
                            cwd=os.path.abspath(pylucene_src_path),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   202
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   203
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   204
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   205
        if system_str == 'Linux'  and 'DISTRIBUTE' not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   206
            normal_install('DISTRIBUTE', 'pip', None, None, res_source_key, home_dir, tmp_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   207
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   208
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   209
        NORMAL_INSTALL = [ #(key,method, option_str, extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   210
            #('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'}),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   211
            ('PSYCOPG2', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   212
            ('MYSQL', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   213
            ('PIL', 'pip', None, None), 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   214
            ('DJANGO','pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   215
            ('JOGGING','pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   216
            ('DJANGO-EXTENSIONS', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   217
            ('DJANGO-REGISTRATION', 'easy_install', '-Z', None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   218
            ('DJANGO-TAGGING', 'pip', None, None),
22
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   219
            ('HTTPLIB2', 'pip', None, None),
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   220
            ('OAUTH2', 'pip', None, None),
83b28fc0d731 improve on ldt test framework
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   221
            ('DJANGO-OAUTH-PLUS', 'pip', None, None),
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   222
            ]
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   223
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   224
        if system_str == "Darwin":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   225
            NORMAL_INSTALL.append(('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'}))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   226
        else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   227
            NORMAL_INSTALL.append(('LXML', 'easy_install', None, None))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   228
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   229
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   230
        for key, method, option_str, extra_env in NORMAL_INSTALL:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   231
            if key not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   232
                normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   233
                        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   234
        logger.notify("Clear source dir")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   235
        shutil.rmtree(src_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   236
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   237
    finally:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   238
        logger.indent -= 2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   239
    script_dir = join(base_dir, 'bin')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   240
    logger.notify('Run "%s Package" to install new packages that provide builds'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   241
                  % join(script_dir, 'easy_install'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   242
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   243
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   244
def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   245
    logger.notify("Install %s from %s with %s" % (key,URLS[key][res_source_key],method))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   246
    if method == 'pip':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   247
        args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS[key][res_source_key]]
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   248
        if option_str :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   249
            args.insert(4,option_str)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   250
        call_subprocess(args,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   251
                cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   252
                filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   253
                show_stdout=True,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   254
                extra_env=extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   255
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   256
        args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS[key][res_source_key]]
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   257
        if option_str :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   258
            args.insert(1,option_str)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   259
        call_subprocess(args,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   260
                cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   261
                filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   262
                show_stdout=True,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   263
                extra_env=extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   264
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   265
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   266
def ensure_dir(dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   267
    if not os.path.exists(dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   268
        logger.notify('Creating directory %s' % dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   269
        os.makedirs(dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   270
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   271
def filter_python_develop(line):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   272
    if not line.strip():
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   273
        return Logger.DEBUG
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   274
    for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   275
                   'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   276
                   'creating ', 'Copying ']:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   277
        if line.startswith(prefix):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   278
            return Logger.DEBUG
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   279
    return Logger.NOTIFY
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   280
"""
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   281
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   282
def main():
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   283
    python_version = ".".join(map(str,sys.version_info[0:2]))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   284
    text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   285
    if os.path.exists(script_name):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   286
        f = open(script_name)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   287
        cur_text = f.read()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   288
        f.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   289
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   290
        cur_text = ''
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   291
    print 'Updating %s' % script_name
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   292
    if cur_text == 'text':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   293
        print 'No update'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   294
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   295
        print 'Script changed; updating...'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   296
        f = open(script_name, 'w')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   297
        f.write(text)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   298
        f.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   299
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   300
if __name__ == '__main__':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   301
    main()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   302