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