sbin/virtualenv/create_python_env.py
author wakimd
Sun, 14 Nov 2010 20:25:22 +0100
changeset 1 3a30d255c235
child 3 9e6b4dbefcbc
permissions -rw-r--r--
First version of API with tests
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 += "    'FOURSUITE_XML' : { 'setup': '4Suite-XML', 'url': 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2', 'local': '"+ os.path.abspath(os.path.join(src_base,"4Suite-XML-1.0.2.tar.bz2"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    46
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
    47
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
    48
EXTRA_TEXT += "    'PYXML' : { 'setup': 'http://sourceforge.net/projects/pyxml/files/pyxml/0.8.4/PyXML-0.8.4.tar.gz/download', 'url': 'http://sourceforge.net/projects/pyxml/files/pyxml/0.8.4/PyXML-0.8.4.tar.gz/download', 'local': '"+ os.path.abspath(os.path.join(src_base,"PyXML-0.8.4.tar.gz"))+"', 'patch': '"+os.path.join(patch_path,"pyxml.patch")+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    49
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
    50
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
    51
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
    52
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
    53
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"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    54
EXTRA_TEXT += "    'LXML' : { 'setup': 'lxml', 'url': '"+ os.path.abspath(os.path.join(src_base,"lxml_2.2.7.tar.gz"))+"', 'local': '"+ os.path.abspath(os.path.join(src_base,"lxml-2.2.7.tar.gz"))+"'},\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    55
EXTRA_TEXT += "}\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    56
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    57
EXTRA_TEXT += "import sys\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    58
EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n"
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    59
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    60
EXTRA_TEXT += """
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    61
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    62
import shutil
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    63
import tarfile
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    64
import urllib
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    65
import platform
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    66
import patch
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    67
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    68
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    69
INDEX_URL = 'http://pypi.python.org/simple/'
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
def extend_parser(parser):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    73
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    74
        '--index-url',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    75
        metavar='INDEX_URL',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    76
        dest='index_url',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    77
        default='',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    78
        help='base URL of Python Package Index')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    79
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    80
        '--type-install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    81
        metavar='type_install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    82
        dest='type_install',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    83
        default='local',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    84
        help='type install : local, url, setup')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    85
    parser.add_option(
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    86
        '--ignore-packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    87
        metavar='ignore_packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    88
        dest='ignore_packages',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    89
        default=None,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    90
        help='list of comma separated keys for package to ignore')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    91
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    92
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    93
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    94
def adjust_options(options, args):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    95
    pass
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    96
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    97
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    98
def after_install(options, home_dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    99
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   100
    base_dir = os.path.dirname(home_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   101
    src_dir = join(home_dir, 'src')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   102
    tmp_dir = join(home_dir, 'tmp')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   103
    ensure_dir(src_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   104
    ensure_dir(tmp_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   105
    system_str = platform.system()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   106
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   107
    res_source_key = options.type_install
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   108
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   109
    ignore_packages = []
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   110
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   111
    if options.ignore_packages :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   112
        ignore_packages = options.ignore_packages.split(",")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   113
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   114
    logger.indent += 2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   115
    try:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   116
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   117
        if 'PYLUCENE' not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   118
            #get pylucene
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   119
            logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   120
            pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   121
            urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   122
            tf = tarfile.open(pylucene_src,'r:gz')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   123
            pylucene_base_path = os.path.join(src_dir,"pylucene") 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   124
            logger.notify("Extract Pylucene to %s " % pylucene_base_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   125
            tf.extractall(pylucene_base_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   126
            tf.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   127
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   128
            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
   129
            jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc"))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   130
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   131
            #install jcc
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   132
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   133
            #patch for linux
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   134
            if system_str == 'Linux' :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   135
                olddir = os.getcwd()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   136
                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
   137
                if os.path.isfile(patch_dest_path):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   138
                    # must unzip egg
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   139
                    # rename file and etract all
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   140
                    shutil.move(patch_dest_path, patch_dest_path + ".zip")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   141
                    zf = zipfile.ZipFile(patch_dest_path + ".zip",'r')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   142
                    zf.extractall(patch_dest_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   143
                    os.remove(patch_dest_path + ".zip")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   144
                logger.notify("Patch jcc : %s " % (patch_dest_path))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   145
                os.chdir(patch_dest_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   146
                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
   147
                p.apply()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   148
                os.chdir(olddir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   149
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   150
            logger.notify("Install jcc")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   151
            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
   152
                            cwd=jcc_src_path,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   153
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   154
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   155
            #install pylucene
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   156
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   157
            logger.notify("Install pylucene")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   158
            #modify makefile
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   159
            makefile_path = os.path.join(pylucene_src_path,"Makefile")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   160
            logger.notify("Modify makefile %s " % makefile_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   161
            shutil.move( makefile_path, makefile_path+"~" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   162
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   163
            destination= open( makefile_path, "w" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   164
            source= open( makefile_path+"~", "r" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   165
            destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   166
            destination.write("ANT=ant\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   167
            destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   168
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   169
            if system_str == "Darwin":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   170
                if sys.version_info >= (2,6):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   171
                    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
   172
                else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   173
                    destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   174
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   175
            elif system_str == "Windows":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   176
                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
   177
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   178
            else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   179
                if sys.version_info >= (2,6) and sys.version_info < (2,7):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   180
                    destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\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
                    destination.write("JCC=$(PYTHON) -m jcc --shared\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   183
                destination.write("NUM_FILES=2\\n")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   184
            for line in source:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   185
                destination.write( line )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   186
            source.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   187
            destination.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   188
            os.remove(makefile_path+"~" )
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   189
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   190
            logger.notify("pylucene make")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   191
            call_subprocess(['make'],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   192
                            cwd=os.path.abspath(pylucene_src_path),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   193
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   194
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   195
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   196
            logger.notify("pylucene make install")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   197
            call_subprocess(['make', 'install'],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   198
                            cwd=os.path.abspath(pylucene_src_path),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   199
                            filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   200
                            show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   201
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   202
        if system_str == 'Linux'  and 'DISTRIBUTE' not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   203
            normal_install('DISTRIBUTE', 'pip', None, None, res_source_key, home_dir, tmp_dir)
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 'PYXML' not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   206
            logger.notify("PyXML install : %s " % URLS['PYXML'][res_source_key])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   207
            if sys.version_info >= (2,6):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   208
                logger.notify("PyXML -> python version >= 2.6 : patching")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   209
                pyxml_src = os.path.join(src_dir,"pyxml.tar.gz")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   210
                urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   211
                logger.notify("PyXML -> python version >= 2.6 : extract archive")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   212
                tf = tarfile.open(pyxml_src,'r:gz')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   213
                pyxml_base_path = os.path.join(src_dir,"pyxml") 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   214
                tf.extractall(pyxml_base_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   215
                tf.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   216
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   217
                #patch
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   218
                pyxml_version = os.listdir(pyxml_base_path)[0]            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   219
                pyxml_path = os.path.join(pyxml_base_path, pyxml_version)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   220
                olddir = os.getcwd()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   221
                os.chdir(pyxml_path)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   222
                logger.notify("PyXML -> python version >= 2.6 : do patch %s : %s " % (pyxml_path, URLS['PYXML']['patch']))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   223
                p = patch.fromfile(URLS['PYXML']['patch'])
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   224
                p.apply()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   225
                os.chdir(olddir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   226
                logger.notify("PyXML -> python version >= 2.6 : install")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   227
                call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), '--build='+os.path.abspath(pyxml_base_path), '--no-download', pyxml_version],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   228
                        cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   229
                        filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   230
                        show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   231
            else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   232
                call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]],
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   233
                        cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   234
                        filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   235
                        show_stdout=True)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   236
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   237
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   238
        NORMAL_INSTALL = [ #(key,method, option_str, extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   239
            #('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'}),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   240
            ('PSYCOPG2', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   241
            ('MYSQL', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   242
            ('PIL', 'pip', None, None), 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   243
            ('FOURSUITE_XML','easy_install', None, None), 
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   244
            ('DJANGO','pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   245
            ('JOGGING','pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   246
            ('DJANGO-EXTENSIONS', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   247
            ('DJANGO-REGISTRATION', 'easy_install', '-Z', None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   248
            ('DJANGO-TAGGING', 'pip', None, None),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   249
            ]
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   250
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   251
        if system_str == "Darwin":
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   252
            NORMAL_INSTALL.append(('LXML', 'easy_install', None, {'STATIC_DEPS': 'true'}))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   253
        else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   254
            NORMAL_INSTALL.append(('LXML', 'easy_install', None, None))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   255
        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   256
            
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   257
        for key, method, option_str, extra_env in NORMAL_INSTALL:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   258
            if key not in ignore_packages:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   259
                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
   260
                        
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   261
        logger.notify("Clear source dir")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   262
        shutil.rmtree(src_dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   263
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   264
    finally:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   265
        logger.indent -= 2
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   266
    script_dir = join(base_dir, 'bin')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   267
    logger.notify('Run "%s Package" to install new packages that provide builds'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   268
                  % join(script_dir, 'easy_install'))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   269
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 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
   272
    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
   273
    if method == 'pip':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   274
        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
   275
        if option_str :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   276
            args.insert(4,option_str)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   277
        call_subprocess(args,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   278
                cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   279
                filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   280
                show_stdout=True,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   281
                extra_env=extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   282
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   283
        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
   284
        if option_str :
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   285
            args.insert(1,option_str)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   286
        call_subprocess(args,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   287
                cwd=os.path.abspath(tmp_dir),
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   288
                filter_stdout=filter_python_develop,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   289
                show_stdout=True,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   290
                extra_env=extra_env)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   291
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   292
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   293
def ensure_dir(dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   294
    if not os.path.exists(dir):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   295
        logger.notify('Creating directory %s' % dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   296
        os.makedirs(dir)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   297
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   298
def filter_python_develop(line):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   299
    if not line.strip():
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   300
        return Logger.DEBUG
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   301
    for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   302
                   'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   303
                   'creating ', 'Copying ']:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   304
        if line.startswith(prefix):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   305
            return Logger.DEBUG
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   306
    return Logger.NOTIFY
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   307
"""
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   308
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   309
def main():
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   310
    python_version = ".".join(map(str,sys.version_info[0:2]))
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   311
    text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   312
    if os.path.exists(script_name):
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   313
        f = open(script_name)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   314
        cur_text = f.read()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   315
        f.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   316
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   317
        cur_text = ''
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   318
    print 'Updating %s' % script_name
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   319
    if cur_text == 'text':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   320
        print 'No update'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   321
    else:
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   322
        print 'Script changed; updating...'
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   323
        f = open(script_name, 'w')
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   324
        f.write(text)
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   325
        f.close()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   326
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   327
if __name__ == '__main__':
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   328
    main()
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
   329