def create_rst(self, nb, in_dir, odir):
raw_rst, resources = nbconvert.export_by_name('<STR_LIT>', nb)<EOL>rst_content = '<STR_LIT>'<EOL>i0 = <NUM_LIT:0><EOL>m = None<EOL>bokeh_str = '<STR_LIT>'<EOL>if '<STR_LIT>' in raw_rst and self.insert_bokeh:<EOL><INDENT>bokeh_str += self.BOKEH_TEMPLATE.format(<EOL>version=self.insert_bokeh)<EOL><DEDENT>if '<STR_LIT>' in raw_rst and self.insert_bokeh_widgets:<EOL><INDENT>bokeh_str += self.BOKEH_WIDGETS_TEMPLATE.format(<EOL>version=self.insert_bokeh_widgets)<EOL><DEDENT>for m in code_blocks.finditer(raw_rst):<EOL><INDENT>lines = m.group().splitlines(True)<EOL>header, content = lines[<NUM_LIT:0>], '<STR_LIT>'.join(lines[<NUM_LIT:1>:])<EOL>no_magics = magic_patt.sub('<STR_LIT>', content)<EOL>if no_magics.strip():<EOL><INDENT>rst_content += (<EOL>raw_rst[i0:m.start()] + bokeh_str + header + no_magics)<EOL>bokeh_str = '<STR_LIT>'<EOL>i0 = m.end()<EOL><DEDENT>else:<EOL><INDENT>rst_content += raw_rst[i0:m.start()]<EOL>i0 = m.end()<EOL><DEDENT><DEDENT>if m is not None:<EOL><INDENT>rst_content += bokeh_str + raw_rst[m.end():]<EOL><DEDENT>else:<EOL><INDENT>rst_content = raw_rst<EOL><DEDENT>rst_content = '<STR_LIT>' % self.reference +rst_content<EOL>url = self.url<EOL>if url is not None:<EOL><INDENT>rst_content += self.CODE_DOWNLOAD_NBVIEWER.format(<EOL>pyfile=os.path.basename(self.py_file),<EOL>nbfile=os.path.basename(self.outfile),<EOL>url=url)<EOL><DEDENT>else:<EOL><INDENT>rst_content += self.CODE_DOWNLOAD.format(<EOL>pyfile=os.path.basename(self.py_file),<EOL>nbfile=os.path.basename(self.outfile))<EOL><DEDENT>supplementary_files = self.supplementary_files<EOL>other_supplementary_files = self.other_supplementary_files<EOL>if supplementary_files or other_supplementary_files:<EOL><INDENT>for f in (supplementary_files or []) + (<EOL>other_supplementary_files or []):<EOL><INDENT>if not os.path.exists(os.path.join(odir, f)):<EOL><INDENT>copyfile(os.path.join(in_dir, f), os.path.join(odir, f))<EOL><DEDENT><DEDENT><DEDENT>if supplementary_files:<EOL><INDENT>rst_content += self.data_download(supplementary_files)<EOL><DEDENT>rst_file = self.get_out_file()<EOL>outputs = sorted(resources['<STR_LIT>'], key=rst_content.find)<EOL>base = os.path.join('<STR_LIT>', os.path.splitext(<EOL>os.path.basename(self.infile))[<NUM_LIT:0>] + '<STR_LIT>')<EOL>out_map = {os.path.basename(original): base % i<EOL>for i, original in enumerate(outputs)}<EOL>for original, final in six.iteritems(out_map):<EOL><INDENT>rst_content = rst_content.replace(original, final)<EOL><DEDENT>with open(rst_file, '<STR_LIT:w>')as f:<EOL><INDENT>f.write(rst_content.rstrip() + '<STR_LIT:\n>')<EOL><DEDENT>pictures = []<EOL>for original in outputs:<EOL><INDENT>fname = os.path.join(odir, out_map[os.path.basename(original)])<EOL>pictures.append(fname)<EOL>if six.PY3:<EOL><INDENT>f = open(fname, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>f = open(fname, '<STR_LIT:w>')<EOL><DEDENT>f.write(resources['<STR_LIT>'][original])<EOL>f.close()<EOL><DEDENT>self.pictures = pictures<EOL>
Create the rst file from the notebook node