sbin/create_python_env.py
changeset 36 bbe6f42d42b2
parent 35 8b65c9054eac
child 42 f5f3563d43fa
child 49 92e78a11e8df
equal deleted inserted replaced
35:8b65c9054eac 36:bbe6f42d42b2
     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 - python blinkster-boot.py --distribute --no-site-packages --index-url=http://pypi.websushi.org/ --clear bvenv
    14 
    13 
    15 """
    14 """
       
    15 
    16 import os
    16 import os
    17 import subprocess
    17 import subprocess
    18 import re
    18 import re
    19 import sys
    19 import sys
       
    20 
    20 
    21 
    21 here = os.path.dirname(os.path.abspath(__file__))
    22 here = os.path.dirname(os.path.abspath(__file__))
    22 base_dir = here
    23 base_dir = here
    23 script_name = os.path.join(base_dir, 'blinkster-boot.py')
    24 script_name = os.path.join(base_dir, 'blinkster-boot.py')
    24 
    25 
    29 # - PIL -> pip
    30 # - PIL -> pip
    30 # - pyxml -> pip
    31 # - pyxml -> pip
    31 # - 4Suite-xml - easy_install ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2
    32 # - 4Suite-xml - easy_install ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2
    32 # - pylucene  - script
    33 # - pylucene  - script
    33 
    34 
    34 
    35 src_base = os.path.join(here,"res","src")
    35 
    36 lib_path = os.path.abspath(os.path.join(here,"res","lib"))
    36 EXTRA_TEXT = """
    37 patch_path = os.path.abspath(os.path.join(here,"res","patch"))
       
    38 
       
    39 EXTRA_TEXT  = "URLS = { \n"
       
    40 
       
    41 EXTRA_TEXT += "    '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"
       
    42 EXTRA_TEXT += "    'FOURSUITE_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"
       
    43 EXTRA_TEXT += "    'PYLUCENE' : { '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"
       
    44 EXTRA_TEXT += "    '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"
       
    45 EXTRA_TEXT += "    'PYXML' : { '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"
       
    46 
       
    47 EXTRA_TEXT += "}\n"
       
    48 
       
    49 EXTRA_TEXT += "import sys\n"
       
    50 EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n"
       
    51 
       
    52 EXTRA_TEXT += """
    37 
    53 
    38 import shutil
    54 import shutil
    39 import tarfile
    55 import tarfile
    40 import urllib
    56 import urllib
    41 import platform
    57 import platform
    42 
    58 import patch
    43 PSYCOPG2_URL = 'http://initd.org/pub/software/psycopg/psycopg2-2.2.1.tar.gz'
    59 
    44 FOURSUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2'
    60 
    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/'
    61 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 
    62 
    50 
    63 
    51 def extend_parser(parser):
    64 def extend_parser(parser):
    52     parser.add_option(
    65     parser.add_option(
    53         '--index-url',
    66         '--index-url',
    54         metavar='INDEX_URL',
    67         metavar='INDEX_URL',
    55         dest='index_url',
    68         dest='index_url',
    56         default='',
    69         default='',
    57         help='base URL of Python Package Index')
    70         help='base URL of Python Package Index')
       
    71     parser.add_option(
       
    72         '--local',
       
    73         metavar='LOCAL',
       
    74         dest='local',
       
    75         action="store_true",
       
    76         default=False,
       
    77         help='base URL of Python Package Index')
       
    78 
    58 
    79 
    59 def adjust_options(options, args):
    80 def adjust_options(options, args):
    60     pass
    81     pass
    61 
    82 
    62 
    83 
    64     base_dir = os.path.dirname(home_dir)
    85     base_dir = os.path.dirname(home_dir)
    65     src_dir = join(home_dir, 'src')
    86     src_dir = join(home_dir, 'src')
    66     tmp_dir = join(home_dir, 'tmp')
    87     tmp_dir = join(home_dir, 'tmp')
    67     ensure_dir(src_dir)
    88     ensure_dir(src_dir)
    68     ensure_dir(tmp_dir)
    89     ensure_dir(tmp_dir)
       
    90     
       
    91     res_source_key = "local" if options.local else "url"
       
    92     
    69     logger.indent += 2
    93     logger.indent += 2
    70     try:
    94     try:
    71         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), PSYCOPG2_URL],
    95         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PSYCOPG2'][res_source_key]],
    72                         cwd=os.path.abspath(tmp_dir),
    96                         cwd=os.path.abspath(tmp_dir),
    73                         filter_stdout=filter_python_develop,
    97                         filter_stdout=filter_python_develop,
    74                         show_stdout=True)
    98                         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],
    99 
       
   100         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PIL'][res_source_key]],
    76                         cwd=os.path.abspath(tmp_dir),
   101                         cwd=os.path.abspath(tmp_dir),
    77                         filter_stdout=filter_python_develop,
   102                         filter_stdout=filter_python_develop,
    78                         show_stdout=True)
   103                         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],
   104 
       
   105         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS['FOURSUITE_XML'][res_source_key]],
    80                         cwd=os.path.abspath(tmp_dir),
   106                         cwd=os.path.abspath(tmp_dir),
    81                         filter_stdout=filter_python_develop,
   107                         filter_stdout=filter_python_develop,
    82                         show_stdout=True)
   108                         show_stdout=True)
    83         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), FOURSUITE_XML_URL],
   109 
    84                         cwd=os.path.abspath(tmp_dir),
   110         
    85                         filter_stdout=filter_python_develop,
   111         if sys.version_info >= (2,6):
    86                         show_stdout=True)
   112             pyxml_src = os.path.join(src_dir,"pyxml.tar.gz")
       
   113             urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src)
       
   114             tf = tarfile.open(pyxml_src,'r:gz')
       
   115             pyxml_base_path = os.path.join(src_dir,"pyxml") 
       
   116             tf.extractall(pyxml_base_path)
       
   117             tf.close()
       
   118             #patch
       
   119             pyxml_version = os.listdir(pyxml_base_path)[0]            
       
   120             pyxml_path = os.path.join(pyxml_base_path, pyxml_version)
       
   121             olddir = os.getcwd()
       
   122             os.chdir(pyxml_path)
       
   123             p = patch.fromfile(URLS['PYXML']['patch'])
       
   124             p.apply()
       
   125             os.chdir(olddir)
       
   126             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],
       
   127                     cwd=os.path.abspath(tmp_dir),
       
   128                     filter_stdout=filter_python_develop,
       
   129                     show_stdout=True)
       
   130         else:
       
   131             call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]],
       
   132                     cwd=os.path.abspath(tmp_dir),
       
   133                     filter_stdout=filter_python_develop,
       
   134                     show_stdout=True)
       
   135         
    87 
   136 
    88         #get pylucene
   137         #get pylucene
    89         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   138         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
    90         urllib.urlretrieve(PY_LUCENE_URL, pylucene_src)
   139         urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
    91         tf = tarfile.open(pylucene_src,'r:gz')
   140         tf = tarfile.open(pylucene_src,'r:gz')
    92         pylucene_base_path = os.path.join(src_dir,"pylucene") 
   141         pylucene_base_path = os.path.join(src_dir,"pylucene") 
    93         tf.extractall(pylucene_base_path)
   142         tf.extractall(pylucene_base_path)
    94         tf.close()
   143         tf.close()
    95         
   144         
   110         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   159         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   111         destination.write("ANT=ant\\n")
   160         destination.write("ANT=ant\\n")
   112         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
   161         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
   113         system_str = platform.system()
   162         system_str = platform.system()
   114         if system_str == "Darwin":
   163         if system_str == "Darwin":
   115             if sys.version_info > (2,6):
   164             if sys.version_info >= (2,6):
   116                 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
   165                 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
   117             else:
   166             else:
   118                 destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n")
   167                 destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n")
   119             destination.write("NUM_FILES=2\\n")
   168             destination.write("NUM_FILES=2\\n")
   120         elif system_str == "Windows":
   169         elif system_str == "Windows":
   126         for line in source:
   175         for line in source:
   127             destination.write( line )
   176             destination.write( line )
   128         source.close()
   177         source.close()
   129         destination.close()
   178         destination.close()
   130         os.remove(makefile_path+"~" )
   179         os.remove(makefile_path+"~" )
       
   180 
       
   181         call_subprocess(['make'],
       
   182                         cwd=os.path.abspath(pylucene_src_path),
       
   183                         filter_stdout=filter_python_develop,
       
   184                         show_stdout=True)
   131 
   185 
   132         call_subprocess(['make', 'install'],
   186         call_subprocess(['make', 'install'],
   133                         cwd=os.path.abspath(pylucene_src_path),
   187                         cwd=os.path.abspath(pylucene_src_path),
   134                         filter_stdout=filter_python_develop,
   188                         filter_stdout=filter_python_develop,
   135                         show_stdout=True)
   189                         show_stdout=True)