docs: def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery):
      """ Generate the rst file for an example directory.
      """
      if not dir == '.':
          target_dir = os.path.join(root_dir, dir)
          src_dir = os.path.join(example_dir, dir)
      else:
          target_dir = root_dir
          src_dir = example_dir
      if not os.path.exists(os.path.join(src_dir, 'README.txt')):
          print('Example directory %s does not have a README.txt file' % src_dir)
          print('Skipping this directory')
          print(80 * '_')
          return
      fhindex.write("""
  
  
  %s
  
  
  """ % file(os.path.join(src_dir, 'README.txt')).read())
      if not os.path.exists(target_dir):
          os.makedirs(target_dir)
  
      def sort_key(a):
          # put last elements without a plot
          if not a.startswith('plot') and a.endswith('.py'):
              return 'zz' + a
          return a
  
      fhindex.write("""
  
  .. toctree::
  
  """)
      for fname in sorted(os.listdir(src_dir), key=sort_key):
          if fname.endswith('py'):
              generate_file_rst(fname, target_dir, src_dir, plot_gallery)
              #thumb = os.path.join(dir, 'images', 'thumb', fname[:-3] + '.png')
              link_name = os.path.join(dir, fname).replace(os.path.sep, '_')
              #fhindex.write('.. figure:: %s\n' % thumb)
              #if link_name.startswith('._'):
              #    link_name = link_name[2:]
              #if dir != '.':
              #    fhindex.write('   :target: ./%s/%s.html\n\n' % (dir,
              #                                                   fname[:-3]))
              #else:
              #    fhindex.write('   :target: ./%s.html\n\n' % link_name[:-3])
              fhindex.write("""
     %s/%s
  """ % (dir, fname[:-3]))
      fhindex.write("""
  
  .. raw:: html
  
      <div style="clear: both"></div>
      """)