def write_batch_script(self, n):
self.n = n<EOL>if self.batch_template_file and not self.batch_template:<EOL><INDENT>with open(self.batch_template_file) as f:<EOL><INDENT>self.batch_template = f.read()<EOL><DEDENT><DEDENT>if not self.batch_template:<EOL><INDENT>self.batch_template = self.default_template<EOL>if not self.job_array_regexp.search(self.batch_template):<EOL><INDENT>self.log.debug("<STR_LIT>")<EOL>firstline, rest = self.batch_template.split('<STR_LIT:\n>',<NUM_LIT:1>)<EOL>self.batch_template = u'<STR_LIT:\n>'.join([firstline, self.job_array_template, rest])<EOL><DEDENT>if self.queue and not self.queue_regexp.search(self.batch_template):<EOL><INDENT>self.log.debug("<STR_LIT>")<EOL>firstline, rest = self.batch_template.split('<STR_LIT:\n>',<NUM_LIT:1>)<EOL>self.batch_template = u'<STR_LIT:\n>'.join([firstline, self.queue_template, rest])<EOL><DEDENT><DEDENT>script_as_string = self.formatter.format(self.batch_template, **self.context)<EOL>self.log.debug('<STR_LIT>', self.batch_file)<EOL>with open(self.batch_file, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(script_as_string)<EOL><DEDENT>os.chmod(self.batch_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)<EOL>
Instantiate and write the batch script to the work_dir.