sbin/create_python_env.py
changeset 50 012451a812f1
parent 49 92e78a11e8df
parent 46 5503cfcdea68
child 52 cabe73ea6929
equal deleted inserted replaced
49:92e78a11e8df 50:012451a812f1
    36 lib_path = os.path.abspath(os.path.join(here,"res","lib"))
    36 lib_path = os.path.abspath(os.path.join(here,"res","lib"))
    37 patch_path = os.path.abspath(os.path.join(here,"res","patch"))
    37 patch_path = os.path.abspath(os.path.join(here,"res","patch"))
    38 
    38 
    39 EXTRA_TEXT  = "URLS = { \n"
    39 EXTRA_TEXT  = "URLS = { \n"
    40 
    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"
    41 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"
    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"
    42 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"
    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"
    43 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"
    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"
    44 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"
    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"
    45 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"
       
    46 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"
    46 
    47 
    47 EXTRA_TEXT += "}\n"
    48 EXTRA_TEXT += "}\n"
    48 
    49 
    49 EXTRA_TEXT += "import sys\n"
    50 EXTRA_TEXT += "import sys\n"
    50 EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n"
    51 EXTRA_TEXT += "sys.path.append('"+lib_path+"')\n"
    67         metavar='INDEX_URL',
    68         metavar='INDEX_URL',
    68         dest='index_url',
    69         dest='index_url',
    69         default='',
    70         default='',
    70         help='base URL of Python Package Index')
    71         help='base URL of Python Package Index')
    71     parser.add_option(
    72     parser.add_option(
    72         '--local',
    73         '--type-install',
    73         metavar='LOCAL',
    74         metavar='type_install',
    74         dest='local',
    75         dest='type_install',
    75         action="store_true",
    76         default='local',
    76         default=False,
    77         help='type install : local, url, setup')
    77         help='base URL of Python Package Index')
       
    78 
    78 
    79 
    79 
    80 def adjust_options(options, args):
    80 def adjust_options(options, args):
    81     pass
    81     pass
    82 
    82 
    83 
    83 
    84 def after_install(options, home_dir):
    84 def after_install(options, home_dir):
       
    85     home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
    85     base_dir = os.path.dirname(home_dir)
    86     base_dir = os.path.dirname(home_dir)
    86     src_dir = join(home_dir, 'src')
    87     src_dir = join(home_dir, 'src')
    87     tmp_dir = join(home_dir, 'tmp')
    88     tmp_dir = join(home_dir, 'tmp')
    88     ensure_dir(src_dir)
    89     ensure_dir(src_dir)
    89     ensure_dir(tmp_dir)
    90     ensure_dir(tmp_dir)
       
    91     system_str = platform.system()
    90     
    92     
    91     res_source_key = "local" if options.local else "url"
    93     res_source_key = options.type_install
    92     
    94     
    93     logger.indent += 2
    95     logger.indent += 2
    94     try:
    96     try:
    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]],
    97         
    96                         cwd=os.path.abspath(tmp_dir),
       
    97                         filter_stdout=filter_python_develop,
       
    98                         show_stdout=True)
       
    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]],
       
   101                         cwd=os.path.abspath(tmp_dir),
       
   102                         filter_stdout=filter_python_develop,
       
   103                         show_stdout=True)
       
   104 
       
   105         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS['FOURSUITE_XML'][res_source_key]],
       
   106                         cwd=os.path.abspath(tmp_dir),
       
   107                         filter_stdout=filter_python_develop,
       
   108                         show_stdout=True)
       
   109 
       
   110         
       
   111         if sys.version_info >= (2,6):
       
   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         
       
   136 
       
   137         #get pylucene
    98         #get pylucene
       
    99         logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key])
   138         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   100         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   139         urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
   101         urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
   140         tf = tarfile.open(pylucene_src,'r:gz')
   102         tf = tarfile.open(pylucene_src,'r:gz')
   141         pylucene_base_path = os.path.join(src_dir,"pylucene") 
   103         pylucene_base_path = os.path.join(src_dir,"pylucene") 
       
   104         logger.notify("Extract Pylucene to %s " % pylucene_base_path)
   142         tf.extractall(pylucene_base_path)
   105         tf.extractall(pylucene_base_path)
   143         tf.close()
   106         tf.close()
   144         
   107         
   145         pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0])
   108         pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0])
       
   109         jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc"))
   146         
   110         
   147         #install jcc
   111         #install jcc
       
   112 
       
   113         #patch for linux
       
   114         if system_str == 'Linux' :
       
   115             olddir = os.getcwd()
       
   116             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')
       
   117             logger.notify("Patch jcc : %s " % (patch_dest_path))
       
   118             os.chdir(patch_dest_path)
       
   119             p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11"))
       
   120             p.apply()
       
   121             os.chdir(olddir)
       
   122 
       
   123         logger.notify("Install jcc")
   148         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
   124         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'],
   149                         cwd=os.path.abspath(os.path.join(pylucene_src_path,"jcc")),
   125                         cwd=jcc_src_path,
   150                         filter_stdout=filter_python_develop,
   126                         filter_stdout=filter_python_develop,
   151                         show_stdout=True)
   127                         show_stdout=True)
   152         #install pylucene       
   128         #install pylucene
       
   129         
       
   130         logger.notify("Install pylucene")
   153         #modify makefile
   131         #modify makefile
   154         makefile_path = os.path.join(pylucene_src_path,"Makefile")
   132         makefile_path = os.path.join(pylucene_src_path,"Makefile")
       
   133         logger.notify("Modify makefile %s " % makefile_path)
   155         shutil.move( makefile_path, makefile_path+"~" )
   134         shutil.move( makefile_path, makefile_path+"~" )
   156 
   135 
   157         destination= open( makefile_path, "w" )
   136         destination= open( makefile_path, "w" )
   158         source= open( makefile_path+"~", "r" )
   137         source= open( makefile_path+"~", "r" )
   159         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   138         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   160         destination.write("ANT=ant\\n")
   139         destination.write("ANT=ant\\n")
   161         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
   140         destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n")
   162         system_str = platform.system()
   141         
   163         if system_str == "Darwin":
   142         if system_str == "Darwin":
   164             if sys.version_info >= (2,6):
   143             if sys.version_info >= (2,6):
   165                 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
   144                 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n")
   166             else:
   145             else:
   167                 destination.write("JCC=$(PYTHON) -m jcc --shared\\n")
   146                 destination.write("JCC=$(PYTHON) -m jcc --shared\\n")
   176             destination.write( line )
   155             destination.write( line )
   177         source.close()
   156         source.close()
   178         destination.close()
   157         destination.close()
   179         os.remove(makefile_path+"~" )
   158         os.remove(makefile_path+"~" )
   180 
   159 
       
   160         logger.notify("pylucene make")
   181         call_subprocess(['make'],
   161         call_subprocess(['make'],
   182                         cwd=os.path.abspath(pylucene_src_path),
   162                         cwd=os.path.abspath(pylucene_src_path),
   183                         filter_stdout=filter_python_develop,
   163                         filter_stdout=filter_python_develop,
   184                         show_stdout=True)
   164                         show_stdout=True)
   185 
   165 
       
   166         logger.notify("pylucene make install")
   186         call_subprocess(['make', 'install'],
   167         call_subprocess(['make', 'install'],
   187                         cwd=os.path.abspath(pylucene_src_path),
   168                         cwd=os.path.abspath(pylucene_src_path),
   188                         filter_stdout=filter_python_develop,
   169                         filter_stdout=filter_python_develop,
   189                         show_stdout=True)
   170                         show_stdout=True)
       
   171 
       
   172         logger.notify("PyXML install : %s " % URLS['PYXML'][res_source_key])
       
   173         if sys.version_info >= (2,6):
       
   174             logger.notify("PyXML -> python version >= 2.6 : patching")
       
   175             pyxml_src = os.path.join(src_dir,"pyxml.tar.gz")
       
   176             urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src)
       
   177             logger.notify("PyXML -> python version >= 2.6 : extract archive")
       
   178             tf = tarfile.open(pyxml_src,'r:gz')
       
   179             pyxml_base_path = os.path.join(src_dir,"pyxml") 
       
   180             tf.extractall(pyxml_base_path)
       
   181             tf.close()
       
   182 
       
   183             #patch
       
   184             pyxml_version = os.listdir(pyxml_base_path)[0]            
       
   185             pyxml_path = os.path.join(pyxml_base_path, pyxml_version)
       
   186             olddir = os.getcwd()
       
   187             os.chdir(pyxml_path)
       
   188             logger.notify("PyXML -> python version >= 2.6 : do patch %s : %s " % (pyxml_path, URLS['PYXML']['patch']))
       
   189             p = patch.fromfile(URLS['PYXML']['patch'])
       
   190             p.apply()
       
   191             os.chdir(olddir)
       
   192             logger.notify("PyXML -> python version >= 2.6 : install")
       
   193             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],
       
   194                     cwd=os.path.abspath(tmp_dir),
       
   195                     filter_stdout=filter_python_develop,
       
   196                     show_stdout=True)
       
   197         else:
       
   198             call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]],
       
   199                     cwd=os.path.abspath(tmp_dir),
       
   200                     filter_stdout=filter_python_develop,
       
   201                     show_stdout=True)
       
   202         
       
   203         logger.notify("Install Distribute from %s" % URLS['DISTRIBUTE'][res_source_key])
       
   204         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['DISTRIBUTE'][res_source_key]],
       
   205                         cwd=os.path.abspath(tmp_dir),
       
   206                         filter_stdout=filter_python_develop,
       
   207                         show_stdout=True)
       
   208                         
       
   209         logger.notify("Install Psycopg2 from %s" % URLS['PSYCOPG2'][res_source_key])
       
   210         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PSYCOPG2'][res_source_key]],
       
   211                         cwd=os.path.abspath(tmp_dir),
       
   212                         filter_stdout=filter_python_develop,
       
   213                         show_stdout=True)
       
   214 
       
   215         logger.notify("Install PIL from %s" % URLS['PIL'][res_source_key])
       
   216         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PIL'][res_source_key]],
       
   217                         cwd=os.path.abspath(tmp_dir),
       
   218                         filter_stdout=filter_python_develop,
       
   219                         show_stdout=True)
       
   220                         
       
   221         logger.notify("Install 4Suite-XML from %s" % URLS['FOURSUITE_XML'][res_source_key])
       
   222         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), URLS['FOURSUITE_XML'][res_source_key]],
       
   223                         cwd=os.path.abspath(tmp_dir),
       
   224                         filter_stdout=filter_python_develop,
       
   225                         show_stdout=True)
       
   226                         
       
   227         logger.notify("Clear source dir")
   190         shutil.rmtree(src_dir)
   228         shutil.rmtree(src_dir)
   191 
   229 
   192     finally:
   230     finally:
   193         logger.indent -= 2
   231         logger.indent -= 2
   194     script_dir = join(base_dir, 'bin')
   232     script_dir = join(base_dir, 'bin')
   195     logger.notify('Run "%s Package" to install new packages that provide builds'
   233     logger.notify('Run "%s Package" to install new packages that provide builds'
   196                   % join(script_dir, 'easy_install'))
   234                   % join(script_dir, 'easy_install'))
   197 
   235 
   198 def ensure_dir(dir):
   236 def ensure_dir(dir):
   199     if not os.path.exists(dir):
   237     if not os.path.exists(dir):
   200         logger.info('Creating directory %s' % dir)
   238         logger.notify('Creating directory %s' % dir)
   201         os.makedirs(dir)
   239         os.makedirs(dir)
   202 
   240 
   203 def filter_python_develop(line):
   241 def filter_python_develop(line):
   204     if not line.strip():
   242     if not line.strip():
   205         return Logger.DEBUG
   243         return Logger.DEBUG