sbin/create_python_env.py
changeset 34 05d10640919a
parent 33 b25bb1dd177c
child 35 8b65c9054eac
equal deleted inserted replaced
33:b25bb1dd177c 34:05d10640919a
     1 """
     1 """
     2 Call this like ``python fassembler/create_python_env.py``; it will
     2 Call this like ``python create_python_env.py``; it will
     3 refresh the blinkster-boot.py script
     3 refresh the blinkster-boot.py script
     4 
     4 
     5 -prerequisite:
     5 -prerequisite:
     6 
     6 
     7 - virtualenv
     7 - virtualenv
    12 
    12 
    13 """
    13 """
    14 import os
    14 import os
    15 import subprocess
    15 import subprocess
    16 import re
    16 import re
       
    17 import sys
    17 
    18 
    18 here = os.path.dirname(os.path.abspath(__file__))
    19 here = os.path.dirname(os.path.abspath(__file__))
    19 base_dir = os.path.dirname(here)
    20 base_dir = here
    20 script_name = os.path.join(base_dir, 'blinkster-boot.py')
    21 script_name = os.path.join(base_dir, 'blinkster-boot.py')
    21 
    22 
    22 import virtualenv
    23 import virtualenv
    23 
    24 
    24 # things to install
    25 # things to install
    33 EXTRA_TEXT = """
    34 EXTRA_TEXT = """
    34 
    35 
    35 import shutil
    36 import shutil
    36 import tarfile
    37 import tarfile
    37 import urllib
    38 import urllib
       
    39 import platform
    38 
    40 
    39 4SUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2'
    41 FOURSUITE_XML_URL = 'ftp://ftp.4suite.org/pub/4Suite/4Suite-XML-1.0.2.tar.bz2'
    40 PY_LUCENE_URL = 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz'
    42 PY_LUCENE_URL = 'http://apache.crihan.fr/dist/lucene/pylucene/pylucene-3.0.1-1-src.tar.gz'
    41 
    43 
    42 def extend_parser(parser):
    44 def extend_parser(parser):
    43     pass
    45     pass
    44 
    46 
    60     base_dir = os.path.dirname(home_dir)
    62     base_dir = os.path.dirname(home_dir)
    61     src_dir = join(home_dir, 'src')
    63     src_dir = join(home_dir, 'src')
    62     tmp_dir = join(home_dir, 'tmp')
    64     tmp_dir = join(home_dir, 'tmp')
    63     ensure_dir(src_dir)
    65     ensure_dir(src_dir)
    64     ensure_dir(tmp_dir)
    66     ensure_dir(tmp_dir)
    65     #logger.indent += 2
    67     logger.indent += 2
    66     try:
    68     try:
    67         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), ,'-E '+ os.path.abspath(home_dir), 'psycopg2', 'pil', 'pyxml'],
    69         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')) ,'-E '+ os.path.abspath(home_dir), 'psycopg2', 'pil', 'pyxml'],
    68                         cwd=os.path.abspath(tmp_dir),
    70                         cwd=os.path.abspath(tmp_dir),
    69                         filter_stdout=filter_python_develop,
    71                         filter_stdout=filter_python_develop,
    70                         show_stdout=False)
    72                         show_stdout=False)
    71         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), 4SUITE_XML_URL],
    73         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), FOURSUITE_XML_URL],
    72                         cwd=os.path.abspath(tmp_dir),
    74                         cwd=os.path.abspath(tmp_dir),
    73                         filter_stdout=filter_python_develop,
    75                         filter_stdout=filter_python_develop,
    74                         show_stdout=False)
    76                         show_stdout=False)
    75 
    77 
    76         #get pylucene
    78         #get pylucene
    77         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
    79         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
    78         urllib.urlretrieve(PY_LUCENE_URL, pylucene_src)
    80         urllib.urlretrieve(PY_LUCENE_URL, pylucene_src)
    79         tf = tarfile.open(pylucene_src,'r:gz')
    81         tf = tarfile.open(pylucene_src,'r:gz')
    80         tf.extractall(os.path.join(src_dir,"pylucene"))
    82         pylucene_base_path = os.path.join(src_dir,"pylucene") 
       
    83         tf.extractall(pylucene_base_path)
    81         tf.close()
    84         tf.close()
       
    85         
       
    86         pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0])
       
    87         
    82         #install jcc
    88         #install jcc
    83         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
    89         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
    84                         cwd=os.path.abspath(os.path.join(src_dir,"pylucene","pylucene-3.0.1-1","jcc")),
    90                         cwd=os.path.abspath(os.path.join(pylucene_src_path,"jcc")),
    85                         filter_stdout=filter_python_develop,
    91                         filter_stdout=filter_python_develop,
    86                         show_stdout=False)
    92                         show_stdout=False)
    87         #install pylucene       
    93         #install pylucene       
    88         #modify makefile 
    94         #modify makefile
    89 #PREFIX_PYTHON=os.path.abspath(fassembler_dir)
    95         makefile_path = os.path.join(pylucene_src_path,"Makefile")
    90 #ANT=ant
    96         shutil.move( makefile_path, makefile_path+"~" )
    91 #PYTHON=$(PREFIX_PYTHON)/bin/python
       
    92 #osx 10.5 10.6 32-64 bit
       
    93 #JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386
       
    94 #NUM_FILES=2
       
    95 
    97 
    96 #linux 
    98         destination= open( makefile_path, "w" )
    97 #JCC=$(PYTHON) -m jcc --shared
    99         source= open( makefile_path+"~", "r" )
    98 #NUM_FILES=2
   100         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir))
       
   101         destination.write("ANT=ant")
       
   102         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python")
       
   103         system_str = platform.system()
       
   104         if system_str == "Darwin":
       
   105             destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386")
       
   106             destination.write("NUM_FILES=2")
       
   107         elif system_str == "Windows":
       
   108             destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386")
       
   109             destination.write("NUM_FILES=2")
       
   110         else:
       
   111             destination.write("JCC=$(PYTHON) -m jcc --shared")
       
   112             destination.write("NUM_FILES=2")
       
   113         for line in source:
       
   114             destination.write( line )
       
   115         source.close()
       
   116         destination.close()
       
   117         os.remove(makefile_path+"~" )
    99 
   118 
   100 # windows
   119         call_subprocess(['make', 'install'],
   101 #JCC=$(PYTHON) -m jcc --shared
   120                         cwd=os.path.abspath(pylucene_src_path),
   102 #NUM_FILES=3
   121                         filter_stdout=filter_python_develop,
       
   122                         show_stdout=False)
   103 
   123 
       
   124         os.re
       
   125         
       
   126         os.removedirs(src_dir)
   104 
   127 
   105 #install pylucene
       
   106 #delete src
       
   107         #call_subprocess([os.path.abspath(join(home_dir, 'bin', 'python')), 'setup.py', 'develop'],
       
   108         #                cwd=os.path.abspath(fassembler_dir),
       
   109         #                filter_stdout=filter_python_develop,
       
   110         #                show_stdout=False)
       
   111     finally:
   128     finally:
   112         #logger.indent -= 2
   129         logger.indent -= 2
   113     script_dir = join(base_dir, 'bin')
   130     script_dir = join(base_dir, 'bin')
   114     logger.notify('Run "%s Package" to install new packages that provide builds'
   131     logger.notify('Run "%s Package" to install new packages that provide builds'
   115                   % join(script_dir, 'easy_install'))
   132                   % join(script_dir, 'easy_install'))
   116 
   133 
   117 def ensure_dir(dir):
   134 def ensure_dir(dir):