def __add_jmeter_components(self, jmx, jtl, variables):
logger.debug("<STR_LIT>", os.path.realpath(jmx))<EOL>with open(jmx, '<STR_LIT:r>') as src_jmx:<EOL><INDENT>source_lines = src_jmx.readlines()<EOL><DEDENT>try:<EOL><INDENT>closing = source_lines.pop(-<NUM_LIT:1>)<EOL>if "<STR_LIT>" in source_lines[-<NUM_LIT:5>]:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>last_string_count = <NUM_LIT:6><EOL><DEDENT>else:<EOL><INDENT>last_string_count = <NUM_LIT:2><EOL><DEDENT>while last_string_count > <NUM_LIT:0>:<EOL><INDENT>closing = source_lines.pop(-<NUM_LIT:1>) + closing<EOL>last_string_count -= <NUM_LIT:1><EOL><DEDENT>logger.debug("<STR_LIT>", closing)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % exc)<EOL><DEDENT>udv_tpl = resource_string(__name__, '<STR_LIT>')<EOL>udv_set = []<EOL>for var_name, var_value in variables.iteritems():<EOL><INDENT>udv_set.append(udv_tpl % (var_name, var_name, var_value))<EOL><DEDENT>udv = "<STR_LIT:\n>".join(udv_set)<EOL>if self.jmeter_ver >= <NUM_LIT>:<EOL><INDENT>save_connect = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>save_connect = '<STR_LIT>'<EOL><DEDENT>if self.ext_log in ['<STR_LIT>', '<STR_LIT:all>']:<EOL><INDENT>level_map = {'<STR_LIT>': '<STR_LIT:true>', '<STR_LIT:all>': '<STR_LIT:false>'}<EOL>tpl_resource = '<STR_LIT>'<EOL>tpl_args = {<EOL>'<STR_LIT>': self.jtl_file,<EOL>'<STR_LIT>': udv,<EOL>'<STR_LIT>': self.ext_log_file,<EOL>'<STR_LIT>': level_map[self.ext_log],<EOL>'<STR_LIT>': save_connect<EOL>}<EOL><DEDENT>else:<EOL><INDENT>tpl_resource = '<STR_LIT>'<EOL>tpl_args = {<EOL>'<STR_LIT>': self.jtl_file,<EOL>'<STR_LIT>': udv,<EOL>'<STR_LIT>': save_connect<EOL>}<EOL><DEDENT>tpl = resource_string(__name__, '<STR_LIT>' + tpl_resource)<EOL>try:<EOL><INDENT>new_jmx = self.core.mkstemp(<EOL>'<STR_LIT>', '<STR_LIT>', os.path.dirname(os.path.realpath(jmx)))<EOL><DEDENT>except OSError as exc:<EOL><INDENT>logger.debug("<STR_LIT>", exc)<EOL>new_jmx = self.core.mkstemp('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>logger.debug("<STR_LIT>", new_jmx)<EOL>with open(new_jmx, "<STR_LIT:wb>") as fh:<EOL><INDENT>fh.write('<STR_LIT>'.join(source_lines))<EOL>fh.write(tpl % tpl_args)<EOL>fh.write(closing)<EOL><DEDENT>return new_jmx<EOL>
Genius idea by Alexey Lavrenyuk