sbin/create_python_env.py
changeset 46 5503cfcdea68
parent 45 6f0e728839d6
child 50 012451a812f1
child 51 1b99846565d5
equal deleted inserted replaced
45:6f0e728839d6 46:5503cfcdea68
    94     
    94     
    95     logger.indent += 2
    95     logger.indent += 2
    96     try:
    96     try:
    97         
    97         
    98         #get pylucene
    98         #get pylucene
    99         logger.info("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key])
    99         logger.notify("Get Pylucene from %s " % URLS['PYLUCENE'][res_source_key])
   100         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   100         pylucene_src = os.path.join(src_dir,"pylucene.tar.gz")
   101         urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
   101         urllib.urlretrieve(URLS['PYLUCENE'][res_source_key], pylucene_src)
   102         tf = tarfile.open(pylucene_src,'r:gz')
   102         tf = tarfile.open(pylucene_src,'r:gz')
   103         pylucene_base_path = os.path.join(src_dir,"pylucene") 
   103         pylucene_base_path = os.path.join(src_dir,"pylucene") 
   104         logger.info("Extract Pylucene to %s " % pylucene_base_path)
   104         logger.notify("Extract Pylucene to %s " % pylucene_base_path)
   105         tf.extractall(pylucene_base_path)
   105         tf.extractall(pylucene_base_path)
   106         tf.close()
   106         tf.close()
   107         
   107         
   108         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"))
   109         jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc"))
   112 
   112 
   113         #patch for linux
   113         #patch for linux
   114         if system_str == 'Linux' :
   114         if system_str == 'Linux' :
   115             olddir = os.getcwd()
   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')
   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.info("Patch jcc : %s " % (patch_dest_path))
   117             logger.notify("Patch jcc : %s " % (patch_dest_path))
   118             os.chdir(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"))
   119             p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11"))
   120             p.apply()
   120             p.apply()
   121             os.chdir(olddir)
   121             os.chdir(olddir)
   122 
   122 
   123         logger.info("Install jcc")
   123         logger.notify("Install jcc")
   124         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'],
   125                         cwd=jcc_src_path,
   125                         cwd=jcc_src_path,
   126                         filter_stdout=filter_python_develop,
   126                         filter_stdout=filter_python_develop,
   127                         show_stdout=True)
   127                         show_stdout=True)
   128         #install pylucene
   128         #install pylucene
   129         
   129         
   130         logger.info("Install pylucene")
   130         logger.notify("Install pylucene")
   131         #modify makefile
   131         #modify makefile
   132         makefile_path = os.path.join(pylucene_src_path,"Makefile")
   132         makefile_path = os.path.join(pylucene_src_path,"Makefile")
   133         logger.info("Modify makefile %s " % makefile_path)
   133         logger.notify("Modify makefile %s " % makefile_path)
   134         shutil.move( makefile_path, makefile_path+"~" )
   134         shutil.move( makefile_path, makefile_path+"~" )
   135 
   135 
   136         destination= open( makefile_path, "w" )
   136         destination= open( makefile_path, "w" )
   137         source= open( makefile_path+"~", "r" )
   137         source= open( makefile_path+"~", "r" )
   138         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   138         destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n")
   155             destination.write( line )
   155             destination.write( line )
   156         source.close()
   156         source.close()
   157         destination.close()
   157         destination.close()
   158         os.remove(makefile_path+"~" )
   158         os.remove(makefile_path+"~" )
   159 
   159 
       
   160         logger.notify("pylucene make")
   160         call_subprocess(['make'],
   161         call_subprocess(['make'],
   161                         cwd=os.path.abspath(pylucene_src_path),
   162                         cwd=os.path.abspath(pylucene_src_path),
   162                         filter_stdout=filter_python_develop,
   163                         filter_stdout=filter_python_develop,
   163                         show_stdout=True)
   164                         show_stdout=True)
   164 
   165 
       
   166         logger.notify("pylucene make install")
   165         call_subprocess(['make', 'install'],
   167         call_subprocess(['make', 'install'],
   166                         cwd=os.path.abspath(pylucene_src_path),
   168                         cwd=os.path.abspath(pylucene_src_path),
   167                         filter_stdout=filter_python_develop,
   169                         filter_stdout=filter_python_develop,
   168                         show_stdout=True)
   170                         show_stdout=True)
   169 
   171 
       
   172         logger.notify("PyXML install : %s " % URLS['PYXML'][res_source_key])
   170         if sys.version_info >= (2,6):
   173         if sys.version_info >= (2,6):
       
   174             logger.notify("PyXML -> python version >= 2.6 : patching")
   171             pyxml_src = os.path.join(src_dir,"pyxml.tar.gz")
   175             pyxml_src = os.path.join(src_dir,"pyxml.tar.gz")
   172             urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src)
   176             urllib.urlretrieve(URLS['PYXML'][res_source_key], pyxml_src)
       
   177             logger.notify("PyXML -> python version >= 2.6 : extract archive")
   173             tf = tarfile.open(pyxml_src,'r:gz')
   178             tf = tarfile.open(pyxml_src,'r:gz')
   174             pyxml_base_path = os.path.join(src_dir,"pyxml") 
   179             pyxml_base_path = os.path.join(src_dir,"pyxml") 
   175             tf.extractall(pyxml_base_path)
   180             tf.extractall(pyxml_base_path)
   176             tf.close()
   181             tf.close()
       
   182 
   177             #patch
   183             #patch
   178             pyxml_version = os.listdir(pyxml_base_path)[0]            
   184             pyxml_version = os.listdir(pyxml_base_path)[0]            
   179             pyxml_path = os.path.join(pyxml_base_path, pyxml_version)
   185             pyxml_path = os.path.join(pyxml_base_path, pyxml_version)
   180             olddir = os.getcwd()
   186             olddir = os.getcwd()
   181             os.chdir(pyxml_path)
   187             os.chdir(pyxml_path)
       
   188             logger.notify("PyXML -> python version >= 2.6 : do patch %s : %s " % (pyxml_path, URLS['PYXML']['patch']))
   182             p = patch.fromfile(URLS['PYXML']['patch'])
   189             p = patch.fromfile(URLS['PYXML']['patch'])
   183             p.apply()
   190             p.apply()
   184             os.chdir(olddir)
   191             os.chdir(olddir)
       
   192             logger.notify("PyXML -> python version >= 2.6 : install")
   185             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],
   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],
   186                     cwd=os.path.abspath(tmp_dir),
   194                     cwd=os.path.abspath(tmp_dir),
   187                     filter_stdout=filter_python_develop,
   195                     filter_stdout=filter_python_develop,
   188                     show_stdout=True)
   196                     show_stdout=True)
   189         else:
   197         else:
   190             call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PYXML'][res_source_key]],
   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]],
   191                     cwd=os.path.abspath(tmp_dir),
   199                     cwd=os.path.abspath(tmp_dir),
   192                     filter_stdout=filter_python_develop,
   200                     filter_stdout=filter_python_develop,
   193                     show_stdout=True)
   201                     show_stdout=True)
   194         
   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)
   195                         
   208                         
   196         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['DISTRIBUTE'][res_source_key]],
   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]],
   197                         cwd=os.path.abspath(tmp_dir),
   217                         cwd=os.path.abspath(tmp_dir),
   198                         filter_stdout=filter_python_develop,
   218                         filter_stdout=filter_python_develop,
   199                         show_stdout=True)
   219                         show_stdout=True)
   200                         
   220                         
   201         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PSYCOPG2'][res_source_key]],
   221         logger.notify("Install 4Suite-XML from %s" % URLS['FOURSUITE_XML'][res_source_key])
   202                         cwd=os.path.abspath(tmp_dir),
       
   203                         filter_stdout=filter_python_develop,
       
   204                         show_stdout=True)
       
   205 
       
   206         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), URLS['PIL'][res_source_key]],
       
   207                         cwd=os.path.abspath(tmp_dir),
       
   208                         filter_stdout=filter_python_develop,
       
   209                         show_stdout=True)
       
   210 
       
   211         call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), 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]],
   212                         cwd=os.path.abspath(tmp_dir),
   223                         cwd=os.path.abspath(tmp_dir),
   213                         filter_stdout=filter_python_develop,
   224                         filter_stdout=filter_python_develop,
   214                         show_stdout=True)
   225                         show_stdout=True)
   215                         
   226                         
       
   227         logger.notify("Clear source dir")
   216         shutil.rmtree(src_dir)
   228         shutil.rmtree(src_dir)
   217 
   229 
   218     finally:
   230     finally:
   219         logger.indent -= 2
   231         logger.indent -= 2
   220     script_dir = join(base_dir, 'bin')
   232     script_dir = join(base_dir, 'bin')
   221     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'
   222                   % join(script_dir, 'easy_install'))
   234                   % join(script_dir, 'easy_install'))
   223 
   235 
   224 def ensure_dir(dir):
   236 def ensure_dir(dir):
   225     if not os.path.exists(dir):
   237     if not os.path.exists(dir):
   226         logger.info('Creating directory %s' % dir)
   238         logger.notify('Creating directory %s' % dir)
   227         os.makedirs(dir)
   239         os.makedirs(dir)
   228 
   240 
   229 def filter_python_develop(line):
   241 def filter_python_develop(line):
   230     if not line.strip():
   242     if not line.strip():
   231         return Logger.DEBUG
   243         return Logger.DEBUG