<s> import shutil <EOL> import os <EOL> import re <EOL> from settings import MainSettings <EOL> from binder . log import * <EOL> def namespace_params ( ns , params ) : <EOL> ns_params = { } <EOL> for p in params : <EOL> ns_params [ ns + '<STR_LIT:.>' + p ] = params [ p ] <EOL> return ns_params <EOL> def make_patterns ( params ) : <EOL> return [ ( re . compile ( "<STR_LIT>" + k + "<STR_LIT>" ) , '<STR_LIT>' . format ( params [ k ] ) ) for k in params ] <EOL> def fill_template_string ( template , params ) : <EOL> res = make_patterns ( params ) <EOL> replaced = template <EOL> for pattern , new in res : <EOL> replaced = pattern . sub ( new , replaced ) <EOL> return replaced <EOL> def fill_template ( template_path , params ) : <EOL> try : <EOL> res = make_patterns ( params ) <EOL> with open ( template_path , '<STR_LIT>' ) as template : <EOL> raw = template . read ( ) <EOL> with open ( template_path , '<STR_LIT:w>' ) as template : <EOL> replaced = raw <EOL> for pattern , new in res : <EOL> replaced = pattern . sub ( new , replaced ) <EOL> template . write ( replaced ) <EOL> except ( IOError , TypeError ) as e : <EOL> error_log ( "<STR_LIT>" , "<STR_LIT>" . format ( template_path , e ) ) <EOL> def make_dir ( path , clean = False ) : <EOL> if os . path . isdir ( path ) : <EOL> if clean : <EOL> shutil . rmtree ( path ) <EOL> os . mkdir ( path ) <EOL> else : <EOL> os . mkdir ( path ) <EOL> def get_binder_home ( ) : <EOL> import binder <EOL> return "<STR_LIT:/>" . join ( binder . __file__ . split ( "<STR_LIT:/>" ) [ : - <NUM_LIT:1> ] ) <EOL> def get_env_string ( ) : <EOL> env = [ <EOL> "<STR_LIT>" . format ( MainSettings . ROOT ) , <EOL> "<STR_LIT>" . format ( os . environ [ "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" . format ( get_binder_home ( ) ) <EOL> ] <EOL> return "<STR_LIT:U+0020>" . join ( env ) </s>
