<s> """<STR_LIT>""" <EOL> virtualenv_version = "<STR_LIT>" <EOL> import base64 <EOL> import sys <EOL> import os <EOL> import optparse <EOL> import re <EOL> import shutil <EOL> import logging <EOL> import tempfile <EOL> import zlib <EOL> import errno <EOL> import distutils . sysconfig <EOL> from distutils . util import strtobool <EOL> try : <EOL> import subprocess <EOL> except ImportError : <EOL> if sys . version_info <= ( <NUM_LIT:2> , <NUM_LIT:3> ) : <EOL> print ( '<STR_LIT>' % sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT> ) <EOL> else : <EOL> raise <EOL> try : <EOL> set <EOL> except NameError : <EOL> from sets import Set as set <EOL> try : <EOL> basestring <EOL> except NameError : <EOL> basestring = str <EOL> try : <EOL> import ConfigParser <EOL> except ImportError : <EOL> import configparser as ConfigParser <EOL> join = os . path . join <EOL> py_version = '<STR_LIT>' % ( sys . version_info [ <NUM_LIT:0> ] , sys . version_info [ <NUM_LIT:1> ] ) <EOL> is_jython = sys . platform . startswith ( '<STR_LIT>' ) <EOL> is_pypy = hasattr ( sys , '<STR_LIT>' ) <EOL> is_win = ( sys . platform == '<STR_LIT:win32>' ) <EOL> abiflags = getattr ( sys , '<STR_LIT>' , '<STR_LIT>' ) <EOL> user_dir = os . path . expanduser ( '<STR_LIT>' ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> user_dir = os . environ . get ( '<STR_LIT>' , user_dir ) <EOL> default_storage_dir = os . path . join ( user_dir , '<STR_LIT>' ) <EOL> else : <EOL> default_storage_dir = os . path . join ( user_dir , '<STR_LIT>' ) <EOL> default_config_file = os . path . join ( default_storage_dir , '<STR_LIT>' ) <EOL> if is_pypy : <EOL> expected_exe = '<STR_LIT>' <EOL> elif is_jython : <EOL> expected_exe = '<STR_LIT>' <EOL> else : <EOL> expected_exe = '<STR_LIT>' <EOL> REQUIRED_MODULES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> REQUIRED_FILES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> majver , minver = sys . version_info [ : <NUM_LIT:2> ] <EOL> if majver == <NUM_LIT:2> : <EOL> if minver >= <NUM_LIT:6> : <EOL> REQUIRED_MODULES . extend ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:abc>' ] ) <EOL> if minver >= <NUM_LIT:7> : <EOL> REQUIRED_MODULES . extend ( [ '<STR_LIT>' ] ) <EOL> if minver <= <NUM_LIT:3> : <EOL> REQUIRED_MODULES . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> elif majver == <NUM_LIT:3> : <EOL> REQUIRED_MODULES . extend ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:abc>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if minver >= <NUM_LIT:2> : <EOL> REQUIRED_FILES [ - <NUM_LIT:1> ] = '<STR_LIT>' % majver <EOL> if minver == <NUM_LIT:3> : <EOL> REQUIRED_MODULES . extend ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> if is_pypy : <EOL> REQUIRED_MODULES . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class Logger ( object ) : <EOL> """<STR_LIT>""" <EOL> DEBUG = logging . DEBUG <EOL> INFO = logging . INFO <EOL> NOTIFY = ( logging . INFO + logging . WARN ) / <NUM_LIT:2> <EOL> WARN = WARNING = logging . WARN <EOL> ERROR = logging . ERROR <EOL> FATAL = logging . FATAL <EOL> LEVELS = [ DEBUG , INFO , NOTIFY , WARN , ERROR , FATAL ] <EOL> def __init__ ( self , consumers ) : <EOL> self . consumers = consumers <EOL> self . indent = <NUM_LIT:0> <EOL> self . in_progress = None <EOL> self . in_progress_hanging = False <EOL> def debug ( self , msg , * args , ** kw ) : <EOL> self . log ( self . DEBUG , msg , * args , ** kw ) <EOL> def info ( self , msg , * args , ** kw ) : <EOL> self . log ( self . INFO , msg , * args , ** kw ) <EOL> def notify ( self , msg , * args , ** kw ) : <EOL> self . log ( self . NOTIFY , msg , * args , ** kw ) <EOL> def warn ( self , msg , * args , ** kw ) : <EOL> self . log ( self . WARN , msg , * args , ** kw ) <EOL> def error ( self , msg , * args , ** kw ) : <EOL> self . log ( self . WARN , msg , * args , ** kw ) <EOL> def fatal ( self , msg , * args , ** kw ) : <EOL> self . log ( self . FATAL , msg , * args , ** kw ) <EOL> def log ( self , level , msg , * args , ** kw ) : <EOL> if args : <EOL> if kw : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> args = args or kw <EOL> rendered = None <EOL> for consumer_level , consumer in self . consumers : <EOL> if self . level_matches ( level , consumer_level ) : <EOL> if ( self . in_progress_hanging <EOL> and consumer in ( sys . stdout , sys . stderr ) ) : <EOL> self . in_progress_hanging = False <EOL> sys . stdout . write ( '<STR_LIT:\n>' ) <EOL> sys . stdout . flush ( ) <EOL> if rendered is None : <EOL> if args : <EOL> rendered = msg % args <EOL> else : <EOL> rendered = msg <EOL> rendered = '<STR_LIT:U+0020>' * self . indent + rendered <EOL> if hasattr ( consumer , '<STR_LIT>' ) : <EOL> consumer . write ( rendered + '<STR_LIT:\n>' ) <EOL> else : <EOL> consumer ( rendered ) <EOL> def start_progress ( self , msg ) : <EOL> assert not self . in_progress , ( <EOL> "<STR_LIT>" <EOL> % ( msg , self . in_progress ) ) <EOL> if self . level_matches ( self . NOTIFY , self . _stdout_level ( ) ) : <EOL> sys . stdout . write ( msg ) <EOL> sys . stdout . flush ( ) <EOL> self . in_progress_hanging = True <EOL> else : <EOL> self . in_progress_hanging = False <EOL> self . in_progress = msg <EOL> def end_progress ( self , msg = '<STR_LIT>' ) : <EOL> assert self . in_progress , ( <EOL> "<STR_LIT>" ) <EOL> if self . stdout_level_matches ( self . NOTIFY ) : <EOL> if not self . in_progress_hanging : <EOL> sys . stdout . write ( '<STR_LIT>' + self . in_progress + msg + '<STR_LIT:\n>' ) <EOL> sys . stdout . flush ( ) <EOL> else : <EOL> sys . stdout . write ( msg + '<STR_LIT:\n>' ) <EOL> sys . stdout . flush ( ) <EOL> self . in_progress = None <EOL> self . in_progress_hanging = False <EOL> def show_progress ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . in_progress_hanging : <EOL> sys . stdout . write ( '<STR_LIT:.>' ) <EOL> sys . stdout . flush ( ) <EOL> def stdout_level_matches ( self , level ) : <EOL> """<STR_LIT>""" <EOL> return self . level_matches ( level , self . _stdout_level ( ) ) <EOL> def _stdout_level ( self ) : <EOL> """<STR_LIT>""" <EOL> for level , consumer in self . consumers : <EOL> if consumer is sys . stdout : <EOL> return level <EOL> return self . FATAL <EOL> def level_matches ( self , level , consumer_level ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( level , slice ) : <EOL> start , stop = level . start , level . stop <EOL> if start is not None and start > consumer_level : <EOL> return False <EOL> if stop is not None and stop <= consumer_level : <EOL> return False <EOL> return True <EOL> else : <EOL> return level >= consumer_level <EOL> def level_for_integer ( cls , level ) : <EOL> levels = cls . LEVELS <EOL> if level < <NUM_LIT:0> : <EOL> return levels [ <NUM_LIT:0> ] <EOL> if level >= len ( levels ) : <EOL> return levels [ - <NUM_LIT:1> ] <EOL> return levels [ level ] <EOL> level_for_integer = classmethod ( level_for_integer ) <EOL> logger = Logger ( [ ( Logger . LEVELS [ - <NUM_LIT:1> ] , sys . stdout ) ] ) <EOL> def mkdir ( path ) : <EOL> if not os . path . exists ( path ) : <EOL> logger . info ( '<STR_LIT>' , path ) <EOL> os . makedirs ( path ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' , path ) <EOL> def copyfileordir ( src , dest ) : <EOL> if os . path . isdir ( src ) : <EOL> shutil . copytree ( src , dest , True ) <EOL> else : <EOL> shutil . copy2 ( src , dest ) <EOL> def copyfile ( src , dest , symlink = True ) : <EOL> if not os . path . exists ( src ) : <EOL> logger . warn ( '<STR_LIT>' , src ) <EOL> return <EOL> if os . path . exists ( dest ) : <EOL> logger . debug ( '<STR_LIT>' , dest ) <EOL> return <EOL> if not os . path . exists ( os . path . dirname ( dest ) ) : <EOL> logger . info ( '<STR_LIT>' % os . path . dirname ( dest ) ) <EOL> os . makedirs ( os . path . dirname ( dest ) ) <EOL> if not os . path . islink ( src ) : <EOL> srcpath = os . path . abspath ( src ) <EOL> else : <EOL> srcpath = os . readlink ( src ) <EOL> if symlink and hasattr ( os , '<STR_LIT>' ) : <EOL> logger . info ( '<STR_LIT>' , dest ) <EOL> try : <EOL> os . symlink ( srcpath , dest ) <EOL> except ( OSError , NotImplementedError ) : <EOL> logger . info ( '<STR_LIT>' , dest ) <EOL> copyfileordir ( src , dest ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' , dest ) <EOL> copyfileordir ( src , dest ) <EOL> def writefile ( dest , content , overwrite = True ) : <EOL> if not os . path . exists ( dest ) : <EOL> logger . info ( '<STR_LIT>' , dest ) <EOL> f = open ( dest , '<STR_LIT:wb>' ) <EOL> f . write ( content . encode ( '<STR_LIT:utf-8>' ) ) <EOL> f . close ( ) <EOL> return <EOL> else : <EOL> f = open ( dest , '<STR_LIT:rb>' ) <EOL> c = f . read ( ) <EOL> f . close ( ) <EOL> if c != content : <EOL> if not overwrite : <EOL> logger . notify ( '<STR_LIT>' , dest ) <EOL> return <EOL> logger . notify ( '<STR_LIT>' , dest ) <EOL> f = open ( dest , '<STR_LIT:wb>' ) <EOL> f . write ( content . encode ( '<STR_LIT:utf-8>' ) ) <EOL> f . close ( ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' , dest ) <EOL> def rmtree ( dir ) : <EOL> if os . path . exists ( dir ) : <EOL> logger . notify ( '<STR_LIT>' , dir ) <EOL> shutil . rmtree ( dir ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' , dir ) <EOL> def make_exe ( fn ) : <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> oldmode = os . stat ( fn ) . st_mode & <NUM_LIT> <EOL> newmode = ( oldmode | <NUM_LIT> ) & <NUM_LIT> <EOL> os . chmod ( fn , newmode ) <EOL> logger . info ( '<STR_LIT>' , fn , oct ( newmode ) ) <EOL> def _find_file ( filename , dirs ) : <EOL> for dir in dirs : <EOL> if os . path . exists ( join ( dir , filename ) ) : <EOL> return join ( dir , filename ) <EOL> return filename <EOL> def _install_req ( py_executable , unzip = False , distribute = False , <EOL> search_dirs = None , never_download = False ) : <EOL> if search_dirs is None : <EOL> search_dirs = file_search_dirs ( ) <EOL> if not distribute : <EOL> setup_fn = '<STR_LIT>' % sys . version [ : <NUM_LIT:3> ] <EOL> project_name = '<STR_LIT>' <EOL> bootstrap_script = EZ_SETUP_PY <EOL> source = None <EOL> else : <EOL> setup_fn = None <EOL> source = '<STR_LIT>' <EOL> project_name = '<STR_LIT>' <EOL> bootstrap_script = DISTRIBUTE_SETUP_PY <EOL> if setup_fn is not None : <EOL> setup_fn = _find_file ( setup_fn , search_dirs ) <EOL> if source is not None : <EOL> source = _find_file ( source , search_dirs ) <EOL> if is_jython and os . _name == '<STR_LIT>' : <EOL> fd , ez_setup = tempfile . mkstemp ( '<STR_LIT>' ) <EOL> os . write ( fd , bootstrap_script ) <EOL> os . close ( fd ) <EOL> cmd = [ py_executable , ez_setup ] <EOL> else : <EOL> cmd = [ py_executable , '<STR_LIT:-c>' , bootstrap_script ] <EOL> if unzip : <EOL> cmd . append ( '<STR_LIT>' ) <EOL> env = { } <EOL> remove_from_env = [ ] <EOL> if logger . stdout_level_matches ( logger . DEBUG ) : <EOL> cmd . append ( '<STR_LIT>' ) <EOL> old_chdir = os . getcwd ( ) <EOL> if setup_fn is not None and os . path . exists ( setup_fn ) : <EOL> logger . info ( '<STR_LIT>' % ( project_name , setup_fn ) ) <EOL> cmd . append ( setup_fn ) <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> env [ '<STR_LIT>' ] = setup_fn + os . path . pathsep + os . environ [ '<STR_LIT>' ] <EOL> else : <EOL> env [ '<STR_LIT>' ] = setup_fn <EOL> else : <EOL> if source is not None and os . path . exists ( source ) : <EOL> logger . info ( '<STR_LIT>' % ( project_name , source ) ) <EOL> os . chdir ( os . path . dirname ( source ) ) <EOL> remove_from_env . append ( '<STR_LIT>' ) <EOL> else : <EOL> if never_download : <EOL> logger . fatal ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( project_name , project_name , <EOL> setup_fn or source , <EOL> search_dirs ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> logger . info ( '<STR_LIT>' % project_name ) <EOL> cmd . extend ( [ '<STR_LIT>' , '<STR_LIT>' , project_name ] ) <EOL> logger . start_progress ( '<STR_LIT>' % project_name ) <EOL> logger . indent += <NUM_LIT:2> <EOL> cwd = None <EOL> if project_name == '<STR_LIT>' : <EOL> env [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> def _filter_ez_setup ( line ) : <EOL> return filter_ez_setup ( line , project_name ) <EOL> if not os . access ( os . getcwd ( ) , os . W_OK ) : <EOL> cwd = tempfile . mkdtemp ( ) <EOL> if source is not None and os . path . exists ( source ) : <EOL> target = os . path . join ( cwd , os . path . split ( source ) [ - <NUM_LIT:1> ] ) <EOL> shutil . copy ( source , target ) <EOL> try : <EOL> call_subprocess ( cmd , show_stdout = False , <EOL> filter_stdout = _filter_ez_setup , <EOL> extra_env = env , <EOL> remove_from_env = remove_from_env , <EOL> cwd = cwd ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> logger . end_progress ( ) <EOL> if os . getcwd ( ) != old_chdir : <EOL> os . chdir ( old_chdir ) <EOL> if is_jython and os . _name == '<STR_LIT>' : <EOL> os . remove ( ez_setup ) <EOL> def file_search_dirs ( ) : <EOL> here = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> dirs = [ '<STR_LIT:.>' , here , <EOL> join ( here , '<STR_LIT>' ) ] <EOL> if os . path . splitext ( os . path . dirname ( __file__ ) ) [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> try : <EOL> import virtualenv <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> dirs . append ( os . path . join ( os . path . dirname ( virtualenv . __file__ ) , '<STR_LIT>' ) ) <EOL> return [ d for d in dirs if os . path . isdir ( d ) ] <EOL> def install_setuptools ( py_executable , unzip = False , <EOL> search_dirs = None , never_download = False ) : <EOL> _install_req ( py_executable , unzip , <EOL> search_dirs = search_dirs , never_download = never_download ) <EOL> def install_distribute ( py_executable , unzip = False , <EOL> search_dirs = None , never_download = False ) : <EOL> _install_req ( py_executable , unzip , distribute = True , <EOL> search_dirs = search_dirs , never_download = never_download ) <EOL> _pip_re = re . compile ( r'<STR_LIT>' , re . I ) <EOL> def install_pip ( py_executable , search_dirs = None , never_download = False ) : <EOL> if search_dirs is None : <EOL> search_dirs = file_search_dirs ( ) <EOL> filenames = [ ] <EOL> for dir in search_dirs : <EOL> filenames . extend ( [ join ( dir , fn ) for fn in os . listdir ( dir ) <EOL> if _pip_re . search ( fn ) ] ) <EOL> filenames = [ ( os . path . basename ( filename ) . lower ( ) , i , filename ) for i , filename in enumerate ( filenames ) ] <EOL> filenames . sort ( ) <EOL> filenames = [ filename for basename , i , filename in filenames ] <EOL> if not filenames : <EOL> filename = '<STR_LIT>' <EOL> else : <EOL> filename = filenames [ - <NUM_LIT:1> ] <EOL> easy_install_script = '<STR_LIT>' <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> easy_install_script = '<STR_LIT>' <EOL> cmd = [ join ( os . path . dirname ( py_executable ) , easy_install_script ) , filename ] <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> cmd . insert ( <NUM_LIT:0> , py_executable ) <EOL> if filename == '<STR_LIT>' : <EOL> if never_download : <EOL> logger . fatal ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % search_dirs ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' % ( <EOL> os . path . basename ( filename ) , filename ) ) <EOL> logger . start_progress ( '<STR_LIT>' ) <EOL> logger . indent += <NUM_LIT:2> <EOL> def _filter_setup ( line ) : <EOL> return filter_ez_setup ( line , '<STR_LIT>' ) <EOL> try : <EOL> call_subprocess ( cmd , show_stdout = False , <EOL> filter_stdout = _filter_setup ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> logger . end_progress ( ) <EOL> def filter_ez_setup ( line , project_name = '<STR_LIT>' ) : <EOL> if not line . strip ( ) : <EOL> return Logger . DEBUG <EOL> if project_name == '<STR_LIT>' : <EOL> for prefix in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> if line . startswith ( prefix ) : <EOL> return Logger . DEBUG <EOL> return Logger . DEBUG <EOL> for prefix in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if line . startswith ( prefix ) : <EOL> return Logger . DEBUG <EOL> return Logger . INFO <EOL> class UpdatingDefaultsHelpFormatter ( optparse . IndentedHelpFormatter ) : <EOL> """<STR_LIT>""" <EOL> def expand_default ( self , option ) : <EOL> if self . parser is not None : <EOL> self . parser . update_defaults ( self . parser . defaults ) <EOL> return optparse . IndentedHelpFormatter . expand_default ( self , option ) <EOL> class ConfigOptionParser ( optparse . OptionParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . config = ConfigParser . RawConfigParser ( ) <EOL> self . files = self . get_config_files ( ) <EOL> self . config . read ( self . files ) <EOL> optparse . OptionParser . __init__ ( self , * args , ** kwargs ) <EOL> def get_config_files ( self ) : <EOL> config_file = os . environ . get ( '<STR_LIT>' , False ) <EOL> if config_file and os . path . exists ( config_file ) : <EOL> return [ config_file ] <EOL> return [ default_config_file ] <EOL> def update_defaults ( self , defaults ) : <EOL> """<STR_LIT>""" <EOL> config = { } <EOL> config . update ( dict ( self . get_config_section ( '<STR_LIT>' ) ) ) <EOL> config . update ( dict ( self . get_environ_vars ( ) ) ) <EOL> for key , val in config . items ( ) : <EOL> key = key . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if not key . startswith ( '<STR_LIT>' ) : <EOL> key = '<STR_LIT>' % key <EOL> option = self . get_option ( key ) <EOL> if option is not None : <EOL> if not val : <EOL> continue <EOL> if option . action == '<STR_LIT>' : <EOL> val = val . split ( ) <EOL> else : <EOL> option . nargs = <NUM_LIT:1> <EOL> if option . action in ( '<STR_LIT:store_true>' , '<STR_LIT>' , '<STR_LIT:count>' ) : <EOL> val = strtobool ( val ) <EOL> try : <EOL> val = option . convert_value ( key , val ) <EOL> except optparse . OptionValueError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> print ( "<STR_LIT>" % e ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> defaults [ option . dest ] = val <EOL> return defaults <EOL> def get_config_section ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if self . config . has_section ( name ) : <EOL> return self . config . items ( name ) <EOL> return [ ] <EOL> def get_environ_vars ( self , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> for key , val in os . environ . items ( ) : <EOL> if key . startswith ( prefix ) : <EOL> yield ( key . replace ( prefix , '<STR_LIT>' ) . lower ( ) , val ) <EOL> def get_default_values ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . process_default_values : <EOL> return optparse . Values ( self . defaults ) <EOL> defaults = self . update_defaults ( self . defaults . copy ( ) ) <EOL> for option in self . _get_all_options ( ) : <EOL> default = defaults . get ( option . dest ) <EOL> if isinstance ( default , basestring ) : <EOL> opt_str = option . get_opt_string ( ) <EOL> defaults [ option . dest ] = option . check_value ( opt_str , default ) <EOL> return optparse . Values ( defaults ) <EOL> def main ( ) : <EOL> parser = ConfigOptionParser ( <EOL> version = virtualenv_version , <EOL> usage = "<STR_LIT>" , <EOL> formatter = UpdatingDefaultsHelpFormatter ( ) ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:count>' , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:0> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:count>' , <EOL> dest = '<STR_LIT>' , <EOL> default = <NUM_LIT:0> , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % sys . executable ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> default_search_dirs = file_search_dirs ( ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> default = default_search_dirs , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> if '<STR_LIT>' in globals ( ) : <EOL> extend_parser ( parser ) <EOL> options , args = parser . parse_args ( ) <EOL> global logger <EOL> if '<STR_LIT>' in globals ( ) : <EOL> adjust_options ( options , args ) <EOL> verbosity = options . verbose - options . quiet <EOL> logger = Logger ( [ ( Logger . level_for_integer ( <NUM_LIT:2> - verbosity ) , sys . stdout ) ] ) <EOL> if options . python and not os . environ . get ( '<STR_LIT>' ) : <EOL> env = os . environ . copy ( ) <EOL> interpreter = resolve_interpreter ( options . python ) <EOL> if interpreter == sys . executable : <EOL> logger . warn ( '<STR_LIT>' % interpreter ) <EOL> else : <EOL> logger . notify ( '<STR_LIT>' % interpreter ) <EOL> env [ '<STR_LIT>' ] = '<STR_LIT:true>' <EOL> file = __file__ <EOL> if file . endswith ( '<STR_LIT>' ) : <EOL> file = file [ : - <NUM_LIT:1> ] <EOL> popen = subprocess . Popen ( [ interpreter , file ] + sys . argv [ <NUM_LIT:1> : ] , env = env ) <EOL> raise SystemExit ( popen . wait ( ) ) <EOL> if majver > <NUM_LIT:2> : <EOL> options . use_distribute = True <EOL> if os . environ . get ( '<STR_LIT>' ) and not options . use_distribute : <EOL> print ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> if not args : <EOL> print ( '<STR_LIT>' ) <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> print ( '<STR_LIT>' % ( <EOL> '<STR_LIT:U+0020>' . join ( args ) ) ) <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> home_dir = args [ <NUM_LIT:0> ] <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> logger . fatal ( '<STR_LIT>' ) <EOL> logger . fatal ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> if '<STR_LIT>' in os . environ : <EOL> logger . warn ( '<STR_LIT>' ) <EOL> del os . environ [ '<STR_LIT>' ] <EOL> if options . relocatable : <EOL> make_environment_relocatable ( home_dir ) <EOL> return <EOL> if options . no_site_packages : <EOL> logger . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> create_environment ( home_dir , <EOL> site_packages = options . system_site_packages , <EOL> clear = options . clear , <EOL> unzip_setuptools = options . unzip_setuptools , <EOL> use_distribute = options . use_distribute , <EOL> prompt = options . prompt , <EOL> search_dirs = options . search_dirs , <EOL> never_download = options . never_download ) <EOL> if '<STR_LIT>' in globals ( ) : <EOL> after_install ( options , home_dir ) <EOL> def call_subprocess ( cmd , show_stdout = True , <EOL> filter_stdout = None , cwd = None , <EOL> raise_on_returncode = True , extra_env = None , <EOL> remove_from_env = None ) : <EOL> cmd_parts = [ ] <EOL> for part in cmd : <EOL> if len ( part ) > <NUM_LIT> : <EOL> part = part [ : <NUM_LIT:20> ] + "<STR_LIT>" + part [ - <NUM_LIT:20> : ] <EOL> if '<STR_LIT:U+0020>' in part or '<STR_LIT:\n>' in part or '<STR_LIT:">' in part or "<STR_LIT:'>" in part : <EOL> part = '<STR_LIT>' % part . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> if hasattr ( part , '<STR_LIT>' ) : <EOL> try : <EOL> part = part . decode ( sys . getdefaultencoding ( ) ) <EOL> except UnicodeDecodeError : <EOL> part = part . decode ( sys . getfilesystemencoding ( ) ) <EOL> cmd_parts . append ( part ) <EOL> cmd_desc = '<STR_LIT:U+0020>' . join ( cmd_parts ) <EOL> if show_stdout : <EOL> stdout = None <EOL> else : <EOL> stdout = subprocess . PIPE <EOL> logger . debug ( "<STR_LIT>" % cmd_desc ) <EOL> if extra_env or remove_from_env : <EOL> env = os . environ . copy ( ) <EOL> if extra_env : <EOL> env . update ( extra_env ) <EOL> if remove_from_env : <EOL> for varname in remove_from_env : <EOL> env . pop ( varname , None ) <EOL> else : <EOL> env = None <EOL> try : <EOL> proc = subprocess . Popen ( <EOL> cmd , stderr = subprocess . STDOUT , stdin = None , stdout = stdout , <EOL> cwd = cwd , env = env ) <EOL> except Exception : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> logger . fatal ( <EOL> "<STR_LIT>" % ( e , cmd_desc ) ) <EOL> raise <EOL> all_output = [ ] <EOL> if stdout is not None : <EOL> stdout = proc . stdout <EOL> encoding = sys . getdefaultencoding ( ) <EOL> fs_encoding = sys . getfilesystemencoding ( ) <EOL> while <NUM_LIT:1> : <EOL> line = stdout . readline ( ) <EOL> try : <EOL> line = line . decode ( encoding ) <EOL> except UnicodeDecodeError : <EOL> line = line . decode ( fs_encoding ) <EOL> if not line : <EOL> break <EOL> line = line . rstrip ( ) <EOL> all_output . append ( line ) <EOL> if filter_stdout : <EOL> level = filter_stdout ( line ) <EOL> if isinstance ( level , tuple ) : <EOL> level , line = level <EOL> logger . log ( level , line ) <EOL> if not logger . stdout_level_matches ( level ) : <EOL> logger . show_progress ( ) <EOL> else : <EOL> logger . info ( line ) <EOL> else : <EOL> proc . communicate ( ) <EOL> proc . wait ( ) <EOL> if proc . returncode : <EOL> if raise_on_returncode : <EOL> if all_output : <EOL> logger . notify ( '<STR_LIT>' % cmd_desc ) <EOL> logger . notify ( '<STR_LIT:\n>' . join ( all_output ) + '<STR_LIT>' ) <EOL> raise OSError ( <EOL> "<STR_LIT>" <EOL> % ( cmd_desc , proc . returncode ) ) <EOL> else : <EOL> logger . warn ( <EOL> "<STR_LIT>" <EOL> % ( cmd_desc , proc . returncode ) ) <EOL> def create_environment ( home_dir , site_packages = False , clear = False , <EOL> unzip_setuptools = False , use_distribute = False , <EOL> prompt = None , search_dirs = None , never_download = False ) : <EOL> """<STR_LIT>""" <EOL> home_dir , lib_dir , inc_dir , bin_dir = path_locations ( home_dir ) <EOL> py_executable = os . path . abspath ( install_python ( <EOL> home_dir , lib_dir , inc_dir , bin_dir , <EOL> site_packages = site_packages , clear = clear ) ) <EOL> install_distutils ( home_dir ) <EOL> if use_distribute or os . environ . get ( '<STR_LIT>' ) : <EOL> install_distribute ( py_executable , unzip = unzip_setuptools , <EOL> search_dirs = search_dirs , never_download = never_download ) <EOL> else : <EOL> install_setuptools ( py_executable , unzip = unzip_setuptools , <EOL> search_dirs = search_dirs , never_download = never_download ) <EOL> install_pip ( py_executable , search_dirs = search_dirs , never_download = never_download ) <EOL> install_activate ( home_dir , bin_dir , prompt ) <EOL> def path_locations ( home_dir ) : <EOL> """<STR_LIT>""" <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> mkdir ( home_dir ) <EOL> if '<STR_LIT:U+0020>' in home_dir : <EOL> try : <EOL> import win32api <EOL> except ImportError : <EOL> print ( '<STR_LIT>' % home_dir ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> home_dir = win32api . GetShortPathName ( home_dir ) <EOL> lib_dir = join ( home_dir , '<STR_LIT>' ) <EOL> inc_dir = join ( home_dir , '<STR_LIT>' ) <EOL> bin_dir = join ( home_dir , '<STR_LIT>' ) <EOL> elif is_jython : <EOL> lib_dir = join ( home_dir , '<STR_LIT>' ) <EOL> inc_dir = join ( home_dir , '<STR_LIT>' ) <EOL> bin_dir = join ( home_dir , '<STR_LIT>' ) <EOL> elif is_pypy : <EOL> lib_dir = home_dir <EOL> inc_dir = join ( home_dir , '<STR_LIT>' ) <EOL> bin_dir = join ( home_dir , '<STR_LIT>' ) <EOL> else : <EOL> lib_dir = join ( home_dir , '<STR_LIT>' , py_version ) <EOL> inc_dir = join ( home_dir , '<STR_LIT>' , py_version + abiflags ) <EOL> bin_dir = join ( home_dir , '<STR_LIT>' ) <EOL> return home_dir , lib_dir , inc_dir , bin_dir <EOL> def change_prefix ( filename , dst_prefix ) : <EOL> prefixes = [ sys . prefix ] <EOL> if sys . platform == "<STR_LIT>" : <EOL> prefixes . extend ( ( <EOL> os . path . join ( "<STR_LIT>" , sys . version [ : <NUM_LIT:3> ] , "<STR_LIT>" ) , <EOL> os . path . join ( sys . prefix , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> os . path . join ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , sys . version [ : <NUM_LIT:3> ] , "<STR_LIT>" ) ) ) <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> prefixes . append ( sys . real_prefix ) <EOL> prefixes = list ( map ( os . path . abspath , prefixes ) ) <EOL> filename = os . path . abspath ( filename ) <EOL> for src_prefix in prefixes : <EOL> if filename . startswith ( src_prefix ) : <EOL> _ , relpath = filename . split ( src_prefix , <NUM_LIT:1> ) <EOL> assert relpath [ <NUM_LIT:0> ] == os . sep <EOL> relpath = relpath [ <NUM_LIT:1> : ] <EOL> return join ( dst_prefix , relpath ) <EOL> assert False , "<STR_LIT>" % ( filename , prefixes ) <EOL> def copy_required_modules ( dst_prefix ) : <EOL> import imp <EOL> for modname in REQUIRED_MODULES : <EOL> if modname in sys . builtin_module_names : <EOL> logger . info ( "<STR_LIT>" % modname ) <EOL> continue <EOL> try : <EOL> f , filename , _ = imp . find_module ( modname ) <EOL> except ImportError : <EOL> logger . info ( "<STR_LIT>" % modname ) <EOL> else : <EOL> if f is not None : <EOL> f . close ( ) <EOL> dst_filename = change_prefix ( filename , dst_prefix ) <EOL> copyfile ( filename , dst_filename ) <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> pyfile = filename [ : - <NUM_LIT:1> ] <EOL> if os . path . exists ( pyfile ) : <EOL> copyfile ( pyfile , dst_filename [ : - <NUM_LIT:1> ] ) <EOL> def install_python ( home_dir , lib_dir , inc_dir , bin_dir , site_packages , clear ) : <EOL> """<STR_LIT>""" <EOL> if sys . executable . startswith ( bin_dir ) : <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> if clear : <EOL> rmtree ( lib_dir ) <EOL> logger . notify ( '<STR_LIT>' , bin_dir ) <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> logger . notify ( '<STR_LIT>' % sys . real_prefix ) <EOL> prefix = sys . real_prefix <EOL> else : <EOL> prefix = sys . prefix <EOL> mkdir ( lib_dir ) <EOL> fix_lib64 ( lib_dir ) <EOL> fix_local_scheme ( home_dir ) <EOL> stdlib_dirs = [ os . path . dirname ( os . __file__ ) ] <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> stdlib_dirs . append ( join ( os . path . dirname ( stdlib_dirs [ <NUM_LIT:0> ] ) , '<STR_LIT>' ) ) <EOL> elif sys . platform == '<STR_LIT>' : <EOL> stdlib_dirs . append ( join ( stdlib_dirs [ <NUM_LIT:0> ] , '<STR_LIT>' ) ) <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> logger . info ( '<STR_LIT>' ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> for stdlib_dir in stdlib_dirs : <EOL> if not os . path . isdir ( stdlib_dir ) : <EOL> continue <EOL> for fn in os . listdir ( stdlib_dir ) : <EOL> bn = os . path . splitext ( fn ) [ <NUM_LIT:0> ] <EOL> if fn != '<STR_LIT>' and bn in REQUIRED_FILES : <EOL> copyfile ( join ( stdlib_dir , fn ) , join ( lib_dir , fn ) ) <EOL> copy_required_modules ( home_dir ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> mkdir ( join ( lib_dir , '<STR_LIT>' ) ) <EOL> import site <EOL> site_filename = site . __file__ <EOL> if site_filename . endswith ( '<STR_LIT>' ) : <EOL> site_filename = site_filename [ : - <NUM_LIT:1> ] <EOL> elif site_filename . endswith ( '<STR_LIT>' ) : <EOL> site_filename = site_filename . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> site_filename_dst = change_prefix ( site_filename , home_dir ) <EOL> site_dir = os . path . dirname ( site_filename_dst ) <EOL> writefile ( site_filename_dst , SITE_PY ) <EOL> writefile ( join ( site_dir , '<STR_LIT>' ) , prefix ) <EOL> site_packages_filename = join ( site_dir , '<STR_LIT>' ) <EOL> if not site_packages : <EOL> writefile ( site_packages_filename , '<STR_LIT>' ) <EOL> else : <EOL> if os . path . exists ( site_packages_filename ) : <EOL> logger . info ( '<STR_LIT>' % site_packages_filename ) <EOL> os . unlink ( site_packages_filename ) <EOL> if is_pypy or is_win : <EOL> stdinc_dir = join ( prefix , '<STR_LIT>' ) <EOL> else : <EOL> stdinc_dir = join ( prefix , '<STR_LIT>' , py_version + abiflags ) <EOL> if os . path . exists ( stdinc_dir ) : <EOL> copyfile ( stdinc_dir , inc_dir ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' % stdinc_dir ) <EOL> if sys . exec_prefix != prefix and not is_pypy : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> exec_dir = join ( sys . exec_prefix , '<STR_LIT>' ) <EOL> elif is_jython : <EOL> exec_dir = join ( sys . exec_prefix , '<STR_LIT>' ) <EOL> else : <EOL> exec_dir = join ( sys . exec_prefix , '<STR_LIT>' , py_version ) <EOL> for fn in os . listdir ( exec_dir ) : <EOL> copyfile ( join ( exec_dir , fn ) , join ( lib_dir , fn ) ) <EOL> if is_jython : <EOL> for name in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> src = join ( prefix , name ) <EOL> if os . path . exists ( src ) : <EOL> copyfile ( src , join ( home_dir , name ) ) <EOL> src = join ( prefix , '<STR_LIT>' ) <EOL> if os . path . exists ( src ) : <EOL> copyfile ( src , join ( home_dir , '<STR_LIT>' ) , symlink = False ) <EOL> copyfile ( join ( prefix , '<STR_LIT>' ) , join ( home_dir , '<STR_LIT>' ) , <EOL> symlink = False ) <EOL> mkdir ( bin_dir ) <EOL> py_executable = join ( bin_dir , os . path . basename ( sys . executable ) ) <EOL> if '<STR_LIT>' in prefix : <EOL> if re . search ( r'<STR_LIT>' , py_executable ) : <EOL> py_executable = os . path . join ( <EOL> os . path . dirname ( py_executable ) , '<STR_LIT>' ) <EOL> logger . notify ( '<STR_LIT>' , expected_exe , py_executable ) <EOL> if sys . executable != py_executable : <EOL> executable = sys . executable <EOL> if sys . platform == '<STR_LIT>' and os . path . exists ( executable + '<STR_LIT>' ) : <EOL> executable += '<STR_LIT>' <EOL> py_executable += '<STR_LIT>' <EOL> logger . info ( '<STR_LIT>' % executable ) <EOL> shutil . copyfile ( executable , py_executable ) <EOL> make_exe ( py_executable ) <EOL> if sys . platform == '<STR_LIT:win32>' or sys . platform == '<STR_LIT>' : <EOL> pythonw = os . path . join ( os . path . dirname ( sys . executable ) , '<STR_LIT>' ) <EOL> if os . path . exists ( pythonw ) : <EOL> logger . info ( '<STR_LIT>' ) <EOL> shutil . copyfile ( pythonw , os . path . join ( os . path . dirname ( py_executable ) , '<STR_LIT>' ) ) <EOL> if is_pypy : <EOL> python_executable = os . path . join ( os . path . dirname ( py_executable ) , '<STR_LIT>' ) <EOL> logger . info ( '<STR_LIT>' % python_executable ) <EOL> copyfile ( py_executable , python_executable ) <EOL> if os . path . splitext ( os . path . basename ( py_executable ) ) [ <NUM_LIT:0> ] != expected_exe : <EOL> secondary_exe = os . path . join ( os . path . dirname ( py_executable ) , <EOL> expected_exe ) <EOL> py_executable_ext = os . path . splitext ( py_executable ) [ <NUM_LIT:1> ] <EOL> if py_executable_ext == '<STR_LIT>' : <EOL> secondary_exe += py_executable_ext <EOL> if os . path . exists ( secondary_exe ) : <EOL> logger . warn ( '<STR_LIT>' <EOL> % ( expected_exe , secondary_exe , py_executable ) ) <EOL> else : <EOL> logger . notify ( '<STR_LIT>' % secondary_exe ) <EOL> shutil . copyfile ( sys . executable , secondary_exe ) <EOL> make_exe ( secondary_exe ) <EOL> if '<STR_LIT>' in prefix : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> original_python = os . path . join ( <EOL> prefix , '<STR_LIT>' ) <EOL> shutil . copy ( original_python , py_executable ) <EOL> virtual_lib = os . path . join ( home_dir , '<STR_LIT>' ) <EOL> if os . path . exists ( virtual_lib ) : <EOL> os . unlink ( virtual_lib ) <EOL> copyfile ( <EOL> os . path . join ( prefix , '<STR_LIT>' ) , <EOL> virtual_lib ) <EOL> try : <EOL> call_subprocess ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , <EOL> os . path . join ( prefix , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , <EOL> py_executable ] ) <EOL> except : <EOL> logger . fatal ( <EOL> "<STR_LIT>" ) <EOL> raise <EOL> py_executable_version = '<STR_LIT>' % ( <EOL> sys . version_info [ <NUM_LIT:0> ] , sys . version_info [ <NUM_LIT:1> ] ) <EOL> if not py_executable . endswith ( py_executable_version ) : <EOL> pth = py_executable + '<STR_LIT>' % ( <EOL> sys . version_info [ <NUM_LIT:0> ] , sys . version_info [ <NUM_LIT:1> ] ) <EOL> if os . path . exists ( pth ) : <EOL> os . unlink ( pth ) <EOL> os . symlink ( '<STR_LIT>' , pth ) <EOL> else : <EOL> pth = join ( bin_dir , '<STR_LIT>' ) <EOL> if os . path . exists ( pth ) : <EOL> os . unlink ( pth ) <EOL> os . symlink ( os . path . basename ( py_executable ) , pth ) <EOL> if sys . platform == '<STR_LIT:win32>' and '<STR_LIT:U+0020>' in py_executable : <EOL> py_executable = '<STR_LIT>' % py_executable <EOL> cmd = [ py_executable , '<STR_LIT:-c>' , """<STR_LIT>""" ] <EOL> logger . info ( '<STR_LIT>' % tuple ( cmd ) ) <EOL> try : <EOL> proc = subprocess . Popen ( cmd , <EOL> stdout = subprocess . PIPE ) <EOL> proc_stdout , proc_stderr = proc . communicate ( ) <EOL> except OSError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if e . errno == errno . EACCES : <EOL> logger . fatal ( '<STR_LIT>' % ( py_executable , e ) ) <EOL> sys . exit ( <NUM_LIT:100> ) <EOL> else : <EOL> raise e <EOL> proc_stdout = proc_stdout . strip ( ) . decode ( "<STR_LIT:utf-8>" ) <EOL> proc_stdout = os . path . normcase ( os . path . abspath ( proc_stdout ) ) <EOL> norm_home_dir = os . path . normcase ( os . path . abspath ( home_dir ) ) <EOL> if hasattr ( norm_home_dir , '<STR_LIT>' ) : <EOL> norm_home_dir = norm_home_dir . decode ( sys . getfilesystemencoding ( ) ) <EOL> if proc_stdout != norm_home_dir : <EOL> logger . fatal ( <EOL> '<STR_LIT>' % py_executable ) <EOL> logger . fatal ( <EOL> '<STR_LIT>' <EOL> % ( proc_stdout , norm_home_dir ) ) <EOL> logger . fatal ( <EOL> '<STR_LIT>' ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> logger . fatal ( <EOL> '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:100> ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' % proc_stdout ) <EOL> pydistutils = os . path . expanduser ( '<STR_LIT>' ) <EOL> if os . path . exists ( pydistutils ) : <EOL> logger . notify ( '<STR_LIT>' <EOL> '<STR_LIT>' % pydistutils ) <EOL> return py_executable <EOL> def install_activate ( home_dir , bin_dir , prompt = None ) : <EOL> if sys . platform == '<STR_LIT:win32>' or is_jython and os . _name == '<STR_LIT>' : <EOL> files = { '<STR_LIT>' : ACTIVATE_BAT , <EOL> '<STR_LIT>' : DEACTIVATE_BAT } <EOL> if os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' and os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> files [ '<STR_LIT>' ] = ACTIVATE_SH <EOL> else : <EOL> files = { '<STR_LIT>' : ACTIVATE_SH } <EOL> files [ '<STR_LIT>' ] = ACTIVATE_FISH <EOL> files [ '<STR_LIT>' ] = ACTIVATE_CSH <EOL> files [ '<STR_LIT>' ] = ACTIVATE_THIS <EOL> home_dir = os . path . abspath ( home_dir ) <EOL> if hasattr ( home_dir , '<STR_LIT>' ) : <EOL> home_dir = home_dir . decode ( sys . getfilesystemencoding ( ) ) <EOL> vname = os . path . basename ( home_dir ) <EOL> for name , content in files . items ( ) : <EOL> content = content . replace ( '<STR_LIT>' , prompt or '<STR_LIT>' ) <EOL> content = content . replace ( '<STR_LIT>' , prompt or '<STR_LIT>' % vname ) <EOL> content = content . replace ( '<STR_LIT>' , home_dir ) <EOL> content = content . replace ( '<STR_LIT>' , vname ) <EOL> content = content . replace ( '<STR_LIT>' , os . path . basename ( bin_dir ) ) <EOL> writefile ( os . path . join ( bin_dir , name ) , content ) <EOL> def install_distutils ( home_dir ) : <EOL> distutils_path = change_prefix ( distutils . __path__ [ <NUM_LIT:0> ] , home_dir ) <EOL> mkdir ( distutils_path ) <EOL> home_dir = os . path . abspath ( home_dir ) <EOL> writefile ( os . path . join ( distutils_path , '<STR_LIT>' ) , DISTUTILS_INIT ) <EOL> writefile ( os . path . join ( distutils_path , '<STR_LIT>' ) , DISTUTILS_CFG , overwrite = False ) <EOL> def fix_local_scheme ( home_dir ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import sysconfig <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> if sysconfig . _get_default_scheme ( ) == '<STR_LIT>' : <EOL> local_path = os . path . join ( home_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( local_path ) : <EOL> os . symlink ( os . path . abspath ( home_dir ) , local_path ) <EOL> def fix_lib64 ( lib_dir ) : <EOL> """<STR_LIT>""" <EOL> if [ p for p in distutils . sysconfig . get_config_vars ( ) . values ( ) <EOL> if isinstance ( p , basestring ) and '<STR_LIT>' in p ] : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> assert os . path . basename ( lib_dir ) == '<STR_LIT>' % sys . version [ : <NUM_LIT:3> ] , ( <EOL> "<STR_LIT>" % lib_dir ) <EOL> lib_parent = os . path . dirname ( lib_dir ) <EOL> assert os . path . basename ( lib_parent ) == '<STR_LIT>' , ( <EOL> "<STR_LIT>" % lib_parent ) <EOL> copyfile ( lib_parent , os . path . join ( os . path . dirname ( lib_parent ) , '<STR_LIT>' ) ) <EOL> def resolve_interpreter ( exe ) : <EOL> """<STR_LIT>""" <EOL> if os . path . abspath ( exe ) != exe : <EOL> paths = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( os . pathsep ) <EOL> for path in paths : <EOL> if os . path . exists ( os . path . join ( path , exe ) ) : <EOL> exe = os . path . join ( path , exe ) <EOL> break <EOL> if not os . path . exists ( exe ) : <EOL> logger . fatal ( '<STR_LIT>' % ( exe , exe ) ) <EOL> raise SystemExit ( <NUM_LIT:3> ) <EOL> if not is_executable ( exe ) : <EOL> logger . fatal ( '<STR_LIT>' % ( exe , exe ) ) <EOL> raise SystemExit ( <NUM_LIT:3> ) <EOL> return exe <EOL> def is_executable ( exe ) : <EOL> """<STR_LIT>""" <EOL> return os . access ( exe , os . X_OK ) <EOL> def make_environment_relocatable ( home_dir ) : <EOL> """<STR_LIT>""" <EOL> home_dir , lib_dir , inc_dir , bin_dir = path_locations ( home_dir ) <EOL> activate_this = os . path . join ( bin_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( activate_this ) : <EOL> logger . fatal ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % activate_this ) <EOL> fixup_scripts ( home_dir ) <EOL> fixup_pth_and_egg_link ( home_dir ) <EOL> OK_ABS_SCRIPTS = [ '<STR_LIT>' , '<STR_LIT>' % sys . version [ : <NUM_LIT:3> ] , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def fixup_scripts ( home_dir ) : <EOL> shebang = '<STR_LIT>' % os . path . normcase ( os . path . abspath ( home_dir ) ) <EOL> new_shebang = '<STR_LIT>' % sys . version [ : <NUM_LIT:3> ] <EOL> activate = "<STR_LIT>" <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> bin_suffix = '<STR_LIT>' <EOL> else : <EOL> bin_suffix = '<STR_LIT>' <EOL> bin_dir = os . path . join ( home_dir , bin_suffix ) <EOL> home_dir , lib_dir , inc_dir , bin_dir = path_locations ( home_dir ) <EOL> for filename in os . listdir ( bin_dir ) : <EOL> filename = os . path . join ( bin_dir , filename ) <EOL> if not os . path . isfile ( filename ) : <EOL> continue <EOL> f = open ( filename , '<STR_LIT:rb>' ) <EOL> lines = f . readlines ( ) <EOL> f . close ( ) <EOL> if not lines : <EOL> logger . warn ( '<STR_LIT>' % filename ) <EOL> continue <EOL> if not lines [ <NUM_LIT:0> ] . strip ( ) . startswith ( shebang ) : <EOL> if os . path . basename ( filename ) in OK_ABS_SCRIPTS : <EOL> logger . debug ( '<STR_LIT>' % filename ) <EOL> elif lines [ <NUM_LIT:0> ] . strip ( ) == new_shebang : <EOL> logger . info ( '<STR_LIT>' % filename ) <EOL> else : <EOL> logger . warn ( '<STR_LIT>' <EOL> % ( filename , shebang ) ) <EOL> continue <EOL> logger . notify ( '<STR_LIT>' % filename ) <EOL> lines = [ new_shebang + '<STR_LIT:\n>' , activate + '<STR_LIT:\n>' ] + lines [ <NUM_LIT:1> : ] <EOL> f = open ( filename , '<STR_LIT:wb>' ) <EOL> f . writelines ( lines ) <EOL> f . close ( ) <EOL> def fixup_pth_and_egg_link ( home_dir , sys_path = None ) : <EOL> """<STR_LIT>""" <EOL> home_dir = os . path . normcase ( os . path . abspath ( home_dir ) ) <EOL> if sys_path is None : <EOL> sys_path = sys . path <EOL> for path in sys_path : <EOL> if not path : <EOL> path = '<STR_LIT:.>' <EOL> if not os . path . isdir ( path ) : <EOL> continue <EOL> path = os . path . normcase ( os . path . abspath ( path ) ) <EOL> if not path . startswith ( home_dir ) : <EOL> logger . debug ( '<STR_LIT>' % path ) <EOL> continue <EOL> for filename in os . listdir ( path ) : <EOL> filename = os . path . join ( path , filename ) <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> if not os . access ( filename , os . W_OK ) : <EOL> logger . warn ( '<STR_LIT>' % filename ) <EOL> else : <EOL> fixup_pth_file ( filename ) <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> if not os . access ( filename , os . W_OK ) : <EOL> logger . warn ( '<STR_LIT>' % filename ) <EOL> else : <EOL> fixup_egg_link ( filename ) <EOL> def fixup_pth_file ( filename ) : <EOL> lines = [ ] <EOL> prev_lines = [ ] <EOL> f = open ( filename ) <EOL> prev_lines = f . readlines ( ) <EOL> f . close ( ) <EOL> for line in prev_lines : <EOL> line = line . strip ( ) <EOL> if ( not line or line . startswith ( '<STR_LIT:#>' ) or line . startswith ( '<STR_LIT>' ) <EOL> or os . path . abspath ( line ) != line ) : <EOL> lines . append ( line ) <EOL> else : <EOL> new_value = make_relative_path ( filename , line ) <EOL> if line != new_value : <EOL> logger . debug ( '<STR_LIT>' % ( line , new_value , filename ) ) <EOL> lines . append ( new_value ) <EOL> if lines == prev_lines : <EOL> logger . info ( '<STR_LIT>' % filename ) <EOL> return <EOL> logger . notify ( '<STR_LIT>' % filename ) <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT:\n>' ) <EOL> f . close ( ) <EOL> def fixup_egg_link ( filename ) : <EOL> f = open ( filename ) <EOL> link = f . read ( ) . strip ( ) <EOL> f . close ( ) <EOL> if os . path . abspath ( link ) != link : <EOL> logger . debug ( '<STR_LIT>' % filename ) <EOL> return <EOL> new_link = make_relative_path ( filename , link ) <EOL> logger . notify ( '<STR_LIT>' % ( link , filename , new_link ) ) <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( new_link ) <EOL> f . close ( ) <EOL> def make_relative_path ( source , dest , dest_is_directory = True ) : <EOL> """<STR_LIT>""" <EOL> source = os . path . dirname ( source ) <EOL> if not dest_is_directory : <EOL> dest_filename = os . path . basename ( dest ) <EOL> dest = os . path . dirname ( dest ) <EOL> dest = os . path . normpath ( os . path . abspath ( dest ) ) <EOL> source = os . path . normpath ( os . path . abspath ( source ) ) <EOL> dest_parts = dest . strip ( os . path . sep ) . split ( os . path . sep ) <EOL> source_parts = source . strip ( os . path . sep ) . split ( os . path . sep ) <EOL> while dest_parts and source_parts and dest_parts [ <NUM_LIT:0> ] == source_parts [ <NUM_LIT:0> ] : <EOL> dest_parts . pop ( <NUM_LIT:0> ) <EOL> source_parts . pop ( <NUM_LIT:0> ) <EOL> full_parts = [ '<STR_LIT:..>' ] * len ( source_parts ) + dest_parts <EOL> if not dest_is_directory : <EOL> full_parts . append ( dest_filename ) <EOL> if not full_parts : <EOL> return '<STR_LIT>' <EOL> return os . path . sep . join ( full_parts ) <EOL> def create_bootstrap_script ( extra_text , python_version = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> filename = __file__ <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> filename = filename [ : - <NUM_LIT:1> ] <EOL> f = open ( filename , '<STR_LIT:rb>' ) <EOL> content = f . read ( ) <EOL> f . close ( ) <EOL> py_exe = '<STR_LIT>' % python_version <EOL> content = ( ( '<STR_LIT>' % py_exe ) <EOL> + '<STR_LIT>' <EOL> + content ) <EOL> return content . replace ( '<STR_LIT>' '<STR_LIT>' , extra_text ) <EOL> def convert ( s ) : <EOL> b = base64 . b64decode ( s . encode ( '<STR_LIT:ascii>' ) ) <EOL> return zlib . decompress ( b ) . decode ( '<STR_LIT:utf-8>' ) <EOL> SITE_PY = convert ( """<STR_LIT>""" ) <EOL> EZ_SETUP_PY = convert ( """<STR_LIT>""" ) <EOL> DISTRIBUTE_SETUP_PY = convert ( """<STR_LIT>""" ) <EOL> ACTIVATE_SH = convert ( """<STR_LIT>""" ) <EOL> ACTIVATE_FISH = convert ( """<STR_LIT>""" ) <EOL> ACTIVATE_CSH = convert ( """<STR_LIT>""" ) <EOL> ACTIVATE_BAT = convert ( """<STR_LIT>""" ) <EOL> DEACTIVATE_BAT = convert ( """<STR_LIT>""" ) <EOL> DISTUTILS_INIT = convert ( """<STR_LIT>""" ) <EOL> DISTUTILS_CFG = convert ( """<STR_LIT>""" ) <EOL> ACTIVATE_THIS = convert ( """<STR_LIT>""" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
