(dir, fhindex, example_dir, root_dir, plot_gallery)
Generate the rst file for an example directory.
Generate the rst file for an example directory.
Generate the rst file for an example directory .
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 80 * '_'
        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)
    sorted_listdir = line_count_sort(os.listdir(src_dir),
                                     src_dir)
    for fname in sorted_listdir:
        if fname == 'setup.py':
            continue
        if fname.endswith('py'):
            if not os.path.exists(os.path.join(dir, 'images', 'thumb')):
                os.makedirs(os.path.join(dir, 'images', 'thumb'))
            generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery)
            new_fname = os.path.join(src_dir, fname)
            _, fdocstring, _ = extract_docstring(new_fname, True)
            thumb = os.path.join(dir, 'images', 'thumb', fname[:-3] + '.png')
            link_name = os.path.join(dir, fname).replace(os.path.sep, '_')
            fhindex.write("""

.. raw:: html


    <div class="thumbnailContainer" tooltip="%s">

""" % (fdocstring))

            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("""   :ref:`example_%s`


.. raw:: html


    </div>


.. toctree::
   :hidden:

   %s/%s

""" % (link_name, dir, fname[:-3]))
    fhindex.write("""
.. raw:: html

    <div style="clear: both"></div>
    """)
def generate_dir_rst ( dir , fhindex , example_dir , root_dir , plot_gallery ) : 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 80 * '_' 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 ) sorted_listdir = line_count_sort ( os . listdir ( src_dir ) , src_dir ) for fname in sorted_listdir : if fname == 'setup.py' : continue if fname . endswith ( 'py' ) : if not os . path . exists ( os . path . join ( dir , 'images' , 'thumb' ) ) : os . makedirs ( os . path . join ( dir , 'images' , 'thumb' ) ) generate_file_rst ( fname , target_dir , src_dir , root_dir , plot_gallery ) new_fname = os . path . join ( src_dir , fname ) _ , fdocstring , _ = extract_docstring ( new_fname , True ) thumb = os . path . join ( dir , 'images' , 'thumb' , fname [ : - 3 ] + '.png' ) link_name = os . path . join ( dir , fname ) . replace ( os . path . sep , '_' ) fhindex . write ( """

.. raw:: html


    <div class="thumbnailContainer" tooltip="%s">

""" % ( fdocstring ) ) 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 ( """   :ref:`example_%s`


.. raw:: html


    </div>


.. toctree::
   :hidden:

   %s/%s

""" % ( link_name , dir , fname [ : - 3 ] ) ) fhindex . write ( """
.. raw:: html

    <div style="clear: both"></div>
    """ )