sbin/create_python_env.py
changeset 35 8b65c9054eac
parent 34 05d10640919a
child 36 bbe6f42d42b2
equal deleted inserted replaced
34:05d10640919a 35:8b65c9054eac
     7 - virtualenv
     7 - virtualenv
     8 - distribute
     8 - distribute
     9 - psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility
     9 - psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility
    10 
    10 
    11 - virtualenv --distribute --no-site-packages venv
    11 - virtualenv --distribute --no-site-packages venv
       
    12 
       
    13 - python blinkster-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear bvenv
    12 
    14 
    13 """
    15 """
    14 import os
    16 import os
    15 import subprocess
    17 import subprocess
    16 import re
    18 import re
    36 import shutil
    38 import shutil
    37 import tarfile
    39 import tarfile
    38 import urllib
    40 import urllib
    39 import platform
    41 import platform
    40 
    42 
       
    43 PSYCOPG2_URL = 'http://initd.org/pub/software/psycopg/psycopg2-2.2.1.tar.gz'
    41 FOURSUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2'
    44 FOURSUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2'
    42 PY_LUCENE_URL = 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz'
    45 PY_LUCENE_URL = 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz'
       
    46 PIL_URL = 'http://effbot.org/downloads/Imaging-1.1.7.tar.gz'
       
    47 INDEX_URL = 'http://pypi.python.org/simple/'
       
    48 PYXML_URL = "http://sourceforge.net/projects/pyxml/files/pyxml/0.8.4/PyXML-0.8.4.tar.gz/download"
       
    49 
    43 
    50 
    44 def extend_parser(parser):
    51 def extend_parser(parser):
    45     pass
    52     parser.add_option(
       
    53         '--index-url',
       
    54         metavar='INDEX_URL',
       
    55         dest='index_url',
       
    56         default='',
       
    57         help='base URL of Python Package Index')
    46 
    58 
    47 def adjust_options(options, args):
    59 def adjust_options(options, args):
    48     if not args:
    60     pass
    49         return # caller will raise error
       
    50     
       
    51     # We're actually going to build the venv in a subdirectory
       
    52     base_dir = args[0]
       
    53     if len(args) > 1:
       
    54         venv_name = args[1]
       
    55     else:
       
    56         venv_name = "blinkster"
       
    57         
       
    58     args[0] = join(base_dir, venv_name)
       
    59 
    61 
    60 
    62 
    61 def after_install(options, home_dir):
    63 def after_install(options, home_dir):
    62     base_dir = os.path.dirname(home_dir)
    64     base_dir = os.path.dirname(home_dir)
    63     src_dir = join(home_dir, 'src')
    65     src_dir = join(home_dir, 'src')
    64     tmp_dir = join(home_dir, 'tmp')
    66     tmp_dir = join(home_dir, 'tmp')
    65     ensure_dir(src_dir)
    67     ensure_dir(src_dir)
    66     ensure_dir(tmp_dir)
    68     ensure_dir(tmp_dir)
    67     logger.indent += 2
    69     logger.indent += 2
    68     try:
    70     try:
    69         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')) ,'-E '+ os.path.abspath(home_dir), 'psycopg2', 'pil', 'pyxml'],
    71         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), PSYCOPG2_URL],
    70                         cwd=os.path.abspath(tmp_dir),
    72                         cwd=os.path.abspath(tmp_dir),
    71                         filter_stdout=filter_python_develop,
    73                         filter_stdout=filter_python_develop,
    72                         show_stdout=False)
    74                         show_stdout=True)
       
    75         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), PIL_URL],
       
    76                         cwd=os.path.abspath(tmp_dir),
       
    77                         filter_stdout=filter_python_develop,
       
    78                         show_stdout=True)
       
    79         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), PYXML_URL],
       
    80                         cwd=os.path.abspath(tmp_dir),
       
    81                         filter_stdout=filter_python_develop,
       
    82                         show_stdout=True)
    73         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), FOURSUITE_XML_URL],
    83         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), FOURSUITE_XML_URL],
    74                         cwd=os.path.abspath(tmp_dir),
    84                         cwd=os.path.abspath(tmp_dir),
    75                         filter_stdout=filter_python_develop,
    85                         filter_stdout=filter_python_develop,
    76                         show_stdout=False)
    86                         show_stdout=True)
    77 
    87 
    78         #get pylucene
    88         #get pylucene
    79         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
    89         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
    80         urllib.urlretrieve(PY_LUCENE_URL, pylucene_src)
    90         urllib.urlretrieve(PY_LUCENE_URL, pylucene_src)
    81         tf = tarfile.open(pylucene_src,'r:gz')
    91         tf = tarfile.open(pylucene_src,'r:gz')
    87         
    97         
    88         #install jcc
    98         #install jcc
    89         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
    99         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
    90                         cwd=os.path.abspath(os.path.join(pylucene_src_path,"jcc")),
   100                         cwd=os.path.abspath(os.path.join(pylucene_src_path,"jcc")),
    91                         filter_stdout=filter_python_develop,
   101                         filter_stdout=filter_python_develop,
    92                         show_stdout=False)
   102                         show_stdout=True)
    93         #install pylucene       
   103         #install pylucene       
    94         #modify makefile
   104         #modify makefile
    95         makefile_path = os.path.join(pylucene_src_path,"Makefile")
   105         makefile_path = os.path.join(pylucene_src_path,"Makefile")
    96         shutil.move( makefile_path, makefile_path+"~" )
   106         shutil.move( makefile_path, makefile_path+"~" )
    97 
   107 
    98         destination= open( makefile_path, "w" )
   108         destination= open( makefile_path, "w" )
    99         source= open( makefile_path+"~", "r" )
   109         source= open( makefile_path+"~", "r" )
   100         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir))
   110         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   101         destination.write("ANT=ant")
   111         destination.write("ANT=ant\\n")
   102         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python")
   112         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
   103         system_str = platform.system()
   113         system_str = platform.system()
   104         if system_str == "Darwin":
   114         if system_str == "Darwin":
   105             destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386")
   115             if sys.version_info > (2,6):
   106             destination.write("NUM_FILES=2")
   116                 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
       
   117             else:
       
   118                 destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n")
       
   119             destination.write("NUM_FILES=2\\n")
   107         elif system_str == "Windows":
   120         elif system_str == "Windows":
   108             destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386")
   121             destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
   109             destination.write("NUM_FILES=2")
   122             destination.write("NUM_FILES=2\\n")
   110         else:
   123         else:
   111             destination.write("JCC=$(PYTHON) -m jcc --shared")
   124             destination.write("JCC=$(PYTHON) -m jcc --shared\\n")
   112             destination.write("NUM_FILES=2")
   125             destination.write("NUM_FILES=2\\n")
   113         for line in source:
   126         for line in source:
   114             destination.write( line )
   127             destination.write( line )
   115         source.close()
   128         source.close()
   116         destination.close()
   129         destination.close()
   117         os.remove(makefile_path+"~" )
   130         os.remove(makefile_path+"~" )
   118 
   131 
   119         call_subprocess(['make', 'install'],
   132         call_subprocess(['make', 'install'],
   120                         cwd=os.path.abspath(pylucene_src_path),
   133                         cwd=os.path.abspath(pylucene_src_path),
   121                         filter_stdout=filter_python_develop,
   134                         filter_stdout=filter_python_develop,
   122                         show_stdout=False)
   135                         show_stdout=True)
   123 
   136         shutil.rmtree(src_dir)
   124         os.re
       
   125         
       
   126         os.removedirs(src_dir)
       
   127 
   137 
   128     finally:
   138     finally:
   129         logger.indent -= 2
   139         logger.indent -= 2
   130     script_dir = join(base_dir, 'bin')
   140     script_dir = join(base_dir, 'bin')
   131     logger.notify('Run "%s Package" to install new packages that provide builds'
   141     logger.notify('Run "%s Package" to install new packages that provide builds'