<s> from __future__ import print_function <EOL> import os <EOL> import sys <EOL> import errno <EOL> from subprocess import call <EOL> from glob import glob <EOL> from os . path import dirname , basename , abspath , isdir , join <EOL> from shutil import rmtree <EOL> DEPS = dirname ( abspath ( __file__ ) ) <EOL> PYTHON = sys . executable <EOL> def build ( extension ) : <EOL> """<STR_LIT>""" <EOL> result = call ( [ PYTHON , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , cwd = join ( DEPS , extension ) ) <EOL> if result > <NUM_LIT:0> : <EOL> raise OSError ( "<STR_LIT>" % extension ) <EOL> def make ( target , ** envvars ) : <EOL> """<STR_LIT>""" <EOL> os . chdir ( '<STR_LIT>' % DEPS ) <EOL> env = { "<STR_LIT>" : PYTHON , "<STR_LIT>" : os . environ [ '<STR_LIT>' ] } <EOL> env . update ( envvars ) <EOL> result = call ( '<STR_LIT>' % target , env = env , shell = True ) <EOL> if result > <NUM_LIT:0> : <EOL> raise OSError ( "<STR_LIT>" % target ) <EOL> os . chdir ( DEPS ) <EOL> def clean ( ) : <EOL> """<STR_LIT>""" <EOL> build_dirs = glob ( '<STR_LIT>' % DEPS ) <EOL> for build_dir in build_dirs : <EOL> lib_name = dirname ( build_dir ) <EOL> print ( "<STR_LIT>" , lib_name ) <EOL> call ( '<STR_LIT>' % build_dir ) <EOL> make ( '<STR_LIT>' ) <EOL> def build_extensions ( ) : <EOL> print ( "<STR_LIT>" ) <EOL> for setup_script in glob ( '<STR_LIT>' % DEPS ) : <EOL> lib_name = basename ( dirname ( setup_script ) ) <EOL> print ( "<STR_LIT>" % lib_name ) <EOL> build ( lib_name ) <EOL> print ( "<STR_LIT>" ) <EOL> make ( '<STR_LIT>' ) <EOL> def install_http_libs ( mod_root ) : <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> make ( '<STR_LIT:http>' , DSTROOT = mod_root ) <EOL> def install_extensions ( ext_root ) : <EOL> """<STR_LIT>""" <EOL> if not isdir ( ext_root ) : <EOL> os . makedirs ( ext_root ) <EOL> for extension in glob ( "<STR_LIT>" % DEPS ) : <EOL> cmd = '<STR_LIT>' % ( extension , ext_root ) <EOL> result = call ( cmd , shell = True ) <EOL> if result > <NUM_LIT:0> : <EOL> lib_name = dirname ( dirname ( extension ) ) <EOL> raise OSError ( "<STR_LIT>" % lib_name ) <EOL> print ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> arg = sys . argv [ <NUM_LIT:1> ] <EOL> if arg == '<STR_LIT>' : <EOL> print ( "<STR_LIT>" ) <EOL> clean ( ) <EOL> else : <EOL> mod_root = arg <EOL> ext_root = join ( mod_root , '<STR_LIT>' ) <EOL> build_extensions ( ) <EOL> if '<STR_LIT>' in os . environ : <EOL> install_http_libs ( mod_root ) <EOL> install_extensions ( ext_root ) <EOL> else : <EOL> print ( "<STR_LIT>" ) </s>
