<s> from sts . util . console import Tee <EOL> import sts . experiments . lifecycle as exp_lifecycle <EOL> from sts . util . convenience import timestamp_string , create_clean_python_dir , create_python_dir , find <EOL> import os <EOL> import shutil <EOL> import re <EOL> import logging <EOL> def setup_experiment ( args , config ) : <EOL> if args . exp_name : <EOL> config . exp_name = args . exp_name <EOL> elif not hasattr ( config , '<STR_LIT>' ) : <EOL> config . exp_name = exp_lifecycle . guess_config_name ( config ) <EOL> if not hasattr ( config , '<STR_LIT>' ) : <EOL> config . results_dir = "<STR_LIT>" % config . exp_name <EOL> if args . timestamp_results is not None : <EOL> config . timestamp_results = args . timestamp_results <EOL> if hasattr ( config , '<STR_LIT>' ) and config . timestamp_results : <EOL> now = timestamp_string ( ) <EOL> config . results_dir += "<STR_LIT:_>" + str ( now ) <EOL> create_python_dir ( "<STR_LIT>" ) <EOL> create_clean_python_dir ( config . results_dir ) <EOL> tee = Tee ( open ( os . path . join ( config . results_dir , "<STR_LIT>" ) , "<STR_LIT:w>" ) ) <EOL> tee . tee_stdout ( ) <EOL> tee . tee_stderr ( ) <EOL> if args . log_config : <EOL> logging . config . fileConfig ( args . log_config ) <EOL> else : <EOL> logging . basicConfig ( level = logging . DEBUG if args . verbose else logging . INFO ) <EOL> for controller_config in config . simulation_config . controller_configs : <EOL> if controller_config . config_template : <EOL> controller_config . generate_config_file ( config . results_dir ) <EOL> if args . publish : <EOL> exp_lifecycle . publish_prepare ( config . exp_name , config . results_dir ) <EOL> additional_metadata = None <EOL> if hasattr ( config , "<STR_LIT>" ) : <EOL> additional_metadata = config . get_additional_metadata ( ) <EOL> exp_lifecycle . dump_metadata ( "<STR_LIT>" % config . results_dir , <EOL> additional_metadata = additional_metadata ) <EOL> config_file = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , config . __file__ ) <EOL> if os . path . exists ( config_file ) : <EOL> canonical_config_file = config . results_dir + "<STR_LIT>" <EOL> if os . path . abspath ( config_file ) != os . path . abspath ( canonical_config_file ) : <EOL> shutil . copy ( config_file , canonical_config_file ) <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> con = config . control_flow . simulation_cfg . controller_configs <EOL> def builtin_pox_controller ( c ) : <EOL> return ( "<STR_LIT>" in str ( c . controller_class ) and <EOL> c . cwd is not None and <EOL> re . match ( "<STR_LIT>" , c . cwd ) is not None ) <EOL> if ( not hasattr ( config , "<STR_LIT>" ) and <EOL> find ( lambda c : not builtin_pox_controller ( c ) , <EOL> config . control_flow . simulation_cfg . controller_configs ) is not None ) : <EOL> log . warn ( '''<STR_LIT>''' <EOL> '''<STR_LIT>''' ) </s>
