def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery):
if not dir == '<STR_LIT:.>':<EOL><INDENT>target_dir = os.path.join(root_dir, dir)<EOL>src_dir = os.path.join(example_dir, dir)<EOL><DEDENT>else:<EOL><INDENT>target_dir = root_dir<EOL>src_dir = example_dir<EOL><DEDENT>if not os.path.exists(os.path.join(src_dir, '<STR_LIT>')):<EOL><INDENT>print('<STR_LIT>' % src_dir)<EOL>print('<STR_LIT>')<EOL>print(<NUM_LIT> * '<STR_LIT:_>')<EOL>return<EOL><DEDENT>fhindex.write("""<STR_LIT>"""<EOL>octree::<EOL>for fname in sorted(os.listdir(src_dir), key=sort_key):<EOL>if fname.endswith('<STR_LIT>'):<EOL>generate_file_rst(fname, target_dir, src_dir, plot_gallery)<EOL>link_name = os.path.join(dir, fname).replace(os.path.sep, '<STR_LIT:_>')<EOL>fhindex.write("""<STR_LIT>"""<EOL>aw:: html<EOL><div style="<STR_LIT>"></div><EOL>
Generate the rst file for an example directory.