<s> import copy <EOL> import logging <EOL> import os <EOL> import xmltodict <EOL> import jenkins_jobs . builder <EOL> from turbo_hipster . lib import common <EOL> from turbo_hipster . lib import models <EOL> from turbo_hipster . lib import utils <EOL> class UnimplementedJJBFunction ( Exception ) : <EOL> pass <EOL> class Runner ( models . ShellTask ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> def __init__ ( self , worker_server , plugin_config , job_name ) : <EOL> super ( Runner , self ) . __init__ ( worker_server , plugin_config , job_name ) <EOL> self . total_steps = <NUM_LIT:6> <EOL> self . jjb_instructions = { } <EOL> self . script_return_codes = [ ] <EOL> def do_job_steps ( self ) : <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _prep_working_dir ( ) <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _grab_jjb_instructions ( ) <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _execute_instructions ( ) <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _parse_and_check_results ( ) <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _handle_results ( ) <EOL> self . log . info ( '<STR_LIT>' ) <EOL> self . _handle_cleanup ( ) <EOL> @ common . task_step <EOL> def _grab_jjb_instructions ( self ) : <EOL> """<STR_LIT>""" <EOL> jjb = jenkins_jobs . builder . Builder ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> jjb . load_files ( self . plugin_config [ '<STR_LIT>' ] ) <EOL> jjb . parser . generateXML ( [ self . plugin_config [ '<STR_LIT>' ] <EOL> . replace ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> if len ( jjb . parser . jobs ) == <NUM_LIT:1> : <EOL> self . jjb_instructions = xmltodict . parse ( <EOL> jjb . parser . jobs [ <NUM_LIT:0> ] . output ( ) ) <EOL> @ common . task_step <EOL> def _execute_instructions ( self ) : <EOL> self . log . debug ( self . plugin_config [ '<STR_LIT>' ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . log . debug ( self . jjb_instructions . keys ( ) ) <EOL> self . log . debug ( self . jjb_instructions ) <EOL> for key , value in self . jjb_instructions [ '<STR_LIT>' ] . items ( ) : <EOL> self . log . debug ( key ) <EOL> self . log . debug ( value ) <EOL> if key in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if value is None : <EOL> continue <EOL> else : <EOL> raise UnimplementedJJBFunction ( <EOL> "<STR_LIT>" % key ) <EOL> elif key in [ '<STR_LIT:description>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> continue <EOL> elif key == '<STR_LIT>' : <EOL> self . _handle_builders ( value ) <EOL> elif key == '<STR_LIT>' : <EOL> continue <EOL> elif key == '<STR_LIT>' : <EOL> continue <EOL> else : <EOL> raise UnimplementedJJBFunction ( <EOL> "<STR_LIT>" <EOL> % key ) <EOL> def _handle_builders ( self , builders ) : <EOL> for key , value in builders . items ( ) : <EOL> self . log . debug ( '<STR_LIT>' ) <EOL> self . log . debug ( key ) <EOL> self . log . debug ( value ) <EOL> if key == '<STR_LIT>' : <EOL> self . _handle_shell_items ( value ) <EOL> else : <EOL> raise UnimplementedJJBFunction ( <EOL> "<STR_LIT>" <EOL> % key ) <EOL> def _handle_shell_items ( self , shell_tasks ) : <EOL> for shell_task in shell_tasks : <EOL> for key , value in shell_task . items ( ) : <EOL> self . log . debug ( '<STR_LIT>' ) <EOL> self . log . debug ( key ) <EOL> self . log . debug ( value ) <EOL> if key == '<STR_LIT>' : <EOL> self . _handle_command ( value ) <EOL> else : <EOL> raise UnimplementedJJBFunction ( <EOL> "<STR_LIT>" <EOL> % key ) <EOL> def _handle_command ( self , command ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> cwd = os . path . join ( self . job_working_dir , '<STR_LIT>' ) <EOL> if not os . path . isdir ( os . path . dirname ( cwd ) ) : <EOL> self . log . debug ( '<STR_LIT>' % cwd ) <EOL> os . makedirs ( os . path . dirname ( cwd ) ) <EOL> env = copy . deepcopy ( self . job_arguments ) <EOL> env [ '<STR_LIT>' ] = os . environ [ '<STR_LIT>' ] <EOL> self . script_return_codes . append ( utils . execute_to_log ( <EOL> command , self . shell_output_log , <EOL> env = env , <EOL> cwd = cwd <EOL> ) ) <EOL> @ common . task_step <EOL> def _parse_and_check_results ( self ) : <EOL> for return_code in self . script_return_codes : <EOL> if return_code > <NUM_LIT:0> : <EOL> self . success = False <EOL> self . messages . append ( '<STR_LIT>' <EOL> '<STR_LIT>' % return_code ) <EOL> @ common . task_step <EOL> def _handle_results ( self ) : <EOL> """<STR_LIT>""" <EOL> self . log . debug ( "<STR_LIT>" ) </s>
