<s> """<STR_LIT>""" <EOL> import ConfigParser <EOL> import copy <EOL> import os <EOL> import re <EOL> import sys <EOL> try : <EOL> import pip <EOL> except ImportError , e : <EOL> print ( '<STR_LIT>' ) % e <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> import virtualenv <EOL> except ImportError , e : <EOL> print ( '<STR_LIT>' ) % e <EOL> print ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> CONFIG = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } , <EOL> } <EOL> REQUIREMENTS_FILE = '<STR_LIT>' <EOL> REQUIREMENTS_REGEXP = re . compile ( r'<STR_LIT>' ) <EOL> DIRNAME = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> rel = lambda * x : os . path . abspath ( os . path . join ( DIRNAME , * x ) ) <EOL> class Environment ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , suffix = None , filename = None ) : <EOL> self . suffix = suffix is None and self . suffix_from_filename ( filename ) or suffix <EOL> print ( '<STR_LIT>' % os . path . basename ( self . dest_dir ) ) <EOL> def create ( self ) : <EOL> print ( '<STR_LIT>' ) <EOL> if not os . path . isdir ( self . dest_dir ) or CONFIG [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> kwargs = copy . copy ( CONFIG [ '<STR_LIT>' ] ) <EOL> kwargs [ '<STR_LIT>' ] = self . dest_dir <EOL> verbosity = int ( kwargs [ '<STR_LIT>' ] ) - int ( kwargs [ '<STR_LIT>' ] ) <EOL> logger = virtualenv . Logger ( [ <EOL> ( virtualenv . Logger . level_for_integer ( <NUM_LIT:2> - verbosity ) , <EOL> sys . stdout ) , <EOL> ] ) <EOL> del kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] <EOL> virtualenv . logger = logger <EOL> virtualenv . create_environment ( ** kwargs ) <EOL> else : <EOL> print ( '<STR_LIT>' % self . dest_dir ) <EOL> @ property <EOL> def dest_dir ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> dest_dir = CONFIG [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if self . suffix : <EOL> dest_dir += self . suffix <EOL> setattr ( self , '<STR_LIT>' , rel ( dest_dir ) ) <EOL> return getattr ( self , '<STR_LIT>' ) <EOL> def install_requirements ( self ) : <EOL> print ( '<STR_LIT>' ) <EOL> if os . path . isfile ( self . requirements_file ) : <EOL> args = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , os . path . basename ( self . dest_dir ) , <EOL> '<STR_LIT>' , os . path . basename ( self . requirements_file ) ] <EOL> if CONFIG [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> download_cache = CONFIG [ '<STR_LIT>' ] [ '<STR_LIT>' ] % self . template_context <EOL> args . extend ( [ '<STR_LIT>' , download_cache ] ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if CONFIG [ '<STR_LIT>' ] [ name ] : <EOL> args . append ( '<STR_LIT>' + name ) <EOL> try : <EOL> pip . main ( args ) <EOL> except SystemExit , e : <EOL> if e . code : <EOL> raise e <EOL> else : <EOL> print ( '<STR_LIT>' % self . requirements_file ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> @ property <EOL> def requirements_file ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> requirements_file , ext = os . path . splitext ( REQUIREMENTS_FILE ) <EOL> if self . suffix : <EOL> requirements_file += self . suffix <EOL> requirements_file += ext <EOL> setattr ( self , '<STR_LIT>' , rel ( requirements_file ) ) <EOL> return getattr ( self , '<STR_LIT>' ) <EOL> def suffix_from_filename ( self , filename ) : <EOL> if filename is None : <EOL> return u'<STR_LIT>' <EOL> try : <EOL> return REQUIREMENTS_REGEXP . findall ( filename ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> print ( '<STR_LIT>' % filename ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> @ property <EOL> def template_context ( self ) : <EOL> return { '<STR_LIT>' : self . dest_dir } <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> os . chdir ( DIRNAME ) <EOL> read_config ( '<STR_LIT>' ) <EOL> filenames = sorted ( os . listdir ( DIRNAME ) ) <EOL> env = None <EOL> for filename in filenames : <EOL> if not REQUIREMENTS_REGEXP . match ( filename ) : <EOL> continue <EOL> if env is not None : <EOL> print ( '<STR_LIT>' ) % ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> env = Environment ( filename = filename ) <EOL> env . create ( ) <EOL> env . install_requirements ( ) <EOL> def read_config ( config_file ) : <EOL> global CONFIG <EOL> if not config_file . startswith ( DIRNAME ) : <EOL> config_file = rel ( config_file ) <EOL> if not os . path . isfile ( config_file ) : <EOL> return <EOL> config = ConfigParser . ConfigParser ( ) <EOL> config . read ( config_file ) <EOL> print ( '<STR_LIT>' % config_file ) <EOL> for section in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> items = config . items ( section ) <EOL> except ConfigParser . NoSectionError : <EOL> continue <EOL> for key , value in items : <EOL> if key in CONFIG [ section ] : <EOL> CONFIG [ section ] [ key ] = value <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
